|
@@ -11,62 +11,27 @@ typedef bool (*LSUP_key_eq_fn_t)(
|
|
|
|
|
|
|
|
|
|
typedef struct idx_entry_t {
|
|
typedef struct idx_entry_t {
|
|
- LSUP_Key key; // Serialized term key.
|
|
|
|
- LSUP_Buffer * sterm; // Serialized term.
|
|
|
|
|
|
+ LSUP_Key key; ///> Serialized term key.
|
|
|
|
+ LSUP_Buffer * sterm; ///> Serialized term.
|
|
} IndexEntry;
|
|
} IndexEntry;
|
|
|
|
|
|
typedef struct ht_store_t {
|
|
typedef struct ht_store_t {
|
|
- struct hashmap * keys; // Triple keys (set).
|
|
|
|
- struct hashmap * idx; // Dictionary of keys to serialized terms.
|
|
|
|
|
|
+ struct hashmap * keys; ///> Triple keys (set).
|
|
|
|
+ struct hashmap * idx; ///> Map of keys to serialized terms.
|
|
} HTStore;
|
|
} HTStore;
|
|
|
|
|
|
typedef struct ht_iterator_t {
|
|
typedef struct ht_iterator_t {
|
|
- HTStore * store; // Store being iterated.
|
|
|
|
- size_t cur; // Internal has table cursor.
|
|
|
|
- size_t ct; // Number of records found at any point of
|
|
|
|
- // a lookup iteration, or number of records
|
|
|
|
- // added at any point of an add loop.
|
|
|
|
- LSUP_Key luk[3]; // 0÷3 lookup keys.
|
|
|
|
- LSUP_key_eq_fn_t eq_fn; // Equality function to test triples.
|
|
|
|
- int rc; // Return code for *next* result.
|
|
|
|
- // When the end of results is reached, this
|
|
|
|
- // is set to LSUP_END.
|
|
|
|
- LSUP_TripleKey * entry; // Retrieved SPO key.
|
|
|
|
|
|
+ HTStore * store; ///> Store being iterated.
|
|
|
|
+ size_t cur; ///> Internal hash table cursor.
|
|
|
|
+ LSUP_Key luk[3]; ///> 0÷3 lookup keys.
|
|
|
|
+ LSUP_key_eq_fn_t eq_fn; ///> Equality function to test triples.
|
|
|
|
+ int rc; ///> Return code for *next* result.
|
|
|
|
+ ///> When the end of results is reached,
|
|
|
|
+ ///> this is set to LSUP_END.
|
|
|
|
+ LSUP_TripleKey * entry; ///> Retrieved SPO key.
|
|
} HTIterator;
|
|
} HTIterator;
|
|
|
|
|
|
|
|
|
|
-/** @brief Copy triple data.
|
|
|
|
- */
|
|
|
|
-static bool htstore_copy_key_iter_fn (const void *item, void *udata)
|
|
|
|
-{
|
|
|
|
- LSUP_TripleKey *spok = (LSUP_TripleKey *)item;
|
|
|
|
- HTStore *dest = udata;
|
|
|
|
-
|
|
|
|
- hashmap_set (dest->keys, spok);
|
|
|
|
- if (UNLIKELY (hashmap_oom (dest->keys))) return false;
|
|
|
|
-
|
|
|
|
- return true;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/** @brief Copy index data.
|
|
|
|
- */
|
|
|
|
-static bool htstore_copy_idx_iter_fn (const void *item, void *udata)
|
|
|
|
-{
|
|
|
|
- IndexEntry *entry = (IndexEntry *)item;
|
|
|
|
- HTStore *dest = udata;
|
|
|
|
-
|
|
|
|
- hashmap_set (dest->idx, entry);
|
|
|
|
- if (UNLIKELY (hashmap_oom (dest->idx))) return false;
|
|
|
|
-
|
|
|
|
- return true;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/** @brief Copy triples only if not
|
|
|
|
- * */
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Dummy callback for queries with all parameters unbound. Returns true.
|
|
* Dummy callback for queries with all parameters unbound. Returns true.
|
|
*/
|
|
*/
|
|
@@ -86,14 +51,14 @@ static bool lookup_sk_eq_fn (
|
|
*/
|
|
*/
|
|
static bool lookup_pk_eq_fn (
|
|
static bool lookup_pk_eq_fn (
|
|
const LSUP_Key spok[], const LSUP_Key luk[])
|
|
const LSUP_Key spok[], const LSUP_Key luk[])
|
|
-{ return spok[1] == luk[0]; }
|
|
|
|
|
|
+{ return spok[1] == luk[1]; }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Keyset lookup for O key.
|
|
* Keyset lookup for O key.
|
|
*/
|
|
*/
|
|
static bool lookup_ok_eq_fn (
|
|
static bool lookup_ok_eq_fn (
|
|
const LSUP_Key spok[], const LSUP_Key luk[])
|
|
const LSUP_Key spok[], const LSUP_Key luk[])
|
|
-{ return spok[2] == luk[0]; }
|
|
|
|
|
|
+{ return spok[2] == luk[2]; }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Keyset lookup for S and P keys.
|
|
* Keyset lookup for S and P keys.
|
|
@@ -107,14 +72,14 @@ static bool lookup_spk_eq_fn (
|
|
*/
|
|
*/
|
|
static bool lookup_sok_eq_fn (
|
|
static bool lookup_sok_eq_fn (
|
|
const LSUP_Key spok[], const LSUP_Key luk[])
|
|
const LSUP_Key spok[], const LSUP_Key luk[])
|
|
-{ return spok[0] == luk[0] && spok[2] == luk[1]; }
|
|
|
|
|
|
+{ return spok[0] == luk[0] && spok[2] == luk[2]; }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Keyset lookup for P and O keys.
|
|
* Keyset lookup for P and O keys.
|
|
*/
|
|
*/
|
|
static bool lookup_pok_eq_fn (
|
|
static bool lookup_pok_eq_fn (
|
|
const LSUP_Key spok[], const LSUP_Key luk[])
|
|
const LSUP_Key spok[], const LSUP_Key luk[])
|
|
-{ return spok[1] == luk[0] && spok[2] == luk[1]; }
|
|
|
|
|
|
+{ return spok[1] == luk[1] && spok[2] == luk[2]; }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Keyset lookup for S, P and O keys.
|
|
* Keyset lookup for S, P and O keys.
|
|
@@ -124,6 +89,17 @@ static bool lookup_spok_eq_fn (
|
|
{ return spok[0] == luk[0] && spok[1] == luk[1] && spok[2] == luk[2]; }
|
|
{ return spok[0] == luk[0] && spok[1] == luk[1] && spok[2] == luk[2]; }
|
|
|
|
|
|
|
|
|
|
|
|
+/* * * CALLBACKS * * */
|
|
|
|
+
|
|
|
|
+uint64_t trp_key_hash_fn (
|
|
|
|
+ const void *item, uint64_t seed0, uint64_t seed1)
|
|
|
|
+{ return (uint64_t) (LSUP_HASH (item, TRP_KLEN, seed0)); }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+int trp_key_cmp_fn (const void *a, const void *b, void *udata)
|
|
|
|
+{ return memcmp (a, b, TRP_KLEN); }
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Hash callback function for index hashmap.
|
|
* Hash callback function for index hashmap.
|
|
*/
|
|
*/
|
|
@@ -136,11 +112,7 @@ static uint64_t htstore_idx_hash_fn (
|
|
* Compare callback function for index hashmap.
|
|
* Compare callback function for index hashmap.
|
|
*/
|
|
*/
|
|
static int htstore_idx_cmp_fn (const void *a, const void *b, void *udata)
|
|
static int htstore_idx_cmp_fn (const void *a, const void *b, void *udata)
|
|
-{
|
|
|
|
- return LSUP_buffer_cmp (
|
|
|
|
- ((const IndexEntry *) a)->sterm,
|
|
|
|
- ((const IndexEntry *) b)->sterm);
|
|
|
|
-}
|
|
|
|
|
|
+{ return ((const IndexEntry *) a)->key - ((const IndexEntry *) b)->key; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -156,11 +128,17 @@ inline static LSUP_rc
|
|
tkey_to_strp (
|
|
tkey_to_strp (
|
|
const HTStore *store, const LSUP_Key *spok, LSUP_BufferTriple *sspo);
|
|
const HTStore *store, const LSUP_Key *spok, LSUP_BufferTriple *sspo);
|
|
|
|
|
|
|
|
+
|
|
static LSUP_rc
|
|
static LSUP_rc
|
|
-htstore_add_key_iter (HTIterator *it, const LSUP_TripleKey spok);
|
|
|
|
|
|
+htstore_add_key_iter (HTIterator *it, const LSUP_Key *spok);
|
|
|
|
|
|
|
|
+
|
|
|
|
+/** @brief Advance iterator by next key.
|
|
|
|
+ *
|
|
|
|
+ * Result is stored in it->entry.
|
|
|
|
+ */
|
|
static LSUP_rc
|
|
static LSUP_rc
|
|
-htiter_next_key (HTIterator *it, LSUP_TripleKey *spok);
|
|
|
|
|
|
+htiter_next_key (HTIterator *it);
|
|
|
|
|
|
|
|
|
|
/* * * API * * */
|
|
/* * * API * * */
|
|
@@ -178,7 +156,7 @@ LSUP_htstore_new (const size_t size)
|
|
|
|
|
|
ht->keys = hashmap_new (
|
|
ht->keys = hashmap_new (
|
|
sizeof (LSUP_TripleKey), size, LSUP_HASH_SEED, 0,
|
|
sizeof (LSUP_TripleKey), size, LSUP_HASH_SEED, 0,
|
|
- key_hash_fn, key_cmp_fn, NULL,
|
|
|
|
|
|
+ trp_key_hash_fn, trp_key_cmp_fn, NULL,
|
|
NULL);
|
|
NULL);
|
|
|
|
|
|
return ht;
|
|
return ht;
|
|
@@ -203,10 +181,18 @@ LSUP_htstore_copy (const HTStore *src)
|
|
LSUP_rc
|
|
LSUP_rc
|
|
LSUP_htstore_copy_contents (HTStore *dest, const HTStore *src)
|
|
LSUP_htstore_copy_contents (HTStore *dest, const HTStore *src)
|
|
{
|
|
{
|
|
- if (hashmap_scan (src->keys, htstore_copy_key_iter_fn, dest) == false)
|
|
|
|
- return LSUP_MEM_ERR;
|
|
|
|
- if (hashmap_scan (src->idx, htstore_copy_idx_iter_fn, dest) == false)
|
|
|
|
- return LSUP_MEM_ERR;
|
|
|
|
|
|
+ size_t i = 0;
|
|
|
|
+ LSUP_TripleKey *spok;
|
|
|
|
+ IndexEntry *entry;
|
|
|
|
+ while (hashmap_iter (src->keys, &i, (void **) &spok)) {
|
|
|
|
+ hashmap_set (dest->keys, spok);
|
|
|
|
+ if (UNLIKELY (hashmap_oom (dest->keys))) return LSUP_MEM_ERR;
|
|
|
|
+ }
|
|
|
|
+ i = 0;
|
|
|
|
+ while (hashmap_iter (src->idx, &i, (void **) &entry)) {
|
|
|
|
+ hashmap_set (dest->idx, entry);
|
|
|
|
+ if (UNLIKELY (hashmap_oom (dest->idx))) return LSUP_MEM_ERR;
|
|
|
|
+ }
|
|
|
|
|
|
return LSUP_OK;
|
|
return LSUP_OK;
|
|
}
|
|
}
|
|
@@ -236,7 +222,7 @@ LSUP_htstore_bool_op(
|
|
return dest;
|
|
return dest;
|
|
}
|
|
}
|
|
|
|
|
|
- LSUP_TripleKey src_tkey, dest_tkey;
|
|
|
|
|
|
+ LSUP_TripleKey *src_tkey;
|
|
|
|
|
|
LSUP_HTIterator *it = LSUP_htstore_add_init(dest);
|
|
LSUP_HTIterator *it = LSUP_htstore_add_init(dest);
|
|
|
|
|
|
@@ -245,7 +231,7 @@ LSUP_htstore_bool_op(
|
|
// Add triples from s2 if not found in s1.
|
|
// Add triples from s2 if not found in s1.
|
|
while (hashmap_iter (s2->keys, &i, (void **) &src_tkey)) {
|
|
while (hashmap_iter (s2->keys, &i, (void **) &src_tkey)) {
|
|
if (!hashmap_get (s1->keys, src_tkey))
|
|
if (!hashmap_get (s1->keys, src_tkey))
|
|
- htstore_add_key_iter (it, src_tkey);
|
|
|
|
|
|
+ htstore_add_key_iter (it, *src_tkey);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -257,7 +243,7 @@ LSUP_htstore_bool_op(
|
|
(op == LSUP_BOOL_INTERSECTION)
|
|
(op == LSUP_BOOL_INTERSECTION)
|
|
^ (hashmap_get (s2->keys, src_tkey) == NULL)
|
|
^ (hashmap_get (s2->keys, src_tkey) == NULL)
|
|
)
|
|
)
|
|
- htstore_add_key_iter (it, src_tkey);
|
|
|
|
|
|
+ htstore_add_key_iter (it, *src_tkey);
|
|
}
|
|
}
|
|
LSUP_htstore_add_done (it);
|
|
LSUP_htstore_add_done (it);
|
|
|
|
|
|
@@ -309,7 +295,6 @@ LSUP_htstore_add_init (HTStore *store)
|
|
MALLOC_GUARD (it, NULL);
|
|
MALLOC_GUARD (it, NULL);
|
|
|
|
|
|
it->store = store;
|
|
it->store = store;
|
|
- it->ct = 0;
|
|
|
|
|
|
|
|
return it;
|
|
return it;
|
|
}
|
|
}
|
|
@@ -349,60 +334,52 @@ LSUP_htstore_remove(
|
|
{
|
|
{
|
|
LSUP_rc rc = LSUP_NOACTION;
|
|
LSUP_rc rc = LSUP_NOACTION;
|
|
|
|
|
|
- LSUP_HTIterator *it = LSUP_htstore_lookup (store, ss, sp, so);
|
|
|
|
|
|
+ LSUP_HTIterator *it = LSUP_htstore_lookup (store, ss, sp, so, ct);
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
|
|
|
|
- LSUP_TripleKey *tmp;
|
|
|
|
- while (htiter_next_key (it, tmp)) {
|
|
|
|
|
|
+ while (htiter_next_key (it)) {
|
|
if (it->rc == LSUP_OK) {
|
|
if (it->rc == LSUP_OK) {
|
|
- tmp = hashmap_delete (store->keys, tmp);
|
|
|
|
- free (tmp);
|
|
|
|
|
|
+ LSUP_TripleKey *del = hashmap_delete (store->keys, it->entry);
|
|
|
|
+ free (del);
|
|
|
|
+ rc = LSUP_OK;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (ct) *ct = it->ct;
|
|
|
|
|
|
|
|
LSUP_htiter_free (it);
|
|
LSUP_htiter_free (it);
|
|
|
|
|
|
- return LSUP_OK;
|
|
|
|
|
|
+ return rc;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
HTIterator *
|
|
HTIterator *
|
|
LSUP_htstore_lookup (HTStore *store, const LSUP_Buffer *ss,
|
|
LSUP_htstore_lookup (HTStore *store, const LSUP_Buffer *ss,
|
|
- const LSUP_Buffer *sp, const LSUP_Buffer *so)
|
|
|
|
|
|
+ const LSUP_Buffer *sp, const LSUP_Buffer *so, size_t *ct)
|
|
{
|
|
{
|
|
HTIterator *it;
|
|
HTIterator *it;
|
|
- MALLOC_GUARD (it, NULL);
|
|
|
|
|
|
+ CALLOC_GUARD (it, NULL);
|
|
|
|
|
|
it->store = store;
|
|
it->store = store;
|
|
- it->cur = 0;
|
|
|
|
- it->ct = 0;
|
|
|
|
it->rc = LSUP_END;
|
|
it->rc = LSUP_END;
|
|
|
|
|
|
if (hashmap_count (store->keys) == 0) return it;
|
|
if (hashmap_count (store->keys) == 0) return it;
|
|
|
|
|
|
- LSUP_TripleKey spok = {
|
|
|
|
- LSUP_buffer_hash (ss),
|
|
|
|
- LSUP_buffer_hash (sp),
|
|
|
|
- LSUP_buffer_hash (so),
|
|
|
|
- };
|
|
|
|
|
|
+ if (ct) *ct = 0;
|
|
|
|
+
|
|
|
|
+ it->luk[0] = LSUP_buffer_hash (ss);
|
|
|
|
+ it->luk[1] = LSUP_buffer_hash (sp);
|
|
|
|
+ it->luk[2] = LSUP_buffer_hash (so);
|
|
|
|
|
|
// s p o
|
|
// s p o
|
|
- if (spok[0] != NULL_KEY && spok[1] != NULL_KEY && spok[2] != NULL_KEY) {
|
|
|
|
- memcpy (it->luk, spok, sizeof (LSUP_TripleKey));
|
|
|
|
|
|
+ if (ss && sp && so) {
|
|
it->eq_fn = lookup_spok_eq_fn;
|
|
it->eq_fn = lookup_spok_eq_fn;
|
|
|
|
|
|
- } else if (spok[0] != NULL_KEY) {
|
|
|
|
- it->luk[0] = spok[0];
|
|
|
|
-
|
|
|
|
|
|
+ } else if (ss) {
|
|
// s p ?
|
|
// s p ?
|
|
- if (spok[1] != NULL_KEY) {
|
|
|
|
- it->luk[1] = spok[1];
|
|
|
|
|
|
+ if (sp) {
|
|
it->eq_fn = lookup_spk_eq_fn;
|
|
it->eq_fn = lookup_spk_eq_fn;
|
|
|
|
|
|
// s ? o
|
|
// s ? o
|
|
- } else if (spok[2] != NULL_KEY) {
|
|
|
|
- it->luk[1] = spok[2];
|
|
|
|
|
|
+ } else if (so) {
|
|
it->eq_fn = lookup_sok_eq_fn;
|
|
it->eq_fn = lookup_sok_eq_fn;
|
|
|
|
|
|
// s ? ?
|
|
// s ? ?
|
|
@@ -410,28 +387,33 @@ LSUP_htstore_lookup (HTStore *store, const LSUP_Buffer *ss,
|
|
it->eq_fn = lookup_sk_eq_fn;
|
|
it->eq_fn = lookup_sk_eq_fn;
|
|
}
|
|
}
|
|
|
|
|
|
- } else if (spok[1] != NULL_KEY) {
|
|
|
|
- it->luk[0] = spok[1];
|
|
|
|
-
|
|
|
|
|
|
+ } else if (sp) {
|
|
// ? p o
|
|
// ? p o
|
|
- if (spok[2] != NULL_KEY) {
|
|
|
|
- it->luk[1] = spok[2];
|
|
|
|
|
|
+ if (so) {
|
|
it->eq_fn = lookup_pok_eq_fn;
|
|
it->eq_fn = lookup_pok_eq_fn;
|
|
|
|
|
|
// ? p ?
|
|
// ? p ?
|
|
} else it->eq_fn = lookup_pk_eq_fn;
|
|
} else it->eq_fn = lookup_pk_eq_fn;
|
|
|
|
|
|
// ? ? o
|
|
// ? ? o
|
|
- } else if (spok[2] != NULL_KEY) {
|
|
|
|
- it->luk[0] = spok[2];
|
|
|
|
|
|
+ } else if (so) {
|
|
it->eq_fn = lookup_ok_eq_fn;
|
|
it->eq_fn = lookup_ok_eq_fn;
|
|
|
|
|
|
// ? ? ?
|
|
// ? ? ?
|
|
} else it->eq_fn = lookup_none_eq_fn;
|
|
} else it->eq_fn = lookup_none_eq_fn;
|
|
|
|
|
|
- // Position cursor at first record in hash table.
|
|
|
|
- if (hashmap_iter (it->store->keys, &it->cur, (void **) it->entry))
|
|
|
|
- it->rc = LSUP_OK; // Else it's LSUP_END already.
|
|
|
|
|
|
+ log_trace ("LUK: {%lx, %lx, %lx}", it->luk[0], it->luk[1], it->luk[2]);
|
|
|
|
+
|
|
|
|
+ if (ct) {
|
|
|
|
+ // Loop over results to determine count.
|
|
|
|
+ while (htiter_next_key (it) == LSUP_OK) {
|
|
|
|
+ (*ct)++;
|
|
|
|
+ log_trace ("ct: %lu", *ct);
|
|
|
|
+ }
|
|
|
|
+ // Reposition cursor to the hashtable beginning.
|
|
|
|
+ it->cur = 0;
|
|
|
|
+ it->rc = LSUP_OK;
|
|
|
|
+ }
|
|
|
|
|
|
return it;
|
|
return it;
|
|
}
|
|
}
|
|
@@ -441,62 +423,28 @@ void
|
|
LSUP_htiter_free (LSUP_HTIterator *it)
|
|
LSUP_htiter_free (LSUP_HTIterator *it)
|
|
{ free (it); }
|
|
{ free (it); }
|
|
|
|
|
|
-
|
|
|
|
-size_t
|
|
|
|
-LSUP_htiter_count (const LSUP_HTIterator *it)
|
|
|
|
-{ return it->cur; }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
LSUP_rc
|
|
LSUP_rc
|
|
-htiter_next_key (HTIterator *it, LSUP_TripleKey *spok)
|
|
|
|
|
|
+htiter_next_key (HTIterator *it)
|
|
{
|
|
{
|
|
if (UNLIKELY (!it)) return LSUP_VALUE_ERR;
|
|
if (UNLIKELY (!it)) return LSUP_VALUE_ERR;
|
|
|
|
|
|
- // If the previous iteration hit the end, return.
|
|
|
|
- if (it->rc != LSUP_OK) return it->rc;
|
|
|
|
-
|
|
|
|
// This value is for internal looping only. It shall never be returned.
|
|
// This value is for internal looping only. It shall never be returned.
|
|
it->rc = LSUP_NORESULT;
|
|
it->rc = LSUP_NORESULT;
|
|
- /*
|
|
|
|
-#ifdef DEBUG
|
|
|
|
- log_trace ("Lookup key: ");
|
|
|
|
- IndexEntry *tmp = NULL;
|
|
|
|
- HASH_FIND (hh, it->store->idx, it->luk + 0, KLEN, tmp);
|
|
|
|
- if (tmp) LSUP_buffer_print(tmp->sterm); else printf("NULL\n");
|
|
|
|
- HASH_FIND (hh, it->store->idx, it->luk + 1, KLEN, tmp);
|
|
|
|
- if (tmp) LSUP_buffer_print(tmp->sterm); else printf("NULL\n");
|
|
|
|
- HASH_FIND (hh, it->store->idx, it->luk + 2, KLEN, tmp);
|
|
|
|
- if (tmp) LSUP_buffer_print(tmp->sterm); else printf("NULL\n");
|
|
|
|
-#endif
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- // Iteration resumes from lookup where first hashmap_iter was called.
|
|
|
|
- do {
|
|
|
|
- if (!it->entry) return LSUP_END;
|
|
|
|
|
|
|
|
|
|
+ do {
|
|
// Loop through all triples until a match is found, or end is reached.
|
|
// Loop through all triples until a match is found, or end is reached.
|
|
- if (it->eq_fn (*it->entry, it->luk)) {
|
|
|
|
- log_trace (
|
|
|
|
- "Found spok: {%lx, %lx, %lx}",
|
|
|
|
- it->entry[0], it->entry[1], it->entry[2]
|
|
|
|
- );
|
|
|
|
- /*
|
|
|
|
-#ifdef DEBUG
|
|
|
|
- IndexEntry *tmp = NULL;
|
|
|
|
- HASH_FIND (hh, it->store->idx, it->entry->key + 0, KLEN, tmp);
|
|
|
|
- LSUP_buffer_print(tmp->sterm);
|
|
|
|
- HASH_FIND (hh, it->store->idx, it->entry->key + 1, KLEN, tmp);
|
|
|
|
- LSUP_buffer_print(tmp->sterm);
|
|
|
|
- HASH_FIND (hh, it->store->idx, it->entry->key + 2, KLEN, tmp);
|
|
|
|
- LSUP_buffer_print(tmp->sterm);
|
|
|
|
-#endif
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- it->rc = LSUP_OK;
|
|
|
|
- it->ct++;
|
|
|
|
|
|
+ if (hashmap_iter (it->store->keys, &it->cur, (void **) &it->entry)) {
|
|
|
|
+ //log_trace("it->cur: %lu", it->cur);
|
|
|
|
+ if (it->eq_fn (*it->entry, it->luk)) {
|
|
|
|
+ log_trace (
|
|
|
|
+ "Found spok: {%lx, %lx, %lx}",
|
|
|
|
+ it->entry[0][0], it->entry[0][1], it->entry[0][2]
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ it->rc = LSUP_OK;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if (hashmap_iter (it->store->keys, &it->cur, (void **) it->entry))
|
|
|
|
- it->rc = LSUP_OK;
|
|
|
|
|
|
+ else it->rc = LSUP_END;
|
|
|
|
|
|
} while (it->rc == LSUP_NORESULT);
|
|
} while (it->rc == LSUP_NORESULT);
|
|
|
|
|
|
@@ -507,8 +455,7 @@ htiter_next_key (HTIterator *it, LSUP_TripleKey *spok)
|
|
LSUP_rc
|
|
LSUP_rc
|
|
LSUP_htiter_next (HTIterator *it, LSUP_BufferTriple *sspo)
|
|
LSUP_htiter_next (HTIterator *it, LSUP_BufferTriple *sspo)
|
|
{
|
|
{
|
|
- LSUP_TripleKey *cur;
|
|
|
|
- LSUP_rc rc = htiter_next_key (it, cur);
|
|
|
|
|
|
+ LSUP_rc rc = htiter_next_key (it);
|
|
if (rc != LSUP_OK) return rc;
|
|
if (rc != LSUP_OK) return rc;
|
|
|
|
|
|
return tkey_to_strp (it->store, *it->entry, sspo);
|
|
return tkey_to_strp (it->store, *it->entry, sspo);
|
|
@@ -541,22 +488,20 @@ tkey_to_strp (
|
|
|
|
|
|
|
|
|
|
static LSUP_rc
|
|
static LSUP_rc
|
|
-htstore_add_key_iter (HTIterator *it, const LSUP_TripleKey spok)
|
|
|
|
|
|
+htstore_add_key_iter (HTIterator *it, const LSUP_Key *spok)
|
|
{
|
|
{
|
|
// Add triple.
|
|
// Add triple.
|
|
log_trace ("Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
|
|
log_trace ("Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
|
|
|
|
|
|
- if (hashmap_get (it->store->keys, &spok)) {
|
|
|
|
|
|
+ if (hashmap_get (it->store->keys, spok)) {
|
|
log_trace ("Triple found. Not adding.");
|
|
log_trace ("Triple found. Not adding.");
|
|
return LSUP_NOACTION;
|
|
return LSUP_NOACTION;
|
|
}
|
|
}
|
|
|
|
|
|
log_trace ("Triple not found, inserting.");
|
|
log_trace ("Triple not found, inserting.");
|
|
|
|
|
|
- hashmap_set (it->store->keys, &spok);
|
|
|
|
|
|
+ hashmap_set (it->store->keys, (void *)spok);
|
|
if (hashmap_oom(it->store->keys)) return LSUP_MEM_ERR;
|
|
if (hashmap_oom(it->store->keys)) return LSUP_MEM_ERR;
|
|
|
|
|
|
- it->ct++;
|
|
|
|
-
|
|
|
|
return LSUP_OK;
|
|
return LSUP_OK;
|
|
}
|
|
}
|