Commit d64bc472 authored by Daniel Salzman's avatar Daniel Salzman

qp-trie: use libknot error codes in qp_trie_del

parent fe686f41
......@@ -65,10 +65,9 @@ inline static int hattrie_find_leq(hattrie_t *trie, const char *key, size_t len,
return qp_trie_get_leq(trie, key, len, dst);
}
inline static int hattrie_del(hattrie_t *trie, const char* key, size_t len)
inline static int hattrie_del(hattrie_t *trie, const char* key, size_t len, value_t *val)
{
// QP has 1 as error instead of -1, to be consistent with qp_trie_get_leq
return - qp_trie_del(trie, key, len, NULL);
return qp_trie_del(trie, key, len, val);
}
inline static hattrie_iter_t* hattrie_iter_begin(hattrie_t *trie)
......
......@@ -308,7 +308,7 @@ int qp_trie_del(struct qp_trie *tbl, const char *key, uint32_t len, value_t *val
{
assert(tbl);
if (!tbl->weight)
return 1;
return KNOT_ENOENT;
node_t *t = &tbl->root; // current and parent node
branch_t *p = NULL;
bitmap_t b = 0;
......@@ -316,12 +316,12 @@ int qp_trie_del(struct qp_trie *tbl, const char *key, uint32_t len, value_t *val
__builtin_prefetch(t->branch.twigs);
b = twigbit(t, key, len);
if (!hastwig(t, b))
return 1;
return KNOT_ENOENT;
p = &t->branch;
t = twig(t, twigoff(t, b));
}
if (key_cmp(key, len, t->leaf.key->chars, t->leaf.key->len) != 0)
return 1;
return KNOT_ENOENT;
mm_free(&tbl->mm, t->leaf.key);
if (val != NULL)
*val = t->leaf.val; // we return value_t directly when deleting
......@@ -329,7 +329,7 @@ int qp_trie_del(struct qp_trie *tbl, const char *key, uint32_t len, value_t *val
if (unlikely(!p)) { // whole trie was a single leaf
assert(tbl->weight == 0);
empty_root(&tbl->root);
return 0;
return KNOT_EOK;
}
// remove leaf t as child of p
int ci = t - p->twigs, // child index via pointer arithmetic
......@@ -340,7 +340,7 @@ int qp_trie_del(struct qp_trie *tbl, const char *key, uint32_t len, value_t *val
node_t *twigs = p->twigs;
(*(node_t *)p) = twigs[1 - ci]; // it might be a leaf or branch
mm_free(&tbl->mm, twigs);
return 0;
return KNOT_EOK;
}
memmove(p->twigs + ci, p->twigs + ci + 1, sizeof(node_t) * (cc - ci - 1));
p->bitmap &= ~b;
......@@ -350,7 +350,7 @@ int qp_trie_del(struct qp_trie *tbl, const char *key, uint32_t len, value_t *val
p->twigs = twigs;
/* We can ignore mm_realloc failure, only beware that next time
* the prev_size passed to it wouldn't be correct; TODO? */
return 0;
return KNOT_EOK;
}
/*!
......
......@@ -72,7 +72,7 @@ int qp_trie_get_leq(struct qp_trie *tbl, const char *key, uint32_t len, value_t
int qp_trie_apply(struct qp_trie *tbl, int (*f)(value_t *, void *), void *d);
/*!
* \brief Remove an item, returning 0 if succeeded or 1 if not found.
* \brief Remove an item, returning KNOT_EOK if succeeded or KNOT_ENOENT if not found.
*
* If val!=NULL and deletion succeeded, the deleted value is set.
*/
......
......@@ -846,7 +846,7 @@ static void upd_changes(
case CONF_IO_TUNSET:
if (*current & CONF_IO_TSET) {
// Remove inserted zone -> no change.
hattrie_del(zones, (const char *)io->id, io->id_len);
hattrie_del(zones, (const char *)io->id, io->id_len, NULL);
} else {
// Remove existing zone.
*current |= type;
......
......@@ -147,7 +147,7 @@ int zone_tree_remove(zone_tree_t *tree,
*removed = (zone_node_t *)(*rval);
}
hattrie_del(tree, (char*)lf+1, *lf);
hattrie_del(tree, (char*)lf+1, *lf, NULL);
return KNOT_EOK;
}
......
......@@ -103,7 +103,7 @@ static int insert(knot_db_txn_t *txn, knot_db_val_t *key, knot_db_val_t *val, un
static int del(knot_db_txn_t *txn, knot_db_val_t *key)
{
return hattrie_del((hattrie_t *)txn->db, key->data, key->len);
return hattrie_del((hattrie_t *)txn->db, key->data, key->len, NULL);
}
static knot_db_iter_t *iter_begin(knot_db_txn_t *txn, unsigned flags)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment