X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2FRelation.c;h=0f671abce2d09c475f8092e22ff760825211250c;hb=3d4400773c3361961bcb9f8b6898321f2005a093;hp=4a6417053c73bff4f223f00064f2c839b2d8504d;hpb=58de9483c458a25a691d648ce13b81227c327d03;p=rrq%2Frrqmisc.git diff --git a/vector/Relation.c b/vector/Relation.c index 4a64170..0f671ab 100644 --- a/vector/Relation.c +++ b/vector/Relation.c @@ -61,10 +61,16 @@ typedef struct { // for ignoring full matches to the key tuple. static int knockout_check(VectorIndex index,void *item,void *data) { Knockout *kod = (Knockout*) data; + void *key = kod->item; + HashVector *hv = (HashVector*) item; + TupleSchema *type = (TupleSchema *)hv->type; VectorIndex i = 0; - for ( ; i < ((HashVector*) item)->table.size; i++ ) { - void *old = HashVector_next( (HashVector*) item, &i, kod->item ); + for ( ; i < hv->table.size; i++ ) { + void *old = HashVector_next( hv, &i ); if ( old ) { + if ( key && type->base.haskey( type, old, key ) == 0 ) { + continue; + } HashVector_add( &kod->knockouts, old ); } } @@ -109,7 +115,7 @@ static int knockout_clear(Knockout *this,Relation *r,Tuple *item,int add) { // Delete them from all tables VectorIndex i; for ( i = 0; i < this->knockouts.table.size; i++ ) { - void *t = HashVector_next( &this->knockouts, &i, 0 ); + void *t = HashVector_next( &this->knockouts, &i ); if ( t ) { HashVector_delete( &r->content, t ); Vector_iterate( &r->constraints, 0, knockout_delete, t ); @@ -139,6 +145,19 @@ Vector *Relation_delete(Relation *r,Tuple *item) { } void *Relation_next(Relation *r,VectorIndex *index,Tuple *query) { - return HashVector_next( &r->content, index, query ); + HashVector *hv = &r->content; + void *key = query; + TupleSchema *type = (TupleSchema *) hv->type; + for ( ; (*index) < hv->table.size; (*index)++ ) { + void *old = HashVector_next( hv, index ); + if ( old ) { + if ( key && type->base.haskey( type, old, key ) == 0 ) { + continue; + } + return old; + } + } + (*index) = hv->table.size; + return 0; }