summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-12-16 11:54:40 +0100
committerDavid Robillard <d@drobilla.net>2017-12-16 14:00:28 +0100
commit46b8e6ed53370d76c294c5e40b040ea78d6c9847 (patch)
tree87b3f6ba6fd93c3f20b9e169443d473b0450f635
parentef7cd1f17eb468b3ac34197a477e6b22516185d4 (diff)
downloadsord-46b8e6ed53370d76c294c5e40b040ea78d6c9847.tar.gz
sord-46b8e6ed53370d76c294c5e40b040ea78d6c9847.tar.bz2
sord-46b8e6ed53370d76c294c5e40b040ea78d6c9847.zip
Update BTree
-rw-r--r--src/sord_test.c15
-rw-r--r--src/sord_validate.c22
-rw-r--r--src/syntax.c2
-rw-r--r--src/zix/btree.c16
4 files changed, 32 insertions, 23 deletions
diff --git a/src/sord_test.c b/src/sord_test.c
index 189edb0..ce54c68 100644
--- a/src/sord_test.c
+++ b/src/sord_test.c
@@ -36,8 +36,9 @@ typedef struct {
static SordNode*
uri(SordWorld* world, int num)
{
- if (num == 0)
+ if (num == 0) {
return 0;
+ }
char str[] = "eg:000";
char* uri_num = str + 3; // First `0'
@@ -189,8 +190,9 @@ test_read(SordWorld* world, SordModel* sord, SordNode* g,
return test_fail("Fail: Iterator has incorrect sord pointer\n");
}
- for (; !sord_iter_end(iter); sord_iter_next(iter))
+ for (; !sord_iter_end(iter); sord_iter_next(iter)) {
sord_iter_get(iter, id);
+ }
// Attempt to increment past end
if (!sord_iter_next(iter)) {
@@ -312,8 +314,9 @@ test_read(SordWorld* world, SordModel* sord, SordNode* g,
iter = sord_search(sord, NULL, NULL, NULL, NULL);
for (; !sord_iter_end(iter); sord_iter_next(iter)) {
sord_iter_get(iter, id);
- if (id[0] == last_subject)
+ if (id[0] == last_subject) {
continue;
+ }
SordQuad subpat = { id[0], 0, 0 };
SordIter* subiter = sord_find(sord, subpat);
@@ -624,8 +627,9 @@ main(int argc, char** argv)
sord = sord_new(world, (1 << i), false);
printf("Testing Index `%s'\n", index_names[i]);
generate(world, sord, n_quads, 0);
- if (test_read(world, sord, 0, n_quads))
+ if (test_read(world, sord, 0, n_quads)) {
return finished(world, sord, EXIT_FAILURE);
+ }
sord_free(sord);
}
@@ -638,8 +642,9 @@ main(int argc, char** argv)
printf("Testing Index `%s'\n", graph_index_names[i]);
SordNode* graph = uri(world, 42);
generate(world, sord, n_quads, graph);
- if (test_read(world, sord, graph, n_quads))
+ if (test_read(world, sord, graph, n_quads)) {
return finished(world, sord, EXIT_FAILURE);
+ }
sord_free(sord);
}
diff --git a/src/sord_validate.c b/src/sord_validate.c
index e30bbc0..a5c8d45 100644
--- a/src/sord_validate.c
+++ b/src/sord_validate.c
@@ -14,8 +14,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define _BSD_SOURCE 1 // for realpath
-#define _DEFAULT_SOURCE 1 // for realpath
+#define _BSD_SOURCE 1 // for realpath
+#define _DEFAULT_SOURCE 1 // for realpath
#include <assert.h>
#include <stdlib.h>
@@ -33,7 +33,7 @@
# include <pcre.h>
#endif
-#define USTR(s) ((const uint8_t*)s)
+#define USTR(s) ((const uint8_t*)(s))
#define NS_foaf (const uint8_t*)"http://xmlns.com/foaf/0.1/"
#define NS_owl (const uint8_t*)"http://www.w3.org/2002/07/owl#"
@@ -155,8 +155,9 @@ is_descendant_of(SordModel* model,
{
if (!child) {
return false;
- } else if (sord_node_equals(child, parent) ||
- sord_ask(model, child, uris->owl_equivalentClass, parent, NULL)) {
+ } else if (
+ sord_node_equals(child, parent) ||
+ sord_ask(model, child, uris->owl_equivalentClass, parent, NULL)) {
return true;
}
@@ -211,11 +212,12 @@ bound_cmp(SordModel* model,
const SordNode* type,
const SordNode* bound)
{
- const char* str = (const char*)sord_node_get_string(literal);
- const char* bound_str = (const char*)sord_node_get_string(bound);
- const bool is_numeric =
- is_descendant_of(model, uris, type, uris->xsd_decimal, uris->owl_onDatatype) ||
- is_descendant_of(model, uris, type, uris->xsd_double, uris->owl_onDatatype);
+ const char* str = (const char*)sord_node_get_string(literal);
+ const char* bound_str = (const char*)sord_node_get_string(bound);
+ const SordNode* pred = uris->owl_onDatatype;
+ const bool is_numeric =
+ is_descendant_of(model, uris, type, uris->xsd_decimal, pred) ||
+ is_descendant_of(model, uris, type, uris->xsd_double, pred);
if (is_numeric) {
const double fbound = serd_strtod(bound_str, NULL);
diff --git a/src/syntax.c b/src/syntax.c
index f35e6f9..773fb95 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -103,7 +103,7 @@ sord_new_reader(SordModel* model,
SordInserter* inserter = sord_inserter_new(model, env);
SerdReader* reader = serd_reader_new(
- syntax, inserter, (void (*)(void*))sord_inserter_free,
+ syntax, inserter, (void (*)(void* ptr))sord_inserter_free,
(SerdBaseSink)sord_inserter_set_base_uri,
(SerdPrefixSink)sord_inserter_set_prefix,
(SerdStatementSink)sord_inserter_write_statement,
diff --git a/src/zix/btree.c b/src/zix/btree.c
index 4557ad4..78a5a0d 100644
--- a/src/zix/btree.c
+++ b/src/zix/btree.c
@@ -24,7 +24,10 @@
// #define ZIX_BTREE_DEBUG 1
-#define ZIX_BTREE_PAGE_SIZE 4096
+#ifndef ZIX_BTREE_PAGE_SIZE
+# define ZIX_BTREE_PAGE_SIZE 4096
+#endif
+
#define ZIX_BTREE_NODE_SPACE (ZIX_BTREE_PAGE_SIZE - 2 * sizeof(uint16_t))
#define ZIX_BTREE_LEAF_VALS ((ZIX_BTREE_NODE_SPACE / sizeof(void*)) - 1)
#define ZIX_BTREE_INODE_VALS (ZIX_BTREE_LEAF_VALS / 2)
@@ -319,12 +322,9 @@ zix_btree_insert(ZixBTree* const t, void* const e)
ZIX_PRIVATE ZixBTreeIter*
zix_btree_iter_new(const ZixBTree* const t)
{
- const size_t s = t->height * sizeof(ZixBTreeIterFrame);
- ZixBTreeIter* const i = (ZixBTreeIter*)malloc(sizeof(ZixBTreeIter) + s);
- if (i) {
- i->level = 0;
- }
- return i;
+ const size_t s = t->height * sizeof(ZixBTreeIterFrame);
+
+ return (ZixBTreeIter*)calloc(1, sizeof(ZixBTreeIter) + s);
}
ZIX_PRIVATE void
@@ -641,6 +641,7 @@ zix_btree_lower_bound(const ZixBTree* const t,
}
const ZixBTreeIterFrame* const frame = &(*ti)->stack[(*ti)->level];
+ assert(frame->node);
if (frame->index == frame->node->n_vals) {
if (found) {
// Found on a previous level but went too far
@@ -658,6 +659,7 @@ ZIX_API void*
zix_btree_get(const ZixBTreeIter* const ti)
{
const ZixBTreeIterFrame* const frame = &ti->stack[ti->level];
+ assert(frame->node);
assert(frame->index < frame->node->n_vals);
return frame->node->vals[frame->index];
}