diff options
author | David Robillard <d@drobilla.net> | 2011-06-09 06:11:04 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-06-09 06:11:04 +0000 |
commit | 0c28ca816f7d28d8a522d41f2d6d31d0112324da (patch) | |
tree | 143963fd5f8f89424936a3479e9b7cdc8377e24a | |
parent | edcd7137e091df562f70daa1092f09d4e92f15a3 (diff) | |
download | sord-0c28ca816f7d28d8a522d41f2d6d31d0112324da.tar.gz sord-0c28ca816f7d28d8a522d41f2d6d31d0112324da.tar.bz2 sord-0c28ca816f7d28d8a522d41f2d6d31d0112324da.zip |
Add sord_contains (ticket #711).
git-svn-id: http://svn.drobilla.net/sord/trunk@148 3d64ff67-21c5-427c-a301-fe4f08042e5a
-rw-r--r-- | sord/sord.h | 7 | ||||
-rw-r--r-- | src/sord.c | 9 | ||||
-rw-r--r-- | src/sord_test.c | 14 |
3 files changed, 30 insertions, 0 deletions
diff --git a/sord/sord.h b/sord/sord.h index 9e6110a..f76bc0e 100644 --- a/sord/sord.h +++ b/sord/sord.h @@ -356,6 +356,13 @@ SordIter* sord_find(SordModel* model, const SordQuad pat); /** + Check if @a model contains a triple pattern. +*/ +SORD_API +bool +sord_contains(SordModel* model, const SordQuad pat); + +/** Add a quad to a model. */ SORD_API @@ -793,6 +793,15 @@ sord_find(SordModel* sord, const SordQuad pat) return sord_iter_new(sord, cur, pat, index_order, mode, prefix_len); } +bool +sord_contains(SordModel* sord, const SordQuad pat) +{ + SordIter* iter = sord_find(sord, pat); + bool ret = (iter != NULL); + sord_iter_free(iter); + return ret; +} + static SordNode* sord_lookup_name(SordWorld* world, const uint8_t* str) { diff --git a/src/sord_test.c b/src/sord_test.c index 71d5453..109bbe9 100644 --- a/src/sord_test.c +++ b/src/sord_test.c @@ -165,6 +165,20 @@ test_read(SordWorld* world, SordModel* sord, { { uri(world, 1), uri(world, 0), uri(world, 4) }, 1 }, { { uri(world, 0), uri(world, 2), uri(world, 0) }, 2 } }; + SordQuad match = { uri(world, 1), uri(world, 2), uri(world, 4) }; + if (!sord_contains(sord, match)) { + fprintf(stderr, "Fail: No match for " TUP_FMT "\n", + TUP_FMT_ARGS(match)); + return test_fail(); + } + + SordQuad nomatch = { uri(world, 1), uri(world, 2), uri(world, 9) }; + if (sord_contains(sord, nomatch)) { + fprintf(stderr, "Fail: False match for " TUP_FMT "\n", + TUP_FMT_ARGS(nomatch)); + return test_fail(); + } + for (unsigned i = 0; i < NUM_PATTERNS; ++i) { QueryTest test = patterns[i]; SordQuad pat = { test.query[0], test.query[1], test.query[2], 0 }; |