Cleanup Tuple to allow self-typing.
[rrq/rrqmisc.git] / vector / Relation.c
index 0b7450f3b3b0aec251e6c99b707bfef8bcc1222b..4a6417053c73bff4f223f00064f2c839b2d8504d 100644 (file)
@@ -30,12 +30,13 @@ Relation *Relation_create(TupleSchema *schema) {
 int Relation_add_constraint(Relation *r,...) {
     va_list ap;
     TupleSchema *ts = (TupleSchema *) r->content.type;
-    tuple *columns = (tuple*) calloc( ts->arity, sizeof( void* ) );
+    Tuple *columns = (Tuple*) malloc(
+       sizeof( Tuple ) + ts->arity * sizeof( void* ) );
     int i = 0;
     va_start( ap, r );
     for ( ; i < ts->arity; i++ ) {
        if ( va_arg( ap, int ) ) {
-           (*columns)[i] = ts->columns[i];
+           columns->elements[i] = ts->columns->elements[i];
        }
     }
     va_end( ap );
@@ -85,7 +86,7 @@ static int knockout_add(VectorIndex index,void *item,void *data) {
 // Find and remove all collisions for a Query, unless "add" is
 // non-zero in which case the function aborts if there is any match in
 // the main content.
-static int knockout_clear(Knockout *this,Relation *r,tuple *item,int add) {
+static int knockout_clear(Knockout *this,Relation *r,Tuple *item,int add) {
     (*this) = (Knockout) {
        .rel = r,
        .knockouts = {
@@ -120,7 +121,7 @@ static int knockout_clear(Knockout *this,Relation *r,tuple *item,int add) {
 
 // add a tuple to a Relation and return a Vector of knocked out
 // tuples, if any, or 0 otherwise.
-Vector *Relation_add(Relation *r,tuple *item) {
+Vector *Relation_add(Relation *r,Tuple *item) {
     Knockout data;
     if ( knockout_clear( &data, r, item, 1 ) ) {
        // Add the new tuple
@@ -131,13 +132,13 @@ Vector *Relation_add(Relation *r,tuple *item) {
     return 0;
 }
 
-Vector *Relation_delete(Relation *r,tuple *item) {
+Vector *Relation_delete(Relation *r,Tuple *item) {
     Knockout data;
     (void) knockout_clear( &data, r, item, 0 );
     return HashVector_contents( &data.knockouts, single_index_level, 0 );
 }
 
-void *Relation_next(Relation *r,VectorIndex *index,tuple *Query) {
-    return HashVector_next( &r->content, index, Query );
+void *Relation_next(Relation *r,VectorIndex *index,Tuple *query) {
+    return HashVector_next( &r->content, index, query );
 }