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 void voidp_releasekey(itemkeyfun *this,void *key) {
26 static int shrink(vector *pv,unsigned long index,void *item,void *data) {
28 if ( item == HV_HOLE ) {
29 ((hashvector*) data)->holes--;
32 ((hashvector*) data)->fill--;
38 int main(int argc,char **argv) {
39 itemkeyfun voidpfun = {
40 .hashcode = voidp_hashcode,
41 .itemkey = voidp_itemkey,
42 .haskey = voidp_haskey,
43 .releasekey = voidp_releasekey
52 for ( ; i < 259; i++ ) {
53 ipslot *item = (ipslot*) calloc( 1, sizeof( ipslot ) );
59 memcpy( item->data, "10.10.10.1", 10 );
60 hashvector_add( &hv, item );
62 for ( i = 256; i < 260; i++ ) {
63 vector_index index = i;
64 void ** slot = vector_next_used( &hv.table, &index );
65 if ( slot && *slot != HV_HOLE ) {
66 hashvector_delete( &hv, *slot );
69 vector_resize( &hv.table, 256, shrink, &hv );