diff options
author | David Robillard <d@drobilla.net> | 2011-02-04 20:16:47 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-02-04 20:16:47 +0000 |
commit | 3e1a25af1cc2aab02b6d1a3e982d04e7e995e189 (patch) | |
tree | 3726cc754ad92634e658208afb61d5032604f683 /src | |
parent | 7528971844b737988af552fa62bbe42b354e2407 (diff) | |
download | sord-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
Diffstat (limited to 'src')
-rw-r--r-- | src/sord.c | 81 | ||||
-rw-r--r-- | src/sord_test.c | 18 | ||||
-rw-r--r-- | src/sordi.c | 3 |
3 files changed, 26 insertions, 76 deletions
@@ -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); |