3 #include "hashvector.h"
5 typedef struct _ipslot {
7 unsigned char data[32];
11 static unsigned long voidp_hashcode(void *key) {
12 return hashvector_hashcode( key, sizeof( ipslot ) );
15 static void* voidp_itemkey(void *item) {
19 static int voidp_haskey(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) {
40 .keyhashcode = voidp_hashcode,
41 .itemkey = voidp_itemkey,
42 .haskey = voidp_haskey
45 for ( ; i < 259; i++ ) {
46 ipslot *item = (ipslot*) calloc( 1, sizeof( ipslot ) );
52 memcpy( item->data, "10.10.10.1", 10 );
53 hashvector_add( &hv, item );
55 for ( i = 256; i < 260; i++ ) {
56 vector_index index = i;
57 void ** slot = vector_next_used( &hv.table, &index, 0, 0 );
58 if ( slot && *slot != HV_HOLE ) {
59 hashvector_delete( &hv, *slot );
62 vector_resize( &hv.table, 256, shrink, &hv );