af0756cd09265c2e67196d7feff625bc38cf9c75
[rrq/rrqmisc.git] / vector / relation.h
1 #ifndef relation_H
2 #define relation_H
3
4 #include <hashvector.h>
5 #include <tupleitem.h>
6
7 /**
8  * A relation is an implementation of a tuple set with (optional) key
9  * constraints. The store is a hashvector whose "type" is a
10  * tupleschema that defines the columns. The key constraints are
11  * represented as additional hashvectors whose tupleschemas are clones
12  * of the column schema with some columns excluded.
13  * \extends hashvector
14  */
15 typedef struct {
16     /**
17      * This is the primary content store for the relation. Its type
18      * should be a tupleschema declaring the "item types" for the
19      * relation columns.
20      */
21     hashvector content;
22
23     /**
24      * This is a collection of relational constraints, if any, which
25      * are represented as hashvectors whose tupleschemas are clones of
26      * the content tupleschema with some columns excluded.
27      */
28     vector constraints;
29 } relation;
30
31 /**
32  * Create a relation for the given tupleschema.
33  */
34 extern relation *relation_create(tupleschema *schema);
35
36 /**
37  * Add a a key index to the relation by identifying the value part for
38  * this index.
39  */
40 extern int relation_addindex(relation *r,tupleschema *ts);
41
42
43 /**
44  * \brief Add a tuple to a relation.
45  * \param r is th relation concerned.
46  * \param t is the tuple to add.
47  *
48  * \returns a vector of all knocked out tuples.
49  */
50 extern vector *relation_add(relation *r,tuple *t);
51
52 /**
53  * \brief Delete all tuples matching to the query.
54  * \returns all deleted tuples.
55  */
56 extern vector *relation_delete(relation *r,tuple *query);
57
58 /**
59  * \brief Return next tuple matching the query at or after the index.
60  * \returns any such matching tuple and updates *index to its index.
61  */
62 extern void *relation_next(relation *r,vector_index *index,tuple *query);
63
64 #endif