29graph_iter_next_buffer (VOLK_GraphIterator *it);
32#define ENTRY(a, b) (be) == (VOLK_STORE_##a) ||
51 VOLK_STORE_HTABLE, NULL, 0,
false);
68 store->
data, NULL, NULL, NULL, sc, NULL, NULL);
102 const VOLK_Graph *gr1,
const VOLK_Graph *gr2, VOLK_Graph *res)
110 log_error (
"Invalid boolean operation: %d.", op);
133 void *lu1_it, *lu2_it, *add_it;
147 add_it = res->store->sif->add_init_fn (res->store->data, res_sc, txn);
150 res_txn = res->store->sif->iter_txn_fn (add_it);
158 if (gr1->store == res->store) lu1_txn = res_txn;
161 CHECK (gr1->store->sif->txn_begin_fn (
162 gr1->store->data, MDB_RDONLY, &lu1_txn), fail);
169 if (gr2->store == res->store) lu2_txn = res_txn;
170 else if (gr2->store == gr1->store) lu2_txn = lu1_txn;
173 CHECK (gr2->store->sif->txn_begin_fn (
174 gr2->store->data, MDB_RDONLY, &lu2_txn), fail);
179 "lu1_txn: %p ; lu2_txn: %p ; res_txn: %p",
180 lu1_txn, lu2_txn, res_txn);
186 lu2_it = gr2->store->sif->lookup_fn (
187 gr2->store->data, NULL, NULL, NULL, gr2_sc, lu2_txn, NULL);
188 while (gr2->store->sif->lu_next_fn (lu2_it, sspo, NULL) ==
VOLK_OK) {
189 lu1_it = gr1->store->sif->lookup_fn (
190 gr1->store->data, sspo->
s, sspo->
p, sspo->
o, gr1_sc,
193 res->store->sif->add_iter_fn (add_it, sspo);
196 gr1->store->sif->lu_free_fn (lu1_it);
198 gr2->store->sif->lu_free_fn (lu2_it);
203 lu1_it = gr1->store->sif->lookup_fn (
204 gr1->store->data, NULL, NULL, NULL, gr1_sc, lu1_txn, NULL);
205 while (gr1->store->sif->lu_next_fn (lu1_it, sspo, NULL) ==
VOLK_OK) {
206 lu2_it = gr2->store->sif->lookup_fn (
207 gr2->store->data, sspo->
s, sspo->
p, sspo->
o, gr2_sc,
211 gr1->store->sif->lu_free_fn (lu1_it);
217 res->store->sif->add_iter_fn (add_it, sspo);
220 gr2->store->sif->lu_free_fn (lu2_it);
222 gr1->store->sif->lu_free_fn (lu1_it);
224 if (open_txn1) gr1->store->sif->txn_commit_fn (lu1_txn);
225 if (open_txn2) gr2->store->sif->txn_commit_fn (lu2_txn);
227 res->store->sif->add_done_fn (add_it);
238 if (lu1_txn) gr1->store->sif->txn_abort_fn (lu1_txn);
239 if (lu2_txn) gr2->store->sif->txn_abort_fn (lu2_txn);
253 gr->store->sif->free_fn (gr->store->data);
254 free (gr->store->id);
287 if (
UNLIKELY (!old_sc || !new_sc)) {
292 PCHECK (rc = gr->store->sif->update_ctx_fn (
293 gr->store->data, old_sc, new_sc, NULL),
finally);
315 void *it = gr->store->sif->lookup_fn (
316 gr->store->data, NULL, NULL, NULL, sc, NULL, &ct);
318 log_error (
"Error initializing lookup.");
321 gr->store->sif->lu_free_fn (it);
345 VOLK_GraphIterator *it;
350 it->data = gr->store->sif->add_init_fn (gr->store->data, sc, txn);
363 "Adding triple {%s, %s, %s} to %s",
378 "Adding relative triple: {%s, %s, %s}",
398 for (
int i = 0; i < 3; i++) {
406 it->graph->store->data, ser_dtype, txn);
407 PCHECK (term_rc,
finally);
423 void *txn, VOLK_Graph *gr,
VOLK_Triple *
const *trp,
size_t *ct)
432 for (
size_t i = 0; trp[i] != NULL; i++) {
457 void *txn, VOLK_Graph *gr,
467 VOLK_rc rc = gr->store->sif->remove_fn (
468 gr->store->data, ss, sp, so, sc, txn, ct);
481 void *txn,
const VOLK_Graph *src, VOLK_Graph *dest,
494 else if (add_rc < 0) {
509 void *txn,
const VOLK_Graph *gr,
513 VOLK_GraphIterator *it;
537 it->data = gr->store->sif->lookup_fn (
538 gr->store->data, ss, sp, so, sc, txn, ct);
555 if (
UNLIKELY (it->sspo == NULL))
return NULL;
570 VOLK_rc rc = graph_iter_next_buffer (it);
594{
return it->sspo == NULL; }
604 it->graph->store->sif->lu_free_fn (it->data);
612 LOG_DEBUG(
"Freeing dummy triple @ %p", it->sspo);
619 it->graph->store->sif->add_done_fn (it->data);
657 gr, spo->
s, spo->
p, spo->
o, NULL);
674 log_error (
"Could not inspect graph for printing.");
678 printf (
"*** Graph %s (%zu triples):\n\n", gr->uri->data, ct);
685 "#%-6zu {%s %s %s}\n",
691 "Output truncated due to abnormal return: %s",
721 log_error (
"Invalid connection type: %d", type);
727 if (!it)
return NULL;
730 while (graph_iter_next_buffer (it) !=
VOLK_END) {
742 if (!ret)
return NULL;
761 if (t1_pos == t2_pos) {
762 log_error (
"Term 1 and 2 positions cannot be the same!");
770 for (
unsigned i = 0; i < 3; i++)
771 if (t1_pos != i && t2_pos != i) rpos = i;
774 gr, spo_l[0], spo_l[1], spo_l[2], NULL);
777 while (graph_iter_next_buffer (it) !=
VOLK_END) {
797 while (graph_iter_next_buffer (it) !=
VOLK_END) {
887graph_iter_next_buffer (VOLK_GraphIterator *it)
888{
return it->graph->store->sif->lu_next_fn (it->data, it->sspo, NULL); }
bool VOLK_graph_iter_is_add(VOLK_GraphIterator *it)
VOLK_Buffer * VOLK_btriple_pos(const VOLK_BufferTriple *trp, VOLK_TriplePos n)
Get serialized triple by term position.
#define BTRP_DUMMY
Dummy buffer triple.
void VOLK_btriple_free(VOLK_BufferTriple *sspo)
Free a buffer triple and all its internal pointers.
VOLK_TriplePos
Triple position of s, p, o.
void VOLK_buffer_free(VOLK_Buffer *buf)
Free a buffer.
#define VOLK_graph_lookup(...)
Non-transactional version of VOLK_graph_lookup_txn.
VOLK_Graph * VOLK_graph_new_ns(VOLK_Store *store, const char *ns_str)
Create an empty graph using a namespace-prefixed string for its URI.
const VOLK_Graph * VOLK_graph_iter_graph(VOLK_GraphIterator *it)
Return the graph related to an iterator.
VOLK_TermSet * VOLK_graph_list_txn(void *txn, VOLK_Store *store)
List all graph URIs in a store.
void VOLK_graph_print(const VOLK_Graph *gr)
Print graph information and triples to stdout.
VOLK_LinkMap * VOLK_graph_connections(const VOLK_Graph *gr, const VOLK_Term *t, const VOLK_LinkType type)
Get term pairs connected to a term in a graph.
VOLK_Graph * VOLK_graph_get_txn(void *txn, VOLK_Store *store, const VOLK_Term *uri, size_t *ct)
Create a temp graph from stored triples.
size_t VOLK_graph_add_link_map(VOLK_GraphIterator *it, VOLK_LinkMap *lm)
Add triples for a term and related link map to a graph.
bool VOLK_graph_contains(const VOLK_Graph *gr, const VOLK_Triple *spo)
Whether a graph contains a triple.
bool VOLK_graph_equals(const VOLK_Graph *gr1, const VOLK_Graph *gr2)
Compare two graphs.
VOLK_rc VOLK_graph_remove_txn(void *txn, VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o, size_t *ct)
Delete triples by a matching pattern.
VOLK_rc VOLK_graph_copy_contents_txn(void *txn, const VOLK_Graph *src, VOLK_Graph *dest, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o)
Copy triples from a source graph into a destination one.
void VOLK_graph_free(VOLK_Graph *gr)
Free a graph.
VOLK_rc VOLK_graph_add_txn(void *txn, VOLK_Graph *gr, VOLK_Triple *const *trp, size_t *ct)
Add triples to a graph.
VOLK_GraphIterator * VOLK_graph_lookup_txn(void *txn, const VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o, size_t *ct)
Look up triples by a matching pattern and yield an iterator.
#define VOLK_graph_copy_contents(...)
VOLK_rc VOLK_graph_bool_op_txn(void *txn, const VOLK_bool_op op, const VOLK_Graph *gr1, const VOLK_Graph *gr2, VOLK_Graph *res)
VOLK_TermSet * VOLK_graph_unique_terms(const VOLK_Graph *gr, VOLK_TriplePos pos)
Get all unique subjcts, predicates, or objects in a graph.
#define VOLK_graph_bool_op(...)
Non-transactional version of VOLK_graph_bool_op_txn.
VOLK_Store * VOLK_graph_store(const VOLK_Graph *gr)
Underlying graph store handle.
VOLK_GraphIterator * VOLK_graph_add_init_txn(void *txn, VOLK_Graph *gr)
Initialize an iterator to add triples.
VOLK_rc VOLK_graph_iter_next(VOLK_GraphIterator *it, VOLK_Triple **spo_p)
Advance a cursor obtained by a lookup and return a matching triple.
VOLK_rc VOLK_graph_set_uri(VOLK_Graph *gr, const char *uri_str)
VOLK_Term * VOLK_bnode_add_collection(VOLK_GraphIterator *it, VOLK_TermSet *ts)
Add triples for an anonymous collection to a graph.
VOLK_rc VOLK_graph_add_iter(VOLK_GraphIterator *it, const VOLK_Triple *spo)
Add a single triple to the store.
void VOLK_graph_iter_free(VOLK_GraphIterator *it)
Free a graph iterator.
VOLK_TermSet * VOLK_graph_term_set(const VOLK_Graph *gr, const VOLK_Term *t1, const VOLK_TriplePos t1_pos, const VOLK_Term *t2, const VOLK_TriplePos t2_pos)
Get a list of terms related to a term pair in a graph.
VOLK_Graph * VOLK_graph_new(VOLK_Store *store, const char *uri_str)
Create new graph.
const VOLK_Term * VOLK_graph_uri(const VOLK_Graph *gr)
Read-only graph URI.
size_t VOLK_graph_size(const VOLK_Graph *gr)
Number of triples in a graph.
#define MALLOC_GUARD(var, rc)
Allocate one pointer with malloc and return rc if it fails.
#define PCHECK(exp, marker)
Jump to marker if exp returns a negative value (skip warnings).
#define PRCNL(exp)
Return NULL if exp returns a negative value (=error).
#define CHECK(exp, marker)
Jump to marker if exp does not return VOLK_OK.
#define CALLOC_GUARD(var, rc)
Allocate one pointer with calloc and return rc if it fails.
#define PRCCK(exp)
Return exp return value if it is of VOLK_rc type and negative (=error).
VOLK_bool_op
Boolean operations that can be performed on a graph.
@ VOLK_BOOL_XOR
Boolean XOR.
@ VOLK_BOOL_UNION
Boolean union.
@ VOLK_BOOL_SUBTRACTION
Boolean subtraction.
@ VOLK_BOOL_INTERSECTION
Boolean intersection.
#define VOLK_VALUE_ERR
An invalid input value was provided.
#define VOLK_MEM_ERR
Memory allocation error.
#define VOLK_NORESULT
No result yielded.
#define VOLK_DB_ERR
Low-level database error.
#define VOLK_END
Loop end.
#define VOLK_OK
Generic success return code.
#define VOLK_NOACTION
No action taken.
const char * VOLK_strerror(VOLK_rc rc)
Return an error message for a return code.
@ VOLK_STORE_TXN
Supports transaction handling.
@ VOLK_STORE_COW
Copy on write.
VOLK_Buffer ** VOLK_store_ctx_list_txn(VOLK_Store *store, void *txn)
get index of all graph (context) URIs in a store.
VOLK_StoreType
Store types. All prefixed with VOLK_STORE_.
VOLK_Store * VOLK_store_new(const VOLK_StoreType store_type, const char *store_id, size_t size, bool clear)
Create a new store.
VOLK_rc VOLK_term_set_add(VOLK_TermSet *ts, VOLK_Term *term, VOLK_Term **existing)
Add term to a term set.
VOLK_Triple * VOLK_triple_new_from_btriple(const VOLK_BufferTriple *sspo)
struct hashmap VOLK_TermSet
a set of unique terms.
VOLK_rc VOLK_term_set_next(VOLK_TermSet *ts, size_t *i, VOLK_Term **term)
Iterate trough a term set.
VOLK_Triple * VOLK_triple_new(VOLK_Term *s, VOLK_Term *p, VOLK_Term *o)
Create a new triple from three terms.
VOLK_Term * VOLK_iriref_new_rel(const VOLK_Term *root, const VOLK_Term *iri)
Create a new relative IRI from an absolute IRI and a web root IRI.
void VOLK_link_map_iter_free(VOLK_LinkMapIterator *it)
Free a link map iterator.
VOLK_Term * VOLK_iriref_new(const char *data)
Create an IRI reference.
VOLK_LinkMapIterator * VOLK_link_map_iter_new(const VOLK_LinkMap *lmap)
Create a new iterator to loop through a link map.
VOLK_LinkMap * VOLK_link_map_new(const VOLK_Term *linked_term, VOLK_LinkType type)
New link map.
VOLK_rc VOLK_link_map_triples(VOLK_LinkMapIterator *it, VOLK_Triple *spo)
Iterate over a link map and generate triples.
VOLK_TermSet * VOLK_term_set_new()
Create a new term set.
void VOLK_term_set_free(VOLK_TermSet *ts)
Free a term set.
#define TRP_DUMMY
Dummy triple with NULL slots. It is not a valid triple.
void VOLK_term_free(VOLK_Term *term)
VOLK_Term * VOLK_triple_pos(const VOLK_Triple *trp, VOLK_TriplePos n)
Get triple by term position.
VOLK_Buffer * VOLK_term_serialize(const VOLK_Term *term)
Serialize a term into a buffer.
VOLK_Term * VOLK_term_new_from_buffer(const VOLK_Buffer *sterm)
See notes in VOLK_term_serialize function body for format info.
VOLK_rc VOLK_link_map_add(VOLK_LinkMap *lmap, VOLK_Term *term, VOLK_TermSet *tset)
Add a term - term set pair to a link map.
VOLK_BufferTriple * VOLK_triple_serialize(const VOLK_Triple *spo)
VOLK_Term * VOLK_term_new(VOLK_TermType type, const char *data, void *metadata)
Create a new term.
void VOLK_triple_free(VOLK_Triple *spo)
Free a triple and all its internal pointers.
VOLK_Term * VOLK_term_copy(const VOLK_Term *src)
Copy a term.
@ VOLK_LINK_EDGE
Edge link (so).
@ VOLK_LINK_INBOUND
Inbound link (sp).
@ VOLK_LINK_OUTBOUND
Outbound link (po).
@ VOLK_TERM_IRIREF
IRI reference.
@ VOLK_TERM_LITERAL
Literal without language tag.
@ VOLK_TERM_BNODE
Blank node.
General-purpose data buffer.
VOLK_StoreFeature features
Feature flags.
iter_free_fn_t lu_free_fn
Free the lookup iterator.
store_add_iter_fn_t add_iter_fn
Add one triple.
store_add_term_fn_t add_term_fn
iter_txn_fn_t iter_txn_fn
Get iterator's transaction.
iter_next_fn_t lu_next_fn
Advance the lookup iterator.
store_lookup_fn_t lookup_fn
Look up triples by pattern.
void * data
Store back end data.
const VOLK_StoreInt * sif
Store interface.
char * data
URI, literal value, or BNode label.
struct term_t * datatype
Data type IRI for VOLK_TERM_LITERAL.
VOLK_TermType type
Term type.
const VOLK_Graph * graph
Parent graph.
size_t ct
Total lookup matches.
void * data
Iterator state.
VOLK_Store * store
Store handle.
VOLK_Term * uri
Graph "name" (URI).