From 2be3617b0022de55a8f2017ac8d645deda2fee5a Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Fri, 8 Jul 2022 23:35:00 +1000 Subject: [PATCH] exported the callbacks, and added convenience macros --- vector/tupleitem.c | 14 +++++++----- vector/tupleitem.h | 56 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/vector/tupleitem.c b/vector/tupleitem.c index ad13267..55328c5 100644 --- a/vector/tupleitem.c +++ b/vector/tupleitem.c @@ -112,15 +112,17 @@ tuple *tuple_create(int arity,...) { return t; } +itemkeyfun tupleschema_callbacks = { + .hashcode = tupleitem_hashcode, + .haskey = tupleitem_haskey, + .itemkey = tupleitem_itemkey, + .releasekey = tupleitem_releasekey +}; + tupleschema *tupleschema_create(int arity,tuple *columns) { tupleschema *ts = (tupleschema*) malloc( sizeof( tupleschema ) ); (*ts) = (tupleschema) { - .base = { - .hashcode = tupleitem_hashcode, - .haskey = tupleitem_haskey, - .itemkey = tupleitem_itemkey, - .releasekey = tupleitem_releasekey - }, + .base = tupleschema_callbacks, .arity = arity, .columns = (itemkeyfun**) columns }; 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 -- 2.39.2