From 813cf9d12ff1b1c58e508485c977d33caaf89a86 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Wed, 13 Jul 2022 20:16:42 +1000 Subject: [PATCH] starting on View --- vector/Query.h | 2 +- vector/QueryCallbacks.h | 6 ++- vector/View.c | 86 +++++++++++++++++++++++++++++++++++++++++ vector/View.h | 5 +++ 4 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 vector/View.c create mode 100644 vector/View.h diff --git a/vector/Query.h b/vector/Query.h index f13083d..188a1ea 100644 --- a/vector/Query.h +++ b/vector/Query.h @@ -14,7 +14,7 @@ struct QueryCallbacks; * a separate \ref Querytype record similar to how \ref ItemKeyFun * records define valye types. */ -typedef struct { +typedef struct Query { struct QueryCallbacks *def; } Query; diff --git a/vector/QueryCallbacks.h b/vector/QueryCallbacks.h index b74550a..ad4461b 100644 --- a/vector/QueryCallbacks.h +++ b/vector/QueryCallbacks.h @@ -2,6 +2,8 @@ #define QueryCallbacks_H typedef struct HashVector HashVector; +typedef struct Query Query; +typedef struct BindingTable BindingTable;; enum NextState { /** @@ -27,7 +29,7 @@ enum NextState { * A struct Query_callbacks record defines the callbacks for a * specific Query type. */ -struct QueryCallbacks { +typedef struct QueryCallbacks { /** * \brief Callback function to reclaim the Query memory for a * given Query. @@ -69,6 +71,6 @@ struct QueryCallbacks { * hashvector. */ void (*variables)(Query *this,HashVector *hv); -}; +} QueryCallbacks; #endif diff --git a/vector/View.c b/vector/View.c new file mode 100644 index 0000000..5da2bcc --- /dev/null +++ b/vector/View.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include + +/** + * A View is a "virtual relation" that captures the differences at + * successive evaluations in the binding sequences offered by a query. + */ +typedef struct { + struct QueryCallbacks *def; + /** + * This is the source query to be a view of. + */ + Query *source; + /** + * This is the size of the names tuple. + */ + int arity; + /** + * This is the binding names to track. + */ + Tuple *names; + /** + * This is the collection of bindings for the tracked names being + * gained at the latest evaluation. + */ + HashVector gained; + /** + * This is the collection of bindings for the tracked names being + * last at the latest evaluation. + */ + HashVector lost; +} View; + +static Tuple *View_type_Tuple(HashVector *hv) { + Tuple *t = Tuple_calloc( hv->fill ); + VectorIndex index = 0; + for ( ; index < hv->table.size; index++ ) { + t->elements[ index ] = &stringitem; + } + return t; +} + +static QueryCallbacks View_def = { + .reclaim = 0, + .next = 0, + .variables = 0 +}; + +Query *View_create(Query *q) { + View *vq = (View*) malloc( sizeof( View ) ); + HashVector hv = (HashVector) { + .table = (Vector) { + .variant = Nibble_index_levels, .size = 16, .entries = 0 + }, + .fill = 0, .holes = 0, .type = &stringitem + }; + q->def->variables( q, &hv ); // Obtain query variables + + TupleSchema *ts = TupleSchema_create( hv.fill, View_type_Tuple( &hv ) ); + (*vq) = (View) { + .def = &View_def, + .source = q, + .arity = 0, + .gained = (HashVector) { + .table = (Vector) { + .variant = Nibble_index_levels, + .size = 16, + .entries = 0 + }, + .fill = 0, .holes = 0, .type = (ItemKeyFun*) ts + }, + .lost = (HashVector) { + .table = (Vector) { + .variant = Nibble_index_levels, + .size = 16, + .entries = 0 + }, + .fill = 0, .holes = 0, .type = (ItemKeyFun*) ts + } + }; + return (Query*) vq; +} diff --git a/vector/View.h b/vector/View.h new file mode 100644 index 0000000..92e38e4 --- /dev/null +++ b/vector/View.h @@ -0,0 +1,5 @@ +#ifndef View_H +#define View_H + + +#endif -- 2.39.2