3 #include "hashvector.h"
5 typedef struct _ipslot {
7 unsigned char data[32];
11 static unsigned long voidp_hashcode(itemkeyfun *this,void *key) {
12 return hashvector_hashcode( key, sizeof( ipslot ) );
15 static void* voidp_itemkey(itemkeyfun *this,void *item) {
19 static int voidp_haskey(itemkeyfun *this,void *item,void *key) {
20 return memcmp( item, key, sizeof( ipslot ) ) == 0;
23 static int shrink(vector *pv,unsigned long index,void *item,void *data) {
25 if ( item == HV_HOLE ) {
26 ((hashvector*) data)->holes--;
29 ((hashvector*) data)->fill--;
35 int main(int argc,char **argv) {
36 itemkeyfun voidpfun = {
37 .hashcode = voidp_hashcode,
38 .itemkey = voidp_itemkey,
39 .haskey = voidp_haskey
48 for ( ; i < 259; i++ ) {
49 ipslot *item = (ipslot*) calloc( 1, sizeof( ipslot ) );
55 memcpy( item->data, "10.10.10.1", 10 );
56 hashvector_add( &hv, item );
58 for ( i = 256; i < 260; i++ ) {
59 vector_index index = i;
60 void ** slot = vector_next_used( &hv.table, &index );
61 if ( slot && *slot != HV_HOLE ) {
62 hashvector_delete( &hv, *slot );
65 vector_resize( &hv.table, 256, shrink, &hv );