summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sord.c33
-rw-r--r--src/syntax.c24
2 files changed, 30 insertions, 27 deletions
diff --git a/src/sord.c b/src/sord.c
index ff449ee..75e9287 100644
--- a/src/sord.c
+++ b/src/sord.c
@@ -314,7 +314,7 @@ sord_iter_seek_match(SordIter* iter)
for (iter->end = true;
!g_sequence_iter_is_end(iter->cur);
sord_iter_forward(iter)) {
- SordNode** const key = (SordNode**)g_sequence_get(iter->cur);
+ const SordNode** const key = (const SordNode**)g_sequence_get(iter->cur);
if (sord_quad_match_inline(key, iter->pat))
return (iter->end = false);
}
@@ -332,7 +332,7 @@ sord_iter_seek_match_range(SordIter* iter)
return true;
do {
- SordNode** key = (SordNode**)g_sequence_get(iter->cur);
+ const SordNode** key = (const SordNode**)g_sequence_get(iter->cur);
if (sord_quad_match_inline(key, iter->pat))
return false; // Found match
@@ -371,7 +371,7 @@ sord_iter_new(const SordModel* sord, GSequenceIter* cur, const SordQuad pat,
case SINGLE:
case RANGE:
assert(
- sord_quad_match_inline((SordNode**)g_sequence_get(iter->cur),
+ sord_quad_match_inline((const SordNode**)g_sequence_get(iter->cur),
iter->pat));
break;
case FILTER_RANGE:
@@ -588,18 +588,18 @@ sord_new(SordWorld* world, unsigned indices, bool graphs)
}
static void
-sord_add_quad_ref(SordModel* sord, SordNode* node)
+sord_add_quad_ref(SordModel* sord, const SordNode* node)
{
if (node) {
assert(node->refs > 0);
- ++node->refs;
+ ++((SordNode*)node)->refs;
}
}
static void
-sord_drop_quad_ref(SordModel* sord, SordNode* node)
+sord_drop_quad_ref(SordModel* sord, const SordNode* node)
{
- sord_node_free(sord_get_world(sord), node);
+ sord_node_free(sord_get_world(sord), (SordNode*)node);
}
void
@@ -731,10 +731,10 @@ sord_find(SordModel* sord, const SordQuad pat)
// It's easiest to think about this algorithm in terms of (S P O) ordering,
// assuming (A B C) == (S P O). For other orderings this is not actually
// the case, but it works the same way.
- SordNode* a = pat[ordering[0]]; // Most Significant Node (MSN)
- SordNode* b = pat[ordering[1]]; // ...
- SordNode* c = pat[ordering[2]]; // ...
- SordNode* d = pat[ordering[3]]; // Least Significant Node (LSN)
+ const SordNode* a = pat[ordering[0]]; // Most Significant Node (MSN)
+ const SordNode* b = pat[ordering[1]]; // ...
+ const SordNode* c = pat[ordering[2]]; // ...
+ const SordNode* d = pat[ordering[3]]; // Least Significant Node (LSN)
if (a && b && c && d)
mode = SINGLE; // No duplicate quads (Sord is a set)
@@ -746,7 +746,7 @@ sord_find(SordModel* sord, const SordQuad pat)
SORD_FIND_LOG("No match found\n");
return NULL;
}
- SordNode** const key = (SordNode**)g_sequence_get(cur);
+ const SordNode** const key = (const SordNode**)g_sequence_get(cur);
if (!key || ( (mode == RANGE || mode == SINGLE)
&& !sord_quad_match_inline(search_key, key) )) {
SORD_FIND_LOG("No match found\n");
@@ -957,12 +957,13 @@ sord_node_free(SordWorld* world, SordNode* node)
}
SordNode*
-sord_node_copy(SordNode* node)
+sord_node_copy(const SordNode* node)
{
- if (node) {
- ++node->refs;
+ SordNode* copy = (SordNode*)node;
+ if (copy) {
+ ++copy->refs;
}
- return node;
+ return copy;
}
static inline bool
diff --git a/src/syntax.c b/src/syntax.c
index daeec69..a0198c3 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -151,26 +151,28 @@ event_statement(void* handle,
{
ReadState* const state = (ReadState*)handle;
- SordQuad tup;
- tup[0] = sord_node_from_serd_node(state, subject, NULL, NULL);
- tup[1] = sord_node_from_serd_node(state, predicate, NULL, NULL);
- tup[2] = sord_node_from_serd_node(state, object,
- object_datatype, object_lang);
+ SordNode* s = sord_node_from_serd_node(state, subject, NULL, NULL);
+ SordNode* p = sord_node_from_serd_node(state, predicate, NULL, NULL);
+ SordNode* o = sord_node_from_serd_node(state, object,
+ object_datatype, object_lang);
+ SordNode* g = NULL;
if (state->graph_uri_node) {
assert(graph->type == SERD_NOTHING);
- tup[3] = sord_node_copy(state->graph_uri_node);
+ g = sord_node_copy(state->graph_uri_node);
} else {
- tup[3] = (graph && graph->buf)
+ g = (graph && graph->buf)
? sord_node_from_serd_node(state, graph, NULL, NULL)
: NULL;
}
+ const SordQuad tup = { s, p, o, g };
sord_add(state->sord, tup);
- sord_node_free(state->world, tup[0]);
- sord_node_free(state->world, tup[1]);
- sord_node_free(state->world, tup[2]);
- sord_node_free(state->world, tup[3]);
+
+ sord_node_free(state->world, s);
+ sord_node_free(state->world, p);
+ sord_node_free(state->world, o);
+ sord_node_free(state->world, g);
return true;
}