Skip to content

Commit 2c68f57

Browse files
Eric Wonggitster
Eric Wong
authored andcommitted
cbtree: remove broken and unused cb_unlink
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]>
1 parent e9d7761 commit 2c68f57

File tree

2 files changed

+0
-33
lines changed

2 files changed

+0
-33
lines changed

cbtree.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -95,38 +95,6 @@ struct cb_node *cb_lookup(struct cb_tree *t, const uint8_t *k, size_t klen)
9595
return p && !memcmp(p->k, k, klen) ? p : NULL;
9696
}
9797

98-
struct cb_node *cb_unlink(struct cb_tree *t, const uint8_t *k, size_t klen)
99-
{
100-
struct cb_node **wherep = &t->root;
101-
struct cb_node **whereq = NULL;
102-
struct cb_node *q = NULL;
103-
size_t direction = 0;
104-
uint8_t c;
105-
struct cb_node *p = t->root;
106-
107-
if (!p) return NULL; /* empty tree, nothing to delete */
108-
109-
/* traverse to find best match, keeping link to parent */
110-
while (1 & (uintptr_t)p) {
111-
whereq = wherep;
112-
q = cb_node_of(p);
113-
c = q->byte < klen ? k[q->byte] : 0;
114-
direction = (1 + (q->otherbits | c)) >> 8;
115-
wherep = q->child + direction;
116-
p = *wherep;
117-
}
118-
119-
if (memcmp(p->k, k, klen))
120-
return NULL; /* no match, nothing unlinked */
121-
122-
/* found an exact match */
123-
if (whereq) /* update parent */
124-
*whereq = q->child[1 - direction];
125-
else
126-
t->root = NULL;
127-
return p;
128-
}
129-
13098
static enum cb_next cb_descend(struct cb_node *p, cb_iter fn, void *arg)
13199
{
132100
if (1 & (uintptr_t)p) {

cbtree.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ static inline void cb_init(struct cb_tree *t)
4747

4848
struct cb_node *cb_lookup(struct cb_tree *, const uint8_t *k, size_t klen);
4949
struct cb_node *cb_insert(struct cb_tree *, struct cb_node *, size_t klen);
50-
struct cb_node *cb_unlink(struct cb_tree *t, const uint8_t *k, size_t klen);
5150

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

0 commit comments

Comments
 (0)