From 4d7f93d07b12ad58f42e41f3e8ecd5550f3bd9c8 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Tue, 21 Jun 2022 13:23:38 +1000 Subject: [PATCH] cleanup and commenting --- pvector/example-hashvector.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pvector/example-hashvector.c b/pvector/example-hashvector.c index 214738f..f752426 100644 --- a/pvector/example-hashvector.c +++ b/pvector/example-hashvector.c @@ -15,14 +15,8 @@ typedef struct _ipslot { unsigned int bits; } ipslot; -static int voidp_hashcode(void *key) { - unsigned char *p = (unsigned char *) key; - int value = 5381; - int i = 0; - for ( ; i < sizeof( ipslot ); i++ ) { - value += ( value << 5 ) + *(p++); - } - return value; +static unsigned long voidp_hashcode(void *key) { + return hashvector_hashcode( key, sizeof( ipslot ) ); } static void* voidp_itemkey(void *item) { @@ -35,7 +29,7 @@ static int voidp_haskey(void *item,void *key) { static struct { hashvector hv; - int fill; + long fill; } table = { .hv = { .table = { 12000, 0 }, @@ -218,14 +212,16 @@ int main(int argc,char **argv) { for ( i = 1; i < argc; i++ ) { load_file( argv[ i ] ); } + fprintf( stdout, "---- hashvector after filling it %ld/%ld/%ld\n", + table.hv.fill, table.hv.holes, table.hv.table.size ); pvector_dump( &table.hv.table, dump_ipslot ); - fprintf( stdout, "--------------\n" ); - if ( hashvector_pack( &table.hv, &test ) < 0 ) { + if ( hashvector_contents( &table.hv, &test ) < 0 ) { fprintf( stdout, "test is not empty\n" ); } + fprintf( stdout, "---- hashvector contents in hash order\n" ); pvector_dump( &test, dump_ipslot ); - fprintf( stdout, "--------------\n" ); pvector_qsort( &test, compare_ipslot ); + fprintf( stdout, "---- contents after sorting\n" ); pvector_dump( &test, dump_ipslot ); return 0; } -- 2.39.2