3 #include <HashVector.h>
4 #include <QueryCallbacks.h>
6 #include <stringitem.h>
9 * A View is a "virtual relation" that captures the differences at
10 * successive evaluations in the binding sequences offered by a query.
13 struct QueryCallbacks *def;
15 * This is the source query to be a view of.
19 * This is the size of the names tuple.
23 * This is the binding names to track.
27 * This is the collection of bindings for the tracked names being
28 * gained at the latest evaluation.
32 * This is the collection of bindings for the tracked names being
33 * last at the latest evaluation.
38 static Tuple *View_type_Tuple(HashVector *hv) {
39 Tuple *t = Tuple_calloc( hv->fill );
40 VectorIndex index = 0;
41 for ( ; index < hv->table.size; index++ ) {
42 t->elements[ index ] = &stringitem;
47 static QueryCallbacks View_def = {
53 Query *View_create(Query *q) {
54 View *vq = (View*) malloc( sizeof( View ) );
55 HashVector hv = (HashVector) {
57 .variant = Nibble_index_levels, .size = 16, .entries = 0
59 .fill = 0, .holes = 0, .type = &stringitem
61 q->def->variables( q, &hv ); // Obtain query variables
63 TupleSchema *ts = TupleSchema_create( hv.fill, View_type_Tuple( &hv ) );
68 .gained = (HashVector) {
70 .variant = Nibble_index_levels,
74 .fill = 0, .holes = 0, .type = (ItemKeyFun*) ts
76 .lost = (HashVector) {
78 .variant = Nibble_index_levels,
82 .fill = 0, .holes = 0, .type = (ItemKeyFun*) ts