X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2Ftupleitem.h;h=3917c9bc8b72f3333a3e6cb766dba7ca0e718075;hb=76dbbc2320962d0808e6cdc715a3ffc7b5e41a22;hp=37d5e248f99b41c73fa9748be9837a6a40346dda;hpb=84fa20543ae0464a87fde599d1db66bfdbd29198;p=rrq%2Frrqmisc.git diff --git a/vector/tupleitem.h b/vector/tupleitem.h index 37d5e24..3917c9b 100644 --- a/vector/tupleitem.h +++ b/vector/tupleitem.h @@ -10,10 +10,11 @@ typedef void *tuple[]; /** * A tupleschema record declares the itemkeyfun functions for tuple - * items together with applicable arity and domain combinations. The - * macro \ref TUPLEITEMINIT may be used to initialize particular - * tupleschema records, which each become tupleitem declaration for - * its particular arity and parts declarations + * items together with applicable arity and domain combinations. + * Records are created dynamically via the \ref tupleschema_create + * function or the \ref TUPLESCHEMA convenience macro. + * + * \extends itemkeyfun */ typedef struct { /** @@ -22,7 +23,7 @@ typedef struct { * itemkeyfun pointer to be within a tupleschema record so as to * provide the handling of the tuple columns. */ - itemkeyfun functions; + itemkeyfun base; /** * This is the number of columns in a tuple. @@ -37,73 +38,63 @@ typedef struct { } 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) + * Create a tuples with given values. * - * 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. + * \related tupleschema */ -extern unsigned long tupleitem_hashcode(itemkeyfun *this,void *key); +extern tuple *tuple_create(int arity,...); /** - * This callback function determines whether an item has a - * given key or not. + * Create a tuples with given values. + * + * \related tupleschema */ -extern int tupleitem_haskey(itemkeyfun *this,void *item,void *key); +extern tupleschema *tupleschema_create(int arity,tuple *columns); /** - * This callback function returns the key of an item by considering - * the arity and schema. + * Copy the given tupleschema into a new tupleschema with some columns + * masked. This represents a sub-index type using the unmasked columns + * for indexing. + * + * \related tupleschema */ -extern void *tupleitem_itemkey(itemkeyfun *this,void *item); +extern tupleschema *tupleschema_mask(tupleschema *schema,...); /** - * This callback function handles a key obtained from the itemkey - * callback function to reclaim temporary allocation. + * \brief Return 1/0 to indicate whether the query matches the item. + * + * \related tupleschema */ -extern void tupleitem_releasekey(itemkeyfun *this,void *key); +extern int tupleschema_match(tupleschema *def,tuple *query,tuple *item); /** - * Create a tuples with given values. + * \brief Generic macro to determine the number of expressions in a + * __VA_ARGS__ + * + * \related tupleschema */ -extern tuple *tuple_create(int arity,...); +#define NUMARGS(...) (sizeof((void*[]){__VA_ARGS__})/sizeof(void*)) /** - * Create a tuples with given values. + * \brief Create a tuple with the given values. + * + * This invokes \ref tuple_create to allocate and assign a void* + * array with the given values. + * + * \related tupleschema */ -extern tupleschema *tupleschema_create(int arity,tuple *columns); +#define TUPLE(...) tuple_create( NUMARGS(__VA_ARGS__), __VA_ARGS__ ) /** - * Copy the given tupleschema into a new tupleschema with some columns - * masked. This represents a sub-index type using the unmasked columns - * for indexing. + * \brief Create a \ref tupleschema with the given column "types". + * + * This invokes \ref tupleschema_create to allocate and initialize a + * \ref tupleschema for the given columns via the \ref TUPLE macro. + * + * \related tupleschema */ -extern tupleschema *tupleschema_mask(tupleschema *schema,...); +#define TUPLESCHEMA(...) \ + tupleschema_create( NUMARGS( __VA_ARGS__ ), TUPLE( __VA_ARGS__ ) ) -/** - * The TUPLEITEMINIT macro is used for initializing a tupleschema - * record appropriately for a given arity and corresponding sequence - * of parts itemkeyfun pointers. - */ -#define TUPLEITEMINIT(arity, ... ) { \ - .functions = { \ - .hashcode = tupleitem_hashcode, \ - .haskey = tupleitem_haskey, \ - .itemkey = tupleitem_itemkey, \ - .releasekey = tupleitem_releasekey \ - }, \ - .arity = arity, \ - .schema = { __VA_ARGS__ } \ - } #endif