3 #include "HashVector.h"
5 typedef struct _ipslot {
7 unsigned char data[32];
11 static unsigned long voidp_hashcode(void *this,void *key) {
12 return HashVector_hashcode( key, sizeof( ipslot ) );
15 static void* voidp_itemkey(void *this,void *item) {
19 static int voidp_haskey(void *this,void *item,void *key) {
20 return memcmp( item, key, sizeof( ipslot ) ) == 0;
23 static void voidp_releasekey(void *this,void *key) {
26 static int voidp_tostring(void *this, void *item, char *buffer, int limit) {
27 return snprintf( buffer, limit, "%p", item );
30 static int shrink(Vector *pv,unsigned long index,void *item,void *data) {
32 if ( item == HV_HOLE ) {
33 ((HashVector*) data)->holes--;
36 ((HashVector*) data)->fill--;
42 int main(int argc,char **argv) {
43 ItemKeyFun voidpfun = {
44 .hashcode = voidp_hashcode,
45 .itemkey = voidp_itemkey,
46 .haskey = voidp_haskey,
47 .releasekey = voidp_releasekey,
48 .tostring = voidp_tostring
57 for ( ; i < 259; i++ ) {
58 ipslot *item = (ipslot*) calloc( 1, sizeof( ipslot ) );
64 memcpy( item->data, "10.10.10.1", 10 );
65 HashVector_add( &hv, item );
67 for ( i = 256; i < 260; i++ ) {
68 VectorIndex index = i;
69 void ** slot = Vector_next_used( &hv.table, &index );
70 if ( slot && *slot != HV_HOLE ) {
71 HashVector_delete( &hv, *slot );
74 Vector_resize( &hv.table, 256, shrink, &hv );