From: Ralph Ronnquist Date: Wed, 6 Jul 2022 00:00:36 +0000 (+1000) Subject: use static callbacks X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=14c22de9f38ec5304dd14a2625b6ac8fdfda52f4;p=rrq%2Frrqmisc.git use static callbacks --- diff --git a/vector/integeritem.c b/vector/integeritem.c index 57d309f..0ad2302 100644 --- a/vector/integeritem.c +++ b/vector/integeritem.c @@ -1,6 +1,15 @@ #include -unsigned long integeritem_hashcode(itemkeyfun *this,void *key) { +/** + * This callback function returns the hashcode of a key. The hashcode + * is used for indexing into the backing vector for finding the an + * item via its key. The same key must map consistently to the same + * hashcode while the hashtable contains an item with that key. + * Different keys map map to the same hashcode, in which case the + * vector placement is made at the first empty or hole slot following + * the hashcode index. + */ +static unsigned long integeritem_hashcode(itemkeyfun *this,void *key) { return (unsigned long) key; } @@ -8,7 +17,7 @@ unsigned long integeritem_hashcode(itemkeyfun *this,void *key) { * This callback function determines whether an item has a * given key or not. */ -int integeritem_haskey(itemkeyfun *this,void *item,void *key) { +static int integeritem_haskey(itemkeyfun *this,void *item,void *key) { return item == key; } @@ -16,7 +25,7 @@ int integeritem_haskey(itemkeyfun *this,void *item,void *key) { * This callback function returns the key of an item by considering * the arity and schema. */ -void *integeritem_itemkey(itemkeyfun *this,void *item) { +static void *integeritem_itemkey(itemkeyfun *this,void *item) { return item; } @@ -24,7 +33,7 @@ void *integeritem_itemkey(itemkeyfun *this,void *item) { * This callback function handles a key obtained from the itemkey * callback function to reclaim temporary allocation. */ -void integeritem_releasekey(itemkeyfun *this,void *key) { +static void integeritem_releasekey(itemkeyfun *this,void *key) { } itemkeyfun integeritem = { diff --git a/vector/integeritem.h b/vector/integeritem.h index 3dc8545..7518b26 100644 --- a/vector/integeritem.h +++ b/vector/integeritem.h @@ -9,33 +9,4 @@ */ extern itemkeyfun integeritem; -/** - * This callback function returns the hashcode of a key. The hashcode - * is used for indexing into the backing vector for finding the an - * item via its key. The same key must map consistently to the same - * hashcode while the hashtable contains an item with that key. - * Different keys map map to the same hashcode, in which case the - * vector placement is made at the first empty or hole slot following - * the hashcode index. - */ -extern unsigned long integeritem_hashcode(itemkeyfun *this,void *key); - -/** - * This callback function determines whether an item has a - * given key or not. - */ -extern int integeritem_haskey(itemkeyfun *this,void *item,void *key); - -/** - * This callback function returns the key of an item by considering - * the arity and schema. - */ -extern void *integeritem_itemkey(itemkeyfun *this,void *item); - -/** - * This callback function handles a key obtained from the itemkey - * callback function to reclaim temporary allocation. - */ -extern void integeritem_releasekey(itemkeyfun *this,void *key); - #endif diff --git a/vector/stringitem.c b/vector/stringitem.c index 12ec1ac..ce10e7c 100644 --- a/vector/stringitem.c +++ b/vector/stringitem.c @@ -2,7 +2,16 @@ #include #include -unsigned long integeritem_hashcode(itemkeyfun *this,void *key) { +/** + * This callback function returns the hashcode of a key. The hashcode + * is used for indexing into the backing vector for finding the an + * item via its key. The same key must map consistently to the same + * hashcode while the hashtable contains an item with that key. + * Different keys map map to the same hashcode, in which case the + * vector placement is made at the first empty or hole slot following + * the hashcode index. + */ +static unsigned long stringitem_hashcode(itemkeyfun *this,void *key) { return hashvector_hashcode( (unsigned char*)key, strlen( (char*)key ) ); } @@ -10,7 +19,7 @@ unsigned long integeritem_hashcode(itemkeyfun *this,void *key) { * This callback function determines whether an item has a * given key or not. */ -int integeritem_haskey(itemkeyfun *this,void *item,void *key) { +static int stringitem_haskey(itemkeyfun *this,void *item,void *key) { return strcmp( item, key ) == 0; } @@ -18,7 +27,7 @@ int integeritem_haskey(itemkeyfun *this,void *item,void *key) { * This callback function returns the key of an item by considering * the arity and schema. */ -void *integeritem_itemkey(itemkeyfun *this,void *item) { +static void *stringitem_itemkey(itemkeyfun *this,void *item) { return item; } @@ -26,7 +35,7 @@ void *integeritem_itemkey(itemkeyfun *this,void *item) { * This callback function handles a key obtained from the itemkey * callback function to reclaim temporary allocation. */ -void integeritem_releasekey(itemkeyfun *this,void *key) { +static void stringitem_releasekey(itemkeyfun *this,void *key) { } itemkeyfun stringitem = { @@ -35,5 +44,3 @@ itemkeyfun stringitem = { .itemkey = stringitem_itemkey, .releasekey = stringitem_releasekey }; - - diff --git a/vector/stringitem.h b/vector/stringitem.h index 0923bcd..cf1d0f7 100644 --- a/vector/stringitem.h +++ b/vector/stringitem.h @@ -9,34 +9,4 @@ */ extern itemkeyfun stringitem; -/** - * This callback function returns the hashcode of a key. The hashcode - * is used for indexing into the backing vector for finding the an - * item via its key. The same key must map consistently to the same - * hashcode while the hashtable contains an item with that key. - * Different keys map map to the same hashcode, in which case the - * vector placement is made at the first empty or hole slot following - * the hashcode index. - */ -extern unsigned long stringitem_hashcode(itemkeyfun *this,void *key); - -/** - * This callback function determines whether an item has a - * given key or not. - */ -extern int stringitem_haskey(itemkeyfun *this,void *item,void *key); - -/** - * This callback function returns the key of an item by considering - * the arity and schema. - */ -extern void *stringitem_itemkey(itemkeyfun *this,void *item); - -/** - * This callback function handles a key obtained from the itemkey - * callback function to reclaim temporary allocation. - */ -extern void stringitem_releasekey(itemkeyfun *this,void *key); - - #endif