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 ] = HashVector_next( hv, &index );
47 static void View_reclaim(Query *this) {
48 View *v = (View*) this;
49 TupleSchema *ts = (TupleSchema*) gained->type;
50 Vector_resize( &v->gained, 0, Vector_clear_any, 0 );
51 Vector_resize( &v->lost, 0, Vector_clear_any, 0 );
57 static QueryCallbacks View_def = {
58 .reclaim = View_reclaim,
63 Query *View_create(Query *q) {
64 View *vq = (View*) malloc( sizeof( View ) );
65 HashVector hv = (HashVector) {
67 .variant = Nibble_index_levels, .size = 16, .entries = 0
69 .fill = 0, .holes = 0, .type = &stringitem
71 q->def->variables( q, &hv ); // Obtain query variables
73 TupleSchema *ts = TupleSchema_create( hv.fill, View_type_Tuple( &hv ) );
78 .gained = (HashVector) {
80 .variant = Nibble_index_levels,
84 .fill = 0, .holes = 0, .type = (ItemKeyFun*) ts
86 .lost = (HashVector) {
88 .variant = Nibble_index_levels,
92 .fill = 0, .holes = 0, .type = (ItemKeyFun*) ts
95 Vector_resize( &hv, 0, Vector_clear_any, 0 );