|
@@ -97,7 +97,11 @@ uint64_t trp_key_hash_fn (
|
|
|
|
|
|
|
|
|
|
int trp_key_cmp_fn (const void *a, const void *b, void *udata)
|
|
int trp_key_cmp_fn (const void *a, const void *b, void *udata)
|
|
-{ return memcmp (a, b, TRP_KLEN); }
|
|
|
|
|
|
+{
|
|
|
|
+ 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); }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -330,24 +334,39 @@ LSUP_htstore_add_done (HTIterator *it)
|
|
LSUP_rc
|
|
LSUP_rc
|
|
LSUP_htstore_remove(
|
|
LSUP_htstore_remove(
|
|
LSUP_HTStore *store, const LSUP_Buffer *ss, const LSUP_Buffer *sp,
|
|
LSUP_HTStore *store, const LSUP_Buffer *ss, const LSUP_Buffer *sp,
|
|
- const LSUP_Buffer *so, size_t *ct)
|
|
|
|
|
|
+ const LSUP_Buffer *so, size_t *ct_p)
|
|
{
|
|
{
|
|
- LSUP_rc rc = LSUP_NOACTION;
|
|
|
|
|
|
+ LSUP_rc rc;
|
|
|
|
+ size_t i, ct;
|
|
|
|
|
|
- LSUP_HTIterator *it = LSUP_htstore_lookup (store, ss, sp, so, ct);
|
|
|
|
|
|
+ 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;
|
|
|
|
|
|
- while (htiter_next_key (it)) {
|
|
|
|
- if (it->rc == LSUP_OK) {
|
|
|
|
- LSUP_TripleKey *del = hashmap_delete (store->keys, it->entry);
|
|
|
|
- free (del);
|
|
|
|
- rc = LSUP_OK;
|
|
|
|
- }
|
|
|
|
|
|
+ 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]);
|
|
|
|
+
|
|
|
|
+finally:
|
|
LSUP_htiter_free (it);
|
|
LSUP_htiter_free (it);
|
|
|
|
|
|
- return rc;
|
|
|
|
|
|
+ if (ct_p) *ct_p = ct;
|
|
|
|
+
|
|
|
|
+ return LSUP_OK;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -406,10 +425,8 @@ LSUP_htstore_lookup (HTStore *store, const LSUP_Buffer *ss,
|
|
|
|
|
|
if (ct) {
|
|
if (ct) {
|
|
// Loop over results to determine count.
|
|
// Loop over results to determine count.
|
|
- while (htiter_next_key (it) == LSUP_OK) {
|
|
|
|
- (*ct)++;
|
|
|
|
- log_trace ("ct: %lu", *ct);
|
|
|
|
- }
|
|
|
|
|
|
+ while (htiter_next_key (it) == LSUP_OK) (*ct)++;
|
|
|
|
+
|
|
// Reposition cursor to the hashtable beginning.
|
|
// Reposition cursor to the hashtable beginning.
|
|
it->cur = 0;
|
|
it->cur = 0;
|
|
it->rc = LSUP_OK;
|
|
it->rc = LSUP_OK;
|