X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2Ftupleitem.h;h=3917c9bc8b72f3333a3e6cb766dba7ca0e718075;hb=74eec6f62db4459232f95b5d39069b9b4ceeb830;hp=59589e7c90555f96dd4e521610eea0f890e48e2f;hpb=813b52397a92922f2540a41c9076a77ca93e1a48;p=rrq%2Frrqmisc.git diff --git a/vector/tupleitem.h b/vector/tupleitem.h index 59589e7..3917c9b 100644 --- a/vector/tupleitem.h +++ b/vector/tupleitem.h @@ -10,10 +10,10 @@ 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 { @@ -39,11 +39,15 @@ typedef struct { /** * Create a tuples with given values. + * + * \related tupleschema */ extern tuple *tuple_create(int arity,...); /** * Create a tuples with given values. + * + * \related tupleschema */ extern tupleschema *tupleschema_create(int arity,tuple *columns); @@ -51,28 +55,46 @@ 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. + * + * \related tupleschema */ extern tupleschema *tupleschema_mask(tupleschema *schema,...); /** * \brief Return 1/0 to indicate whether the query matches the item. + * + * \related tupleschema */ extern int tupleschema_match(tupleschema *def,tuple *query,tuple *item); /** - * The TUPLEITEMINIT macro is used for initializing a tupleschema - * record appropriately for a given arity and corresponding sequence - * of parts itemkeyfun pointers. + * \brief Generic macro to determine the number of expressions in a + * __VA_ARGS__ + * + * \related tupleschema */ -#define TUPLEITEMINIT(arity, ... ) { \ - .functions = { \ - .hashcode = tupleitem_hashcode, \ - .haskey = tupleitem_haskey, \ - .itemkey = tupleitem_itemkey, \ - .releasekey = tupleitem_releasekey \ - }, \ - .arity = arity, \ - .schema = { __VA_ARGS__ } \ - } +#define NUMARGS(...) (sizeof((void*[]){__VA_ARGS__})/sizeof(void*)) + +/** + * \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 + */ +#define TUPLE(...) tuple_create( NUMARGS(__VA_ARGS__), __VA_ARGS__ ) + +/** + * \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 TUPLESCHEMA(...) \ + tupleschema_create( NUMARGS( __VA_ARGS__ ), TUPLE( __VA_ARGS__ ) ) + #endif