Skip to content

Commit

Permalink
cbtree: remove broken and unused cb_unlink
Browse files Browse the repository at this point in the history
cb_unlink is broken once a node is no longer self-referential
due to subsequent insertions.  This is a consequence of an
intrusive implementation and I'm not sure if it's easily fixable
while retaining our cache-friendly intrusive property (I've
tried for several hours in another project).

In any case, we're not using cb_unlink anywhere in our codebase,
just get rid of it to avoid misleading future readers.

Signed-off-by: Eric Wong <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Eric Wong authored and gitster committed Dec 7, 2021
1 parent e9d7761 commit 2c68f57
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 33 deletions.
32 changes: 0 additions & 32 deletions cbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,6 @@ struct cb_node *cb_lookup(struct cb_tree *t, const uint8_t *k, size_t klen)
return p && !memcmp(p->k, k, klen) ? p : NULL;
}

struct cb_node *cb_unlink(struct cb_tree *t, const uint8_t *k, size_t klen)
{
struct cb_node **wherep = &t->root;
struct cb_node **whereq = NULL;
struct cb_node *q = NULL;
size_t direction = 0;
uint8_t c;
struct cb_node *p = t->root;

if (!p) return NULL; /* empty tree, nothing to delete */

/* traverse to find best match, keeping link to parent */
while (1 & (uintptr_t)p) {
whereq = wherep;
q = cb_node_of(p);
c = q->byte < klen ? k[q->byte] : 0;
direction = (1 + (q->otherbits | c)) >> 8;
wherep = q->child + direction;
p = *wherep;
}

if (memcmp(p->k, k, klen))
return NULL; /* no match, nothing unlinked */

/* found an exact match */
if (whereq) /* update parent */
*whereq = q->child[1 - direction];
else
t->root = NULL;
return p;
}

static enum cb_next cb_descend(struct cb_node *p, cb_iter fn, void *arg)
{
if (1 & (uintptr_t)p) {
Expand Down
1 change: 0 additions & 1 deletion cbtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ static inline void cb_init(struct cb_tree *t)

struct cb_node *cb_lookup(struct cb_tree *, const uint8_t *k, size_t klen);
struct cb_node *cb_insert(struct cb_tree *, struct cb_node *, size_t klen);
struct cb_node *cb_unlink(struct cb_tree *t, const uint8_t *k, size_t klen);

typedef enum cb_next (*cb_iter)(struct cb_node *, void *arg);

Expand Down

0 comments on commit 2c68f57

Please sign in to comment.