exported the callbacks, and added convenience macros
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 8 Jul 2022 13:35:00 +0000 (23:35 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 8 Jul 2022 13:35:00 +0000 (23:35 +1000)
vector/tupleitem.c
vector/tupleitem.h

index ad1326735e816c5fa7989378c8e0f1fcfe81bb69..55328c5446624abda6224bc07993acfcaacdc0c9 100644 (file)
@@ -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
     };
index 59589e7c90555f96dd4e521610eea0f890e48e2f..3917c9bc8b72f3333a3e6cb766dba7ca0e718075 100644 (file)
@@ -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