return 0;
}
-static int dumpitem(unsigned long index,void *item) {
+static int dumpitem(const unsigned long index,const void *item) {
fprintf( stdout, "[%ld] %p\n", index, item );
return 0;
}
-static int dump_ipslot(unsigned long index,void *item) {
+static int dump_ipslot(const unsigned long index,const void *item) {
static char buffer[100];
ipslot *ip = (ipslot*) item;
const char *p = inet_ntop( ip->family, ip->data, buffer, 100 );
return 0;
}
-static int compare_ipslot(void *ax,void *bx) {
+static int compare_ipslot(const void *ax,const void *bx) {
ipslot *a = (ipslot *) ax;
ipslot *b = (ipslot *) bx;
int x = b->family - a->family;
return 0;
}
+static int shrink(pvector *pv,unsigned long index,void *item,void *data) {
+ if ( item ) {
+ if ( item == HV_HOLE ) {
+ ((hashvector*) data)->holes--;
+ } else {
+ free( item );
+ ((hashvector*) data)->fill--;
+ }
+ }
+ return 0;
+}
+
int main(int argc,char **argv) {
+#if TEST0
pvector test = { 0 };
pvector_resize( &test, 100, 0, 0 );
pvector_set( &test, 5, (void*) 500 );
pvector_qsort( &test, compare_ipslot );
fprintf( stdout, "---- contents after sorting\n" );
pvector_dump( &test, dump_ipslot );
+#endif
+#if TEST1
+ hashvector hv = {
+ .table = { 4, 0 },
+ .fill = 0,
+ .holes = 0,
+ .keyhashcode = voidp_hashcode,
+ .itemkey = voidp_itemkey,
+ .haskey = voidp_haskey
+ };
+ int i = 0;
+ for ( ; i < 259; i++ ) {
+ ipslot *item = (ipslot*) calloc( 1, sizeof( ipslot ) );
+ if ( i > 250 ) {
+ int n = i;
+ i = n;
+ }
+ item->family = i;
+ memcpy( item->data, "10.10.10.1", 10 );
+ hashvector_add( &hv, item );
+ }
+ pvector_resize( &hv.table, 256, shrink, &hv );
+#endif
return 0;
}