|
@@ -1,4 +1,3 @@
|
|
-#include "htable.h"
|
|
|
|
#include "graph.h"
|
|
#include "graph.h"
|
|
|
|
|
|
// Initial size of lookup graph. It will double each time capacity is reached.
|
|
// Initial size of lookup graph. It will double each time capacity is reached.
|
|
@@ -31,7 +30,7 @@ typedef struct Graph {
|
|
LSUP_store_type store_type; // In-memory or MDB-backed
|
|
LSUP_store_type store_type; // In-memory or MDB-backed
|
|
LSUP_Term *uri; // Graph "name" (URI)
|
|
LSUP_Term *uri; // Graph "name" (URI)
|
|
union {
|
|
union {
|
|
- LSUP_HTStore * ht_store;
|
|
|
|
|
|
+ //LSUP_HTStore * ht_store;
|
|
LSUP_MDBStore * mdb_store;
|
|
LSUP_MDBStore * mdb_store;
|
|
};
|
|
};
|
|
} Graph;
|
|
} Graph;
|
|
@@ -40,7 +39,7 @@ typedef struct Graph {
|
|
typedef struct GraphIterator {
|
|
typedef struct GraphIterator {
|
|
const Graph * graph; // Parent graph.
|
|
const Graph * graph; // Parent graph.
|
|
union { // Internal store iterator.
|
|
union { // Internal store iterator.
|
|
- LSUP_HTIterator * ht_iter;
|
|
|
|
|
|
+ //LSUP_HTIterator * ht_iter;
|
|
LSUP_MDBIterator * mdb_iter;
|
|
LSUP_MDBIterator * mdb_iter;
|
|
};
|
|
};
|
|
size_t ct; // Total matches.
|
|
size_t ct; // Total matches.
|
|
@@ -54,6 +53,11 @@ typedef struct GraphIterator {
|
|
size_t LSUP_graph_size(const LSUP_Graph *gr);
|
|
size_t LSUP_graph_size(const LSUP_Graph *gr);
|
|
|
|
|
|
|
|
|
|
|
|
+/* * * Static prototypes. * * */
|
|
|
|
+
|
|
|
|
+static inline void default_ctx_init();
|
|
|
|
+
|
|
|
|
+
|
|
/* * * Post-lookup callback prototypes * * */
|
|
/* * * Post-lookup callback prototypes * * */
|
|
|
|
|
|
int match_add_fn(
|
|
int match_add_fn(
|
|
@@ -81,25 +85,27 @@ static inline bool is_null_trp(const LSUP_TripleKey *trp)
|
|
*trp[2] == NULL_KEY);
|
|
*trp[2] == NULL_KEY);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#define ENTRY(x) (be) == (x) ||
|
|
|
|
+static inline bool
|
|
|
|
+check_backend (LSUP_store_type be)
|
|
|
|
+{ return (BACKEND_TBL false); }
|
|
|
|
+#undef ENTRY
|
|
|
|
+
|
|
|
|
|
|
/* * * GRAPH * * */
|
|
/* * * GRAPH * * */
|
|
|
|
|
|
Graph *
|
|
Graph *
|
|
LSUP_graph_new(const LSUP_store_type store_type)
|
|
LSUP_graph_new(const LSUP_store_type store_type)
|
|
{
|
|
{
|
|
|
|
+ if (!check_backend(store_type)) return NULL;
|
|
|
|
+
|
|
LSUP_Graph *gr;
|
|
LSUP_Graph *gr;
|
|
CRITICAL(gr = malloc(sizeof(LSUP_Graph)));
|
|
CRITICAL(gr = malloc(sizeof(LSUP_Graph)));
|
|
|
|
|
|
- // Initialize default context only once per process.
|
|
|
|
- if(UNLIKELY(!default_ctx)) {
|
|
|
|
- LSUP_Term *default_ctx_uri = LSUP_uri_new(default_ctx_label);
|
|
|
|
- LSUP_term_serialize(default_ctx_uri, default_ctx);
|
|
|
|
- LSUP_term_free(default_ctx_uri);
|
|
|
|
- atexit(ctx_cleanup);
|
|
|
|
- }
|
|
|
|
|
|
+ default_ctx_init();
|
|
|
|
|
|
if (store_type == LSUP_STORE_MEM) {
|
|
if (store_type == LSUP_STORE_MEM) {
|
|
- gr->ht_store = LSUP_htstore_new(0);
|
|
|
|
|
|
+ // TODO uncomment gr->ht_store = LSUP_htstore_new(0);
|
|
|
|
|
|
} else if (store_type == LSUP_STORE_MDB) {
|
|
} else if (store_type == LSUP_STORE_MDB) {
|
|
gr->mdb_store = LSUP_mdbstore_new(
|
|
gr->mdb_store = LSUP_mdbstore_new(
|
|
@@ -150,6 +156,7 @@ LSUP_graph_copy(const Graph *src)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+/* TODO uncomment
|
|
Graph *
|
|
Graph *
|
|
LSUP_graph_bool_op(
|
|
LSUP_graph_bool_op(
|
|
const LSUP_bool_op op, const Graph *gr1, const Graph *gr2)
|
|
const LSUP_bool_op op, const Graph *gr1, const Graph *gr2)
|
|
@@ -176,6 +183,7 @@ LSUP_graph_bool_op(
|
|
|
|
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
+*/
|
|
|
|
|
|
|
|
|
|
void
|
|
void
|
|
@@ -185,7 +193,7 @@ LSUP_graph_free(LSUP_Graph *gr)
|
|
LSUP_term_free(gr->uri);
|
|
LSUP_term_free(gr->uri);
|
|
|
|
|
|
if (gr->store_type == LSUP_STORE_MEM)
|
|
if (gr->store_type == LSUP_STORE_MEM)
|
|
- LSUP_htstore_free(gr->ht_store);
|
|
|
|
|
|
+ NULL;// TODO uncomment LSUP_htstore_free(gr->ht_store);
|
|
else
|
|
else
|
|
LSUP_mdbstore_free(gr->mdb_store);
|
|
LSUP_mdbstore_free(gr->mdb_store);
|
|
|
|
|
|
@@ -207,7 +215,7 @@ LSUP_rc
|
|
LSUP_graph_resize(LSUP_Graph *gr, size_t size)
|
|
LSUP_graph_resize(LSUP_Graph *gr, size_t size)
|
|
{
|
|
{
|
|
if (gr->store_type == LSUP_STORE_MEM)
|
|
if (gr->store_type == LSUP_STORE_MEM)
|
|
- return LSUP_htstore_resize(gr->ht_store, size);
|
|
|
|
|
|
+ return 0;// TODO uncomment LSUP_htstore_resize(gr->ht_store, size);
|
|
|
|
|
|
return LSUP_VALUE_ERR;
|
|
return LSUP_VALUE_ERR;
|
|
}
|
|
}
|
|
@@ -217,7 +225,7 @@ size_t
|
|
LSUP_graph_capacity(const Graph *gr)
|
|
LSUP_graph_capacity(const Graph *gr)
|
|
{
|
|
{
|
|
if(gr->store_type == LSUP_STORE_MEM)
|
|
if(gr->store_type == LSUP_STORE_MEM)
|
|
- return LSUP_htstore_capacity(gr->ht_store);
|
|
|
|
|
|
+ return 0;// TODO uncomment LSUP_htstore_capacity(gr->ht_store);
|
|
|
|
|
|
return LSUP_NOT_IMPL_ERR;
|
|
return LSUP_NOT_IMPL_ERR;
|
|
}
|
|
}
|
|
@@ -227,7 +235,7 @@ size_t
|
|
LSUP_graph_size(const Graph *gr)
|
|
LSUP_graph_size(const Graph *gr)
|
|
{
|
|
{
|
|
if(gr->store_type == LSUP_STORE_MEM)
|
|
if(gr->store_type == LSUP_STORE_MEM)
|
|
- return LSUP_htstore_size(gr->ht_store);
|
|
|
|
|
|
+ return 0;// TODO uncomment LSUP_htstore_size(gr->ht_store);
|
|
|
|
|
|
return LSUP_mdbstore_size(gr->mdb_store);
|
|
return LSUP_mdbstore_size(gr->mdb_store);
|
|
}
|
|
}
|
|
@@ -247,6 +255,7 @@ LSUP_graph_add(
|
|
* NOTE It is possible to pass both sets of RDF triples and buffer triples.
|
|
* NOTE It is possible to pass both sets of RDF triples and buffer triples.
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+ /* TODO uncomment
|
|
if (gr->store_type == LSUP_STORE_MEM) {
|
|
if (gr->store_type == LSUP_STORE_MEM) {
|
|
// Resize all at once if needed.
|
|
// Resize all at once if needed.
|
|
htsize_t prealloc = LSUP_htstore_size(gr->ht_store) + trp_ct + strp_ct;
|
|
htsize_t prealloc = LSUP_htstore_size(gr->ht_store) + trp_ct + strp_ct;
|
|
@@ -291,6 +300,7 @@ LSUP_graph_add(
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
}
|
|
}
|
|
|
|
+ */
|
|
|
|
|
|
if (gr->store_type == LSUP_STORE_MDB) {
|
|
if (gr->store_type == LSUP_STORE_MDB) {
|
|
rc = LSUP_NOACTION;
|
|
rc = LSUP_NOACTION;
|
|
@@ -334,6 +344,8 @@ LSUP_graph_add(
|
|
}
|
|
}
|
|
|
|
|
|
LSUP_mdbstore_add_done(it, NULL);
|
|
LSUP_mdbstore_add_done(it, NULL);
|
|
|
|
+
|
|
|
|
+ return rc;
|
|
}
|
|
}
|
|
|
|
|
|
return LSUP_VALUE_ERR;
|
|
return LSUP_VALUE_ERR;
|
|
@@ -350,7 +362,7 @@ LSUP_graph_remove(Graph *gr, const LSUP_Triple *spo, size_t *ct)
|
|
LSUP_Buffer *sc = LSUP_buffer_new_from_term(gr->uri);
|
|
LSUP_Buffer *sc = LSUP_buffer_new_from_term(gr->uri);
|
|
|
|
|
|
if (gr->store_type == LSUP_STORE_MEM)
|
|
if (gr->store_type == LSUP_STORE_MEM)
|
|
- rc = LSUP_htstore_remove(gr->ht_store, &sspo, ct);
|
|
|
|
|
|
+ rc = 0;// TODO uncomment LSUP_htstore_remove(gr->ht_store, &sspo, ct);
|
|
else
|
|
else
|
|
rc = LSUP_mdbstore_remove(gr->mdb_store, &sspo, sc, ct);
|
|
rc = LSUP_mdbstore_remove(gr->mdb_store, &sspo, sc, ct);
|
|
|
|
|
|
@@ -374,7 +386,7 @@ LSUP_graph_lookup(const Graph *gr, const LSUP_Triple *spo)
|
|
LSUP_Buffer *sc = LSUP_buffer_new_from_term(gr->uri);
|
|
LSUP_Buffer *sc = LSUP_buffer_new_from_term(gr->uri);
|
|
|
|
|
|
if (gr->store_type == LSUP_STORE_MEM) {
|
|
if (gr->store_type == LSUP_STORE_MEM) {
|
|
- it->ht_iter = LSUP_htstore_lookup(gr->ht_store, &sspo, &it->ct);
|
|
|
|
|
|
+ // TODO uncomment it->ht_iter = LSUP_htstore_lookup(gr->ht_store, &sspo, &it->ct);
|
|
|
|
|
|
} else {
|
|
} else {
|
|
it->mdb_iter = LSUP_mdbstore_lookup(gr->mdb_store, &sspo, sc, &it->ct);
|
|
it->mdb_iter = LSUP_mdbstore_lookup(gr->mdb_store, &sspo, sc, &it->ct);
|
|
@@ -398,7 +410,7 @@ graph_iter_next_buffer(GraphIterator *it, LSUP_SerTriple *sspo)
|
|
LSUP_rc rc;
|
|
LSUP_rc rc;
|
|
|
|
|
|
if (it->graph->store_type == LSUP_STORE_MEM)
|
|
if (it->graph->store_type == LSUP_STORE_MEM)
|
|
- rc = LSUP_htiter_next(it->ht_iter, sspo);
|
|
|
|
|
|
+ rc = 0;// TODO uncomment LSUP_htiter_next(it->ht_iter, sspo);
|
|
else rc = LSUP_mdbiter_next(it->mdb_iter, sspo);
|
|
else rc = LSUP_mdbiter_next(it->mdb_iter, sspo);
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
@@ -427,7 +439,7 @@ void
|
|
LSUP_graph_iter_free(GraphIterator *it)
|
|
LSUP_graph_iter_free(GraphIterator *it)
|
|
{
|
|
{
|
|
if (it->graph->store_type == LSUP_STORE_MEM)
|
|
if (it->graph->store_type == LSUP_STORE_MEM)
|
|
- LSUP_htiter_free(it->ht_iter);
|
|
|
|
|
|
+ NULL;// TODO uncomment LSUP_htiter_free(it->ht_iter);
|
|
else
|
|
else
|
|
LSUP_mdbiter_free(it->mdb_iter);
|
|
LSUP_mdbiter_free(it->mdb_iter);
|
|
|
|
|
|
@@ -445,3 +457,17 @@ LSUP_graph_contains(const LSUP_Graph *gr, const LSUP_Triple *spo)
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/* * * Static functions * * */
|
|
|
|
+
|
|
|
|
+static inline void default_ctx_init()
|
|
|
|
+{
|
|
|
|
+ // Initialize default context only once per process.
|
|
|
|
+ if(UNLIKELY(!default_ctx)) {
|
|
|
|
+ LSUP_Term *default_ctx_uri = LSUP_uri_new(default_ctx_label);
|
|
|
|
+ default_ctx = LSUP_buffer_new_from_term(default_ctx_uri);
|
|
|
|
+ LSUP_term_free(default_ctx_uri);
|
|
|
|
+ atexit(ctx_cleanup);
|
|
|
|
+ }
|
|
|
|
+}
|