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 <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Wong committed
Dec 7, 2021 at 18:38 UTC
2c68f577fc8a400f4d354f4700e4809c1bfd6470
2 files changed
-33
cbtree.c
-32
@@ -95,38 +95,6 @@ struct cb_node *cb_lookup(struct cb_tree *t, const uint8_t *k, size_t klen)
95
return p && !memcmp(p->k, k, klen) ? p : NULL;
96
}
97
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
-
98
static enum cb_next cb_descend(struct cb_node *p, cb_iter fn, void *arg)
99
{
100
if (1 & (uintptr_t)p) {
cbtree.h
-1
@@ -47,7 +47,6 @@ static inline void cb_init(struct cb_tree *t)
47
48
struct cb_node *cb_lookup(struct cb_tree *, const uint8_t *k, size_t klen);
49
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);
50
51
typedef enum cb_next (*cb_iter)(struct cb_node *, void *arg);
52