889b875f29ab816a7795602654f9ca3c5fac3e1f
[rrq/rrqmisc.git] / vector / tupleitem.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. The
14  * macro \ref TUPLEITEMINIT may be used to initialize particular
15  * tupleschema records, which each become tupleitem declaration for
16  * its particular arity and parts declarations
17  */
18 typedef struct {
19     /**
20      * These are the itemkeyfun callback functions to support
21      * hashvector use for tuple items. The functions expects their
22      * itemkeyfun pointer to be within a tupleschema record so as to
23      * provide the handling of the tuple columns.
24      */
25     itemkeyfun base;
26
27     /**
28      * This is the number of columns in a tuple.
29      */
30     int arity;
31
32     /**
33      * This points to an array of pointers to the tuple item domains
34      * as represented by their associated itemkeyfun records.
35      */
36     itemkeyfun **columns;
37 } tupleschema;
38
39 /**
40  * Create a tuples with given values.
41  */
42 extern tuple *tuple_create(int arity,...);
43
44 /**
45  * Create a tuples with given values.
46  */
47 extern tupleschema *tupleschema_create(int arity,tuple *columns);
48
49 /**
50  * Copy the given tupleschema into a new tupleschema with some columns
51  * masked. This represents a sub-index type using the unmasked columns
52  * for indexing.
53  */
54 extern tupleschema *tupleschema_mask(tupleschema *schema,...);
55
56 /**
57  * \brief Return 1/0 to indicate whether the query matches the item.
58  */
59 extern int tupleschema_match(tupleschema *def,tuple *query,tuple *item);
60
61 /**
62  * The TUPLEITEMINIT macro is used for initializing a tupleschema
63  * record appropriately for a given arity and corresponding sequence
64  * of parts itemkeyfun pointers.
65  */
66 #define TUPLEITEMINIT(arity, ... ) {    \
67         .functions = {                          \
68             .hashcode = tupleitem_hashcode,     \
69             .haskey = tupleitem_haskey,         \
70             .itemkey = tupleitem_itemkey,       \
71             .releasekey = tupleitem_releasekey  \
72         },                                      \
73             .arity = arity,                     \
74             .schema = { __VA_ARGS__ }           \
75     }
76
77 #endif