X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=pvector%2Fexample-pvector.c;h=12154b58da04b4ac509e60ab459eb81b50a36174;hb=2339c8634f18b2eaf7e68ea964d28285a42cf536;hp=73beeb19b70eca1e833ac71e6c1b44fba5102898;hpb=b4647b184df6ce07762053d48b4ee650a73068af;p=rrq%2Frrqmisc.git diff --git a/pvector/example-pvector.c b/pvector/example-pvector.c index 73beeb1..12154b5 100644 --- a/pvector/example-pvector.c +++ b/pvector/example-pvector.c @@ -89,7 +89,7 @@ static void add_entry(ipslot *tmp) { ipslot *p = (ipslot *) malloc( sizeof( ipslot ) ); memmove( p, tmp, sizeof( ipslot ) ); if ( table.data.size == table.fill ) { - (void) pvector_resize( &table.data, table.fill + 256, 0 ); + (void) pvector_resize( &table.data, table.fill + 256, 0, 0 ); } pvector_set( &table.data, table.fill++, p ); } @@ -112,29 +112,45 @@ static void load_file(const char *filename) { } } -static int int_reclaim(pvector *pv,int index,void *item) { - return 1; +static int int_reclaim(pvector *pv,unsigned long index,void *item,void *data) { + return 0; } +static int dumpitem(unsigned long index,void *item) { + fprintf( stdout, "[%ld] %p\n", index, item ); + return 0; +} + +static int dump_ipslot(unsigned long index,void *item) { + static char buffer[100]; + ipslot *ip = (ipslot*) item; + const char *p = inet_ntop( (ip->bits <= 32)? AF_INET : AF_INET6, + ip->data, buffer, 100 ); + + fprintf( stdout, "[%ld] %s/%d\n", index, p, ip->bits ); + return 0; +} int main(int argc,char **argv) { - pvector test; - pvector_resize( &test, 100, 0 ); + pvector test = { 0 }; + pvector_resize( &test, 100, 0, 0 ); pvector_set( &test, 5, (void*) 500 ); pvector_set( &test, 55, (void*) 600 ); //pvector_set( &test, 550, (void*) 800 ); - pvector_resize( &test, 300, 0 ); + pvector_resize( &test, 300, 0, 0 ); pvector_set( &test, 55, (void*) 650 ); - pvector_resize( &test, 30000, 0 ); + pvector_resize( &test, 30000, 0, 0 ); pvector_set( &test, 22255, (void*) 26 ); - pvector_resize( &test, 100, int_reclaim ); + pvector_dump( &test, dumpitem ); + pvector_resize( &test, 100, int_reclaim, 0 ); pvector_set( &test, 5, (void*) 2 ); + pvector_dump( &test, dumpitem ); -#if 0 int i; for ( i = 1; i < argc; i++ ) { load_file( argv[ i ] ); } -#endif + pvector_dump( &table.data, dump_ipslot ); + return 0; }