Volksdata 1.0b10
RDF library
Loading...
Searching...
No Matches
dataset.c
Go to the documentation of this file.
1#include "volksdata/dataset.h"
2
3
6{
7 VOLK_Dataset *ds = malloc (sizeof (*ds));
8 NLNL (ds);
9
10 ds->store = store;
11 ds->gr = VOLK_term_set_new();
12
13 return ds;
14}
15
16
19{
20 VOLK_Buffer **tdata = VOLK_store_ctx_list_txn (store, txn);
21 NLNL (tdata);
22 size_t i = 0;
23 VOLK_Dataset *ds = malloc (sizeof (*ds));
24 NLCHECK (ds, fail_ds);
25
26 ds->store = store;
27 ds->gr = VOLK_term_set_new();
28 NLCHECK (ds->gr, fail_gr);
29
30 while (tdata[i]) {
32 VOLK_rc rc = VOLK_term_set_add (ds->gr, t, NULL);
33 VOLK_buffer_free (tdata[i]);
34 if (UNLIKELY (rc != VOLK_OK)) {
36 goto fail_t;
37 }
38 i++;
39 }
40 free (tdata);
41
42 return ds;
43
44fail_t:
45 i++; // tdata[i] was already freed.
46fail_gr:
48fail_ds:
49 while (tdata[i]) VOLK_buffer_free (tdata[i++]);
50 free (tdata);
51 return NULL;
52}
53
54
55void
57{
59 free (ds);
60}
61
62
63size_t
65{
66 size_t
67 ct = 0,
68 i = 0;
69 VOLK_Term *c = NULL;
70 VOLK_rc rc;
71 while ((rc = VOLK_term_set_next (ds->gr, &i, &c)) != VOLK_END) {
72 RCCK (rc); // FIXME This only returns an undefined size_t value.
73 VOLK_Graph *gr = VOLK_graph_new (ds->store, c->data);
74 ct += VOLK_graph_size (gr);
75 VOLK_graph_free (gr);
76 }
77
78 return ct;
79}
80
81
82/*
83 * Inline prototypes.
84 */
85VOLK_rc VOLK_dataset_add (VOLK_Dataset *ds, const VOLK_Graph *gr);
86VOLK_rc VOLK_dataset_remove (VOLK_Dataset *ds, const VOLK_Graph *gr);
87bool VOLK_dataset_contains (VOLK_Dataset *ds, const VOLK_Graph *gr);
#define UNLIKELY(x)
Definition core.h:39
VOLK_Dataset * VOLK_dataset_new(VOLK_Store *store)
Create an empty dataset.
Definition dataset.c:5
bool VOLK_dataset_contains(VOLK_Dataset *ds, const VOLK_Graph *gr)
Check if a graph is in a dataset.
Definition dataset.h:122
VOLK_Dataset * VOLK_dataset_new_from_store_txn(void *txn, VOLK_Store *store)
Create a dataset populated with a whole store.
Definition dataset.c:18
void VOLK_dataset_free(VOLK_Dataset *ds)
Free a dataset handle.
Definition dataset.c:56
size_t VOLK_dataset_size(VOLK_Dataset *ds)
Number of triples in a dataset.
Definition dataset.c:64
VOLK_rc VOLK_dataset_remove(VOLK_Dataset *ds, const VOLK_Graph *gr)
Remove graphs from the dataset.
Definition dataset.h:101
VOLK_rc VOLK_dataset_add(VOLK_Dataset *ds, const VOLK_Graph *gr)
Add graphs to the dataset.
Definition dataset.h:82
#define NLCHECK(exp, marker)
Log error and jump to marker if exp is NULL.
Definition core.h:337
#define NLNL(exp)
Log error and return NULL if exp is NULL.
Definition core.h:401
#define RCCK(exp)
Return exp return value if it is of VOLK_rc type and nonzero.
Definition core.h:346
#define VOLK_END
Loop end.
Definition core.h:119
#define VOLK_OK
Generic success return code.
Definition core.h:95
int VOLK_rc
Return code.
Definition core.h:91
VOLK_Buffer ** VOLK_store_ctx_list_txn(VOLK_Store *store, void *txn)
get index of all graph (context) URIs in a store.
Definition store.c:224
VOLK_rc VOLK_term_set_next(VOLK_TermSet *ts, size_t *i, VOLK_Term **term)
Iterate trough a term set.
Definition term.c:597
VOLK_TermSet * VOLK_term_set_new()
Create a new term set.
Definition term.c:548
void VOLK_term_set_free(VOLK_TermSet *ts)
Free a term set.
Definition term.c:609
void VOLK_term_free(VOLK_Term *term)
Definition term.c:392
VOLK_Term * VOLK_term_new_from_buffer(const VOLK_Buffer *sterm)
See notes in VOLK_term_serialize function body for format info.
Definition term.c:194
VOLK_rc VOLK_term_set_add(VOLK_TermSet *ts, VOLK_Term *term, VOLK_Term **ins)
Add term to a term set.
Definition term.c:561
void VOLK_buffer_free(VOLK_Buffer *buf)
Free a buffer.
Definition buffer.c:97
void VOLK_graph_free(VOLK_Graph *gr)
Free a graph.
Definition graph.c:263
#define VOLK_graph_size(...)
Non-transactional version of VOLK_graph_size_txn().
Definition graph.h:291
VOLK_Graph * VOLK_graph_new(VOLK_Store *store, const char *uri_str)
Create new graph.
Definition graph.c:45
General-purpose data buffer.
Definition buffer.h:47
RDF Dataset type.
Definition dataset.h:26
VOLK_Store * store
Definition dataset.h:27
VOLK_TermSet * gr
Graphs in the dataset.
Definition dataset.h:29
Store structure.
Definition store.h:59
RDF term.
Definition term.h:61
char * data
URI, literal value, or BNode label.
Definition term.h:62