initial tuple support
[rrq/rrqmisc.git] / vector / tupleitem.h
1 #ifndef tupleitem_H
2 #define tupleitem_H
3
4 #include <itemkeyfun.h>
5
6 /**
7  * A tupleschema record declares the itemkeyfun functions for tuple
8  * items together with applicable arity and domain combinations. The
9  * macro \ref TUPLEITEMINIT may be used to initialize particular
10  * tupleschema records, which each become tupleitem declaration for
11  * its particular arity and parts declarations
12  */
13 typedef struct {
14     /**
15      * These are the itemkeyfun callback functions to support
16      * hashvector use for tuple items. The functions expects their
17      * itemkeyfun pointer to be within a tupleschema record so as to
18      * provide the handling of the tuple columns.
19      */
20     itemkeyfun functions;
21     /**
22      * This is the number of columns in a tuple.
23      */
24     int arity;
25     /**
26      * This is an array of pointers to the tuple item domains as
27      * represented by their associated itemkeyfun records.
28      */
29     itemkeyfun **schema;
30 } tupleschema;
31
32 /**
33  * This callback function returns the hashcode of a key.
34  *
35  * \param this is a pointer to the itemkeyfun record from where this
36  * callback got invoked
37  *
38  * \param key is the key to produce a hascode for
39  *
40  * \returns the hashcode which is a vector_index (i.e. unsigned long)
41  *
42  * The hashcode is used for indexing into the backing vector for
43  * finding the an item via its key. The same key must map consistently
44  * to the same hashcode while the hashtable contains an item with that
45  * key. Different keys map map to the same hashcode, in which case the
46  * vector placement is made at the first empty or hole slot following
47  * the hashcode index.
48  */
49 extern unsigned long tupleitem_hashcode(itemkeyfun *this,void *key);
50
51 /**
52  * This callback function determines whether an item has a
53  * given key or not.
54  */
55 extern int tupleitem_haskey(itemkeyfun *this,void *item,void *key);
56
57 /**
58  * This callback function returns the key of an item by considering
59  * the arity and schema.
60  */
61 extern void *tupleitem_itemkey(itemkeyfun *this,void *item);
62
63 /**
64  * This callback function handles a key obtained from the itemkey
65  * callback function to reclaim temporary allocation.
66  */
67 extern void tupleitem_releasekey(itemkeyfun *this,void *key);
68
69 /**
70  * The TUPLEITEMINIT macro is used for initializing a tupleschema
71  * record appropriately for a given arity and corresponding sequence
72  * of parts itemkeyfun pointers.
73  */
74 #define TUPLEITEMINIT(arity, ... ) {    \
75         functions = {                           \
76             .hashcode = tupleitem_hashcode,     \
77             .haskey = tupleitem_haskey,         \
78             .itemkey = tupleitem_itemkey,       \
79             .releasekey = tupleitem_releasekey  \
80         },                                      \
81             .arity = arity,                     \
82             .schema = { __VA_ARGS__ }           \
83     }
84
85 #endif