c589176d3387601fae18fc29ad57ba954740ba26
[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 (optinal) 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  */
14 typedef struct {
15     /**
16      * This is the primary content store for the relation. Its type
17      * should be a tupleschema declaring the "item types" for the
18      * relation columns.
19      */
20     hashvector content;
21
22     /**
23      * This is a collection of relational constraints, if any, which
24      * are represented as hashvectors whose tupleschemas are clones of
25      * the content tupleschema with some columns excluded.
26      */
27     vector constraints;
28 } relation;
29
30 /**
31  * Create a relation for the given tupleschema.
32  */
33 extern relation *relation_create(tupleschema *schema);
34
35 /**
36  * Add a a key index to the relation by identifying the value part for
37  * this index.
38  */
39 extern int relation_addindex(relation *r,tupleschema *ts);
40
41
42 /**
43  * \brief Add a tuple to a relation.
44  * \param r is th relation concerned.
45  * \param t is the tuple to add.
46  *
47  * \returns a vector of all knocked out tuples.
48  */
49 extern vector *relation_add(relation *r,tuple *t);
50
51 /**
52  * \brief Delete all tuples matching to the query.
53  * \returns all deleted tuples.
54  */
55 extern vector *relation_delete(relation *r,tuple *query);
56
57 /**
58  * \brief Return next tuple matching the query at or after the index.
59  * \returns any such matching tuple and updates *index to its index.
60  */
61 extern void *relation_next(relation *r,vector_index *index,tuple *query);
62
63 #endif