X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2Ftupleitem.h;h=3917c9bc8b72f3333a3e6cb766dba7ca0e718075;hb=76dbbc2320962d0808e6cdc715a3ffc7b5e41a22;hp=baec9e3806d51e5d0897713d52d1f9b7169f5cb4;hpb=6f54a8281e4e5d6bc05e6b4eadc3327d5e48614a;p=rrq%2Frrqmisc.git diff --git a/vector/tupleitem.h b/vector/tupleitem.h index baec9e3..3917c9b 100644 --- a/vector/tupleitem.h +++ b/vector/tupleitem.h @@ -3,12 +3,18 @@ #include +/** + * A tuple is an array of void* + */ +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 { /** @@ -17,69 +23,78 @@ 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. */ int arity; + /** - * This is an array of pointers to the tuple item domains as - * represented by their associated itemkeyfun records. + * This points to an array of pointers to the tuple item domains + * as represented by their associated itemkeyfun records. */ - itemkeyfun **schema; + 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 + * Create a tuples with given values. * - * \param key is the key to produce a hascode for + * \related tupleschema + */ +extern tuple *tuple_create(int arity,...); + +/** + * Create a tuples with given values. * - * \returns the hashcode which is a vector_index (i.e. unsigned long) + * \related tupleschema + */ +extern tupleschema *tupleschema_create(int arity,tuple *columns); + +/** + * Copy the given tupleschema into a new tupleschema with some columns + * masked. This represents a sub-index type using the unmasked columns + * for indexing. * - * 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 tupleschema *tupleschema_mask(tupleschema *schema,...); /** - * This callback function determines whether an item has a - * given key or not. + * \brief Return 1/0 to indicate whether the query matches the item. + * + * \related tupleschema */ -extern int tupleitem_haskey(itemkeyfun *this,void *item,void *key); +extern int tupleschema_match(tupleschema *def,tuple *query,tuple *item); /** - * This callback function returns the key of an item by considering - * the arity and schema. + * \brief Generic macro to determine the number of expressions in a + * __VA_ARGS__ + * + * \related tupleschema */ -extern void *tupleitem_itemkey(itemkeyfun *this,void *item); +#define NUMARGS(...) (sizeof((void*[]){__VA_ARGS__})/sizeof(void*)) /** - * This callback function handles a key obtained from the itemkey - * callback function to reclaim temporary allocation. + * \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 void tupleitem_releasekey(itemkeyfun *this,void *key); +#define TUPLE(...) tuple_create( NUMARGS(__VA_ARGS__), __VA_ARGS__ ) /** - * The TUPLEITEMINIT macro is used for initializing a tupleschema - * record appropriately for a given arity and corresponding sequence - * of parts itemkeyfun pointers. + * \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 */ -#define TUPLEITEMINIT(arity, ... ) { \ - functions = { \ - .hashcode = tupleitem_hashcode, \ - .haskey = tupleitem_haskey, \ - .itemkey = tupleitem_itemkey, \ - .releasekey = tupleitem_releasekey \ - }, \ - .arity = arity, \ - .schema = { __VA_ARGS__ } \ - } +#define TUPLESCHEMA(...) \ + tupleschema_create( NUMARGS( __VA_ARGS__ ), TUPLE( __VA_ARGS__ ) ) + #endif