Added Query functions. Major renaming of stuff to use camelcase type names.
[rrq/rrqmisc.git] / vector / TupleSchema.h
1 #ifndef tupleitem_H
2 #define tupleitem_H
3
4 #include <ItemKeyFun.h>
5
6 /**
7  * A tuple is an array of void*
8  */
9 typedef void *tuple[];
10
11 /**
12  * A TupleSchema record declares the ItemKeyFun functions for tuple
13  * items together with applicable arity and domain combinations.
14  * Records are created dynamically via the \ref TupleSchema_create
15  * function or the \ref TUPLESCHEMA convenience macro.
16  *
17  * \extends ItemKeyFun
18  */
19 typedef struct {
20     /**
21      * These are the ItemKeyFun callback functions to support
22      * HashVector use for tuple items. The functions expects their
23      * ItemKeyFun pointer to be within a TupleSchema record so as to
24      * provide the handling of the tuple columns.
25      */
26     ItemKeyFun base;
27
28     /**
29      * This is the number of columns in a tuple.
30      */
31     int arity;
32
33     /**
34      * This points to an array of pointers to the tuple item domains
35      * as represented by their associated ItemKeyFun records.
36      */
37     ItemKeyFun **columns;
38 } TupleSchema;
39
40 /**
41  * Create a tuples with given values.
42  *
43  * \related TupleSchema
44  */
45 extern tuple *tuple_create(int arity,...);
46
47 /**
48  * Create a tuples with given values.
49  *
50  * \related TupleSchema
51  */
52 extern TupleSchema *TupleSchema_create(int arity,tuple *columns);
53
54 /**
55  * Copy the given TupleSchema into a new TupleSchema with some columns
56  * masked. This represents a sub-index type using the unmasked columns
57  * for indexing.
58  *
59  * \related TupleSchema
60  */
61 extern TupleSchema *TupleSchema_mask(TupleSchema *schema,...);
62
63 /**
64  * \brief Return 1/0 to indicate whether the query matches the item.
65  *
66  * \related TupleSchema
67  */
68 extern int TupleSchema_match(TupleSchema *def,tuple *query,tuple *item);
69
70 /**
71  * \brief Generic macro to determine the number of expressions in a
72  * __VA_ARGS__
73  *
74  * \related TupleSchema
75  */
76 #define NUMARGS(...) (sizeof((void*[]){__VA_ARGS__})/sizeof(void*))
77
78 /**
79  * \brief Create a tuple with the given values.
80  *
81  * This invokes \ref tuple_create to allocate and assign a void*
82  * array with the given values.
83  *
84  * \related TupleSchema
85  */
86 #define TUPLE(...) tuple_create( NUMARGS(__VA_ARGS__), __VA_ARGS__ )
87
88 /**
89  * \brief Create a \ref TupleSchema with the given column "types".
90  *
91  * This invokes \ref TupleSchema_create to allocate and initialize a
92  * \ref TupleSchema for the given columns via the \ref TUPLE macro.
93  *
94  * \related TupleSchema
95  */
96 #define TUPLESCHEMA(...) \
97     TupleSchema_create( NUMARGS( __VA_ARGS__ ), TUPLE( __VA_ARGS__ ) )
98
99
100 #endif