// Iteration context for adding or querying a relation
typedef struct {
relation *rel;
- vector knockouts;
+ hashvector knockouts;
void *item;
} knockout;
for ( ; i < ((hashvector*) item)->table.size; i++ ) {
void *old = hashvector_next( (hashvector*) item, &i, kod->item );
if ( old ) {
- vector_append( &kod->knockouts, old );
+ hashvector_add( &kod->knockouts, old );
}
}
return 0;
}
// delete the (tuple*)item from the (hashvector*)data
-static int knockout_delete_item(vector_index index,void *item,void *data) {
- hashvector_delete( (hashvector*)data, item );
- return 0;
-}
-
-// delete the tuples of (vector*)data from the (hashvector*)item
static int knockout_delete(vector_index index,void *item,void *data) {
- vector_iterate( (vector*)data, 0, knockout_delete_item, item );
+ hashvector_delete( (hashvector*) item, data );
return 0;
}
(*this) = (knockout) {
.rel = r,
.knockouts = {
- .variant = bitpair_index_levels,
- .size = 0, .entries = 0
+ .table = {
+ .variant = nibble_index_levels, .size = 16, .entries = 0
+ },
+ .fill = 0, .holes = 0, .type = r->content.type,
},
.item = item
};
knockout_check( 0, &r->content, this );
- if ( add && this->knockouts.size > 0 ) {
- return 0;
+ if ( add ) {
+ if ( this->knockouts.fill > 0 ) {
+ return 0;
+ }
+ // Find all constraint knockouts for addition
+ vector_iterate( &r->constraints, 0, knockout_check, this );
}
- // Find all constraint knockouts
- vector_iterate( &r->constraints, 0, knockout_check, this );
- if ( this->knockouts.size > 0 ) {
+ if ( this->knockouts.fill > 0 ) {
// Delete them from all tables
- vector_iterate(
- &this->knockouts, 0, knockout_delete_item, &r->content );
- vector_iterate(
- &r->constraints, 0, knockout_delete, &this->knockouts );
+ vector_index i;
+ for ( i = 0; i < this->knockouts.table.size; i++ ) {
+ void *t = hashvector_next( &this->knockouts, &i, 0 );
+ if ( t ) {
+ hashvector_delete( &r->content, t );
+ vector_iterate( &r->constraints, 0, knockout_delete, t );
+ }
+ }
}
return 1;
}
// Add the new tuple
hashvector_add( &r->content, item );
vector_iterate( &r->constraints, 0, knockout_add, item );
- if ( data.knockouts.size > 0 ) {
- return vector_clone( single_index_level, &data.knockouts );
- }
+ return hashvector_contents( &data.knockouts, single_index_level, 0 );
}
return 0;
}
vector *relation_delete(relation *r,tuple *item) {
knockout data;
(void) knockout_clear( &data, r, item, 0 );
- if ( data.knockouts.size > 0 ) {
- return vector_clone( single_index_level, &data.knockouts );
- }
- return 0;
+ return hashvector_contents( &data.knockouts, single_index_level, 0 );
}
void *relation_next(relation *r,vector_index *index,tuple *query) {