|
@@ -97,11 +97,7 @@ uint64_t trp_key_hash_fn (
|
|
|
|
|
|
|
|
|
int trp_key_cmp_fn (const void *a, const void *b, void *udata)
|
|
|
-{
|
|
|
- const LSUP_Key *aa = a, *bb = b;
|
|
|
- log_trace ("cmp a: {%lx, %lx, %lx}", aa[0], aa[1], aa[2]);
|
|
|
- log_trace ("cmp b: {%lx, %lx, %lx}", bb[0], bb[1], bb[2]);
|
|
|
- return memcmp (a, b, TRP_KLEN); }
|
|
|
+{ return memcmp (a, b, TRP_KLEN); }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -276,17 +272,16 @@ LSUP_htstore_size (const LSUP_HTStore *ht)
|
|
|
LSUP_rc
|
|
|
LSUP_htstore_add_term (HTStore *store, const LSUP_Buffer *sterm)
|
|
|
{
|
|
|
- if (hashmap_get (store->idx, sterm)) return LSUP_NOACTION;
|
|
|
+ IndexEntry entry_s = {
|
|
|
+ .key = LSUP_buffer_hash (sterm),
|
|
|
+ };
|
|
|
+ if (hashmap_get (store->idx, &entry_s)) return LSUP_NOACTION;
|
|
|
|
|
|
- LSUP_Key tk = LSUP_buffer_hash (sterm);
|
|
|
- log_trace ("Adding term key: %lx", tk);
|
|
|
+ entry_s.sterm = LSUP_buffer_new (sterm->size, sterm->addr);
|
|
|
|
|
|
- hashmap_set (
|
|
|
- store->idx, &(IndexEntry){
|
|
|
- .key = tk,
|
|
|
- // This shall be freed with the index hashmap.
|
|
|
- .sterm = LSUP_buffer_new (sterm->size, sterm->addr)
|
|
|
- });
|
|
|
+ log_trace ("Adding term key: %lx", entry_s.key);
|
|
|
+ hashmap_set (store->idx, &entry_s);
|
|
|
+ //log_trace ("Term index size: %lu", hashmap_count (store->idx));
|
|
|
|
|
|
return LSUP_OK;
|
|
|
}
|
|
@@ -317,10 +312,8 @@ LSUP_htstore_add_iter (HTIterator *it, const LSUP_BufferTriple *sspo)
|
|
|
|
|
|
if (rc != LSUP_OK) return rc;
|
|
|
|
|
|
- for (int i = 0; i < 3; i++) {
|
|
|
- rc = LSUP_htstore_add_term (it->store, LSUP_btriple_pos (sspo, i));
|
|
|
- if (rc != LSUP_OK) return rc;
|
|
|
- }
|
|
|
+ for (int i = 0; i < 3; i++)
|
|
|
+ LSUP_htstore_add_term (it->store, LSUP_btriple_pos (sspo, i));
|
|
|
|
|
|
return rc;
|
|
|
}
|
|
@@ -336,37 +329,31 @@ LSUP_htstore_remove(
|
|
|
LSUP_HTStore *store, const LSUP_Buffer *ss, const LSUP_Buffer *sp,
|
|
|
const LSUP_Buffer *so, size_t *ct_p)
|
|
|
{
|
|
|
- LSUP_rc rc;
|
|
|
- size_t i, ct;
|
|
|
+ size_t ct;
|
|
|
|
|
|
LSUP_HTIterator *it = LSUP_htstore_lookup (store, ss, sp, so, &ct);
|
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
|
|
|
|
+ LSUP_rc rc;
|
|
|
if (ct == 0) {
|
|
|
rc = LSUP_NOACTION;
|
|
|
goto finally;
|
|
|
}
|
|
|
- // Preallocate delete list.
|
|
|
- LSUP_TripleKey **del_list = malloc (sizeof (*del_list) * ct);
|
|
|
- if (UNLIKELY (!del_list)) {
|
|
|
- rc = LSUP_MEM_ERR;
|
|
|
- goto finally;
|
|
|
- }
|
|
|
-
|
|
|
- // Gather delete list first. Looping over hashmap while deleting elements
|
|
|
- // won't work.
|
|
|
- for (i = 0; htiter_next_key (it) == LSUP_OK; i++)
|
|
|
- del_list[i] = it->entry;
|
|
|
|
|
|
- for (i = 0; i < ct; i++)
|
|
|
- hashmap_delete (store->keys, del_list[i]);
|
|
|
+ while (htiter_next_key (it) == LSUP_OK) {
|
|
|
+ log_trace (
|
|
|
+ "Deleting {%lx, %lx, %lx}.",
|
|
|
+ it->entry[0][0], it->entry[0][1], it->entry[0][2]);
|
|
|
+ hashmap_delete (store->keys, it->entry);
|
|
|
+ rc = LSUP_OK;
|
|
|
+ it->cur = 0; // Reset cursor, buckets are rearranged after deletion.
|
|
|
+ }
|
|
|
|
|
|
finally:
|
|
|
LSUP_htiter_free (it);
|
|
|
-
|
|
|
if (ct_p) *ct_p = ct;
|
|
|
|
|
|
- return LSUP_OK;
|
|
|
+ return rc;
|
|
|
}
|
|
|
|
|
|
|