From: Ralph Ronnquist Date: Wed, 6 Jul 2022 00:01:01 +0000 (+1000) Subject: fix vararg usae; use static callbacks X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=e47e7f1e366224e9e514e28f172afa65c732db21;p=rrq%2Frrqmisc.git fix vararg usae; use static callbacks --- diff --git a/vector/tupleitem.c b/vector/tupleitem.c index ce5c713..14c3b3b 100644 --- a/vector/tupleitem.c +++ b/vector/tupleitem.c @@ -5,7 +5,24 @@ #define COLUMN def->columns -unsigned long tupleitem_hashcode(itemkeyfun *this,void *key) { +/** + * This callback function returns the hashcode of a key. + * + * \param this is a pointer to the itemkeyfun record from where this + * callback got invoked + * + * \param key is the key to produce a hascode for + * + * \returns the hashcode which is a vector_index (i.e. unsigned long) + * + * 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 tupleitem_hashcode(itemkeyfun *this,void *key) { tupleschema *def = (tupleschema *) this; tuple *kp = (tuple*) key; int i = 0; @@ -23,7 +40,7 @@ unsigned long tupleitem_hashcode(itemkeyfun *this,void *key) { * This callback function determines whether an item has a * given key or not. */ -int tupleitem_haskey(itemkeyfun *this,void *item,void *key) { +static int tupleitem_haskey(itemkeyfun *this,void *item,void *key) { tupleschema *def = (tupleschema *) this; tuple *kp = (tuple*) key; tuple *tp = (tuple*) item; @@ -42,7 +59,7 @@ int tupleitem_haskey(itemkeyfun *this,void *item,void *key) { * This callback function returns the key of an item by considering * the arity and mask. */ -void *tupleitem_itemkey(itemkeyfun *this,void *item) { +static void *tupleitem_itemkey(itemkeyfun *this,void *item) { tupleschema *def = (tupleschema *) this; tuple *tp = (tuple*) item; int i, j; @@ -65,7 +82,7 @@ void *tupleitem_itemkey(itemkeyfun *this,void *item) { * This callback function handles a key obtained from the itemkey * callback function to reclaim temporary allocation. */ -void tupleitem_releasekey(itemkeyfun *this,void *key) { +static void tupleitem_releasekey(itemkeyfun *this,void *key) { tupleschema *def = (tupleschema *) this; tuple *kp = (tuple*) key; int i,j; @@ -82,9 +99,11 @@ tuple *tuple_create(int arity,...) { va_list ap; int i; tuple *t = (tuple *)malloc( arity * sizeof( void* ) ); + va_start( ap, arity ); for ( i = 0; i < arity; i++ ) { (*t)[i] = va_arg( ap, void* ); } + va_end( ap ); return t; } @@ -112,6 +131,7 @@ tupleschema *tupleschema_mask(tupleschema *schema,...) { masked->columns = COPYA( itemkeyfun*, schema->columns, schema->arity ); va_list ap; int i; + va_start( ap, schema ); for ( ;; ) { i = va_arg( ap, int ); if ( i < 0 || i >= schema->arity ) { @@ -119,5 +139,17 @@ tupleschema *tupleschema_mask(tupleschema *schema,...) { } masked->columns[i] = 0; }; + va_end( ap ); return masked; } + +unsigned long tuple_mask(int arity,tuple *t) { + unsigned long mask = 0; + while ( arity-- > 0 ) { + mask <<= 1; + if ( (*t)[ arity ] ) { + mask++; + } + } + return mask; +} diff --git a/vector/tupleitem.h b/vector/tupleitem.h index 37d5e24..5956668 100644 --- a/vector/tupleitem.h +++ b/vector/tupleitem.h @@ -36,43 +36,6 @@ typedef struct { itemkeyfun **columns; } tupleschema; -/** - * This callback function returns the hashcode of a key. - * - * \param this is a pointer to the itemkeyfun record from where this - * callback got invoked - * - * \param key is the key to produce a hascode for - * - * \returns the hashcode which is a vector_index (i.e. unsigned long) - * - * 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 tupleitem_hashcode(itemkeyfun *this,void *key); - -/** - * This callback function determines whether an item has a - * given key or not. - */ -extern int tupleitem_haskey(itemkeyfun *this,void *item,void *key); - -/** - * This callback function returns the key of an item by considering - * the arity and schema. - */ -extern void *tupleitem_itemkey(itemkeyfun *this,void *item); - -/** - * This callback function handles a key obtained from the itemkey - * callback function to reclaim temporary allocation. - */ -extern void tupleitem_releasekey(itemkeyfun *this,void *key); - /** * Create a tuples with given values. */