summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-02-04 20:16:47 +0000
committerDavid Robillard <d@drobilla.net>2011-02-04 20:16:47 +0000
commit3e1a25af1cc2aab02b6d1a3e982d04e7e995e189 (patch)
tree3726cc754ad92634e658208afb61d5032604f683
parent7528971844b737988af552fa62bbe42b354e2407 (diff)
downloadsord-3e1a25af1cc2aab02b6d1a3e982d04e7e995e189.tar.gz
sord-3e1a25af1cc2aab02b6d1a3e982d04e7e995e189.tar.bz2
sord-3e1a25af1cc2aab02b6d1a3e982d04e7e995e189.zip
Remove sord_set_option and sord_open, just pass options to sord_new instead.
git-svn-id: http://svn.drobilla.net/sord/trunk@22 3d64ff67-21c5-427c-a301-fe4f08042e5a
-rw-r--r--sord/sord.h50
-rw-r--r--src/sord.c81
-rw-r--r--src/sord_test.c18
-rw-r--r--src/sordi.c3
4 files changed, 39 insertions, 113 deletions
diff --git a/sord/sord.h b/sord/sord.h
index 8b1cb1c..8c92a5c 100644
--- a/sord/sord.h
+++ b/sord/sord.h
@@ -64,6 +64,7 @@ typedef int SordCount; ///< Count of nodes or triples
*/
typedef SordID SordQuad[4];
+/** Index into a SordQuad. */
typedef enum {
SORD_SUBJECT = 0,
SORD_PREDICATE = 1,
@@ -71,13 +72,23 @@ typedef enum {
SORD_GRAPH = 3
} SordQuadIndex;
-/** Type of a node */
+/** Type of a node. */
typedef enum {
SORD_URI = 1, ///< URI
SORD_BLANK = 2, ///< Blank node identifier
SORD_LITERAL = 3 ///< Literal (string with optional lang and/or type)
} SordNodeType;
+/** Indexing option. */
+typedef enum {
+ SORD_SPO = 1, ///< Subject, Predicate, Object
+ SORD_SOP = 1 << 1, ///< Subject, Object, Predicate
+ SORD_OPS = 1 << 2, ///< Object, Predicate, Subject
+ SORD_OSP = 1 << 3, ///< Object, Subject, Predicate
+ SORD_PSO = 1 << 4, ///< Predicate, Subject, Object
+ SORD_POS = 1 << 5 ///< Predicate, Object, Subject
+} SordIndexOption;
+
/** @name Initialisation and Cleanup
* @{
*/
@@ -85,42 +96,7 @@ typedef enum {
/** Create a new store. */
SORD_API
Sord
-sord_new(void);
-
-/** Set a store option.
- * Options are RDF properties (with the store as the subject), with the
- * restriction that each has at most one value.
- * If @a value is NULL, the option is unset (i.e. the property is removed).
- *
- * Known options (with acceptable types):
- * - http://drobilla.net/ns/sord#index-spo :: xsd:boolean
- * - http://drobilla.net/ns/sord#index-sop :: xsd:boolean
- * - http://drobilla.net/ns/sord#index-ops :: xsd:boolean
- * - http://drobilla.net/ns/sord#index-osp :: xsd:boolean
- * - http://drobilla.net/ns/sord#index-pso :: xsd:boolean
- * - http://drobilla.net/ns/sord#index-pos :: xsd:boolean
- *
- * @param sord Store
- * @param key URI of this option (predicate)
- * @param value String of option value (object)
- * @param type Type of @a value
- * @param datatype Data type of @a value (if @a type is SORD_LITERAL), or NULL
- * @param lang Language of @a value (if @a type is SORD_LITERAL), or NULL
- */
-SORD_API
-void
-sord_set_option(Sord sord, const char* key, const char* value,
- SordNodeType type, const char* datatype, const char* lang);
-
-/** Open store on disk. */
-SORD_API
-bool
-sord_open(Sord sord);
-
-/** Close store on disk. */
-SORD_API
-void
-sord_close(Sord sord);
+sord_new(unsigned indices, bool graphs);
/** Close and free @a sord, leaving disk data intact. */
SORD_API
diff --git a/src/sord.c b/src/sord.c
index 7c29e4e..f475561 100644
--- a/src/sord.c
+++ b/src/sord.c
@@ -535,16 +535,33 @@ sord_best_index(Sord sord, const SordQuad pat, SearchMode* mode, int* n_prefix)
}
Sord
-sord_new()
+sord_new(unsigned indices, bool graphs)
{
Sord sord = (Sord)malloc(sizeof(struct _Sord));
sord->names = g_hash_table_new_full(g_str_hash, g_str_equal, free, 0);
sord->literals = g_hash_table_new_full(sord_literal_hash, sord_literal_equal, 0, 0);
+ sord->n_quads = 0;
+ sord->n_nodes = 0;
sord->user_data_free = NULL;
- for (unsigned i = 0; i < NUM_ORDERS; ++i)
- sord->indices[i] = NULL;
+ for (unsigned i = 0; i < (NUM_ORDERS / 2); ++i) {
+ if (indices & (1 << i)) {
+ sord->indices[i] = g_sequence_new(free);
+ if (graphs) {
+ sord->indices[i + (NUM_ORDERS / 2)] = g_sequence_new(free);
+ } else {
+ sord->indices[i + (NUM_ORDERS / 2)] = NULL;
+ }
+ } else {
+ sord->indices[i] = NULL;
+ sord->indices[i + (NUM_ORDERS / 2)] = NULL;
+ }
+ }
+
+ if (!sord->indices[DEFAULT_ORDER]) {
+ sord->indices[DEFAULT_ORDER] = g_sequence_new(free);
+ }
return sord;
}
@@ -603,62 +620,6 @@ sord_free(Sord sord)
free(sord);
}
-void
-sord_set_option(Sord sord, const char* key, const char* value,
- SordNodeType type, const char* datatype, const char* lang)
-{
- const char* const prefix = "http://drobilla.net/ns/sord#";
- const size_t prefix_len = strlen(prefix);
- if (strncmp(key, prefix, prefix_len)) {
- fprintf(stderr, "Unknown option %s\n", key);
- return;
- }
-
- const char* option = key + prefix_len;
- const bool value_is_true = !strcmp(value, "true") || !strcmp(value, "1") || !strcmp(value, "yes");
- if (!strcmp(option, "index-all")) {
- for (int i = 0; i < NUM_ORDERS; ++i) {
- sord->indices[i] = g_sequence_new(free);
- }
- } else if (!strncmp(option, "index-", 6) && value_is_true) {
- for (int i = 0; i < NUM_ORDERS; ++i) {
- if (!strcmp(option + 6, order_names[i])) {
- sord->indices[i] = g_sequence_new(free);
- return;
- }
- }
- } else {
- fprintf(stderr, "Unknown option %s\n", key);
- }
-}
-
-bool
-sord_open(Sord sord)
-{
- sord->n_quads = sord->n_nodes = 0;
-
- bool no_indices = true;
- for (unsigned i = 0; i < NUM_ORDERS; ++i) {
- if (sord->indices[i]) {
- no_indices = false;
- break;
- }
- }
-
- if (no_indices) {
- // FIXME: make sord_new take a parameter so this is explicit
- sord->indices[SPO] = g_sequence_new(free);
- sord->indices[OPS] = g_sequence_new(free);
- sord->indices[GSPO] = g_sequence_new(free);
- sord->indices[GOPS] = g_sequence_new(free);
- }
-
- if (!sord->indices[DEFAULT_ORDER])
- sord->indices[DEFAULT_ORDER] = g_sequence_new(NULL);
-
- return true;
-}
-
int
sord_num_quads(Sord sord)
{
@@ -698,7 +659,7 @@ sord_graphs_begin(Sord read)
static inline GSequenceIter*
index_search(Sord sord, GSequence* db, const SordQuad search_key)
{
- return g_sequence_search(
+ return g_sequence_search(
db, (void*)search_key, sord_quad_compare, sord);
}
diff --git a/src/sord_test.c b/src/sord_test.c
index 82e7612..af2da40 100644
--- a/src/sord_test.c
+++ b/src/sord_test.c
@@ -267,10 +267,8 @@ main(int argc, char** argv)
sord_free(NULL); // Shouldn't crash
- // Create with default options
- Sord sord = sord_new();
- sord_set_option(sord, "http://unknown", "something", SORD_LITERAL, NULL, NULL);
- sord_open(sord);
+ // Create with minimal indexing
+ Sord sord = sord_new(SORD_SPO, false);
generate(sord, n_quads, n_objects_per);
if (test_read(sord, n_quads, n_objects_per)) {
@@ -314,28 +312,20 @@ main(int argc, char** argv)
sord_free(sord);
- // Test each pattern type with each index
static const char* const index_names[6] = {
"spo", "sop", "ops", "osp", "pso", "pos"
};
- char* option = strdup("http://drobilla.net/ns/sord#index-xxx");
- const size_t option_len = strlen(option);
for (int i = 0; i < 6; ++i) {
- strncpy(option + option_len - 3, index_names[i], 3);
- sord = sord_new();
- sord_set_option(sord, option, "true", SORD_LITERAL, NULL, NULL);
+ sord = sord_new((1 << i), false);
printf("Testing Index `%s'\n", index_names[i]);
- sord_open(sord);
generate(sord, n_quads, n_objects_per);
if (test_read(sord, n_quads, n_objects_per))
goto fail;
sord_free(sord);
}
- free(option);
- sord = sord_new();
- sord_open(sord);
+ sord = sord_new(SORD_SPO, false);
if (test_write(sord, n_quads, n_objects_per))
goto fail;
diff --git a/src/sordi.c b/src/sordi.c
index 59dfb8a..883f300 100644
--- a/src/sordi.c
+++ b/src/sordi.c
@@ -118,8 +118,7 @@ main(int argc, char** argv)
const uint8_t* input = (const uint8_t*)argv[a++];
- Sord sord = sord_new();
- sord_open(sord);
+ Sord sord = sord_new(SORD_SPO|SORD_OPS, false);
bool success = sord_read_file(sord, input, NULL, NULL);