mirror of
git://projects.qi-hardware.com/wernermisc.git
synced 2024-11-22 07:00:39 +02:00
qpkg: removed non-generic jrb access functions
- jrb.h, jrb.c (jrb_insert_str, jrb_insert_int, jrb_insert_dbl): removed - jrb.h, jrb.c (jrb_find_str, jrb_find_int, jrb_find_dbl): removed - jrb.h, jrb.c (jrb_find_gte_str, jrb_find_gte_int, jrb_find_gte_dbl): removed - jrb.c (jrb_print_tree, jrb_iprint_tree): removed unused tree dump functions
This commit is contained in:
parent
b4ff969a24
commit
769d31581d
191
qpkg/jrb.c
191
qpkg/jrb.c
@ -50,8 +50,6 @@ static JRB lprev(JRB n);
|
||||
static JRB rprev(JRB n);
|
||||
static void recolor(JRB n);
|
||||
static void single_rotate(JRB y, int l);
|
||||
static void jrb_print_tree(JRB t, int level);
|
||||
static void jrb_iprint_tree(JRB t, int level);
|
||||
|
||||
#define isred(n) (n->red)
|
||||
#define isblack(n) (!isred(n))
|
||||
@ -167,108 +165,6 @@ JRB make_jrb(void)
|
||||
return head;
|
||||
}
|
||||
|
||||
JRB jrb_find_gte_str(JRB n, char *key, int *fnd)
|
||||
{
|
||||
int cmp;
|
||||
|
||||
*fnd = 0;
|
||||
if (!ishead(n)) {
|
||||
fprintf(stderr, "jrb_find_gte_str called on non-head %p\n", n);
|
||||
exit(1);
|
||||
}
|
||||
if (n->parent == n) return n;
|
||||
cmp = strcmp(key, n->blink->key.s);
|
||||
if (cmp == 0) {
|
||||
*fnd = 1;
|
||||
return n->blink;
|
||||
}
|
||||
if (cmp > 0) return n;
|
||||
else n = n->parent;
|
||||
while (1) {
|
||||
if (isext(n)) return n;
|
||||
cmp = strcmp(key, getlext(n)->key.s);
|
||||
if (cmp == 0) {
|
||||
*fnd = 1;
|
||||
return getlext(n);
|
||||
}
|
||||
if (cmp < 0) n = n->flink ; else n = n->blink;
|
||||
}
|
||||
}
|
||||
|
||||
JRB jrb_find_str(JRB n, char *key)
|
||||
{
|
||||
int fnd;
|
||||
JRB j;
|
||||
j = jrb_find_gte_str(n, key, &fnd);
|
||||
if (fnd) return j; else return NULL;
|
||||
}
|
||||
|
||||
JRB jrb_find_gte_int(JRB n, int ikey, int *fnd)
|
||||
{
|
||||
*fnd = 0;
|
||||
if (!ishead(n)) {
|
||||
fprintf(stderr, "jrb_find_gte_int called on non-head %p\n", n);
|
||||
exit(1);
|
||||
}
|
||||
if (n->parent == n) return n;
|
||||
if (ikey == n->blink->key.i) {
|
||||
*fnd = 1;
|
||||
return n->blink;
|
||||
}
|
||||
if (ikey > n->blink->key.i) return n;
|
||||
else n = n->parent;
|
||||
while (1) {
|
||||
if (isext(n)) return n;
|
||||
if (ikey == getlext(n)->key.i) {
|
||||
*fnd = 1;
|
||||
return getlext(n);
|
||||
}
|
||||
n = (ikey < getlext(n)->key.i) ? n->flink : n->blink;
|
||||
}
|
||||
}
|
||||
|
||||
JRB jrb_find_int(JRB n, int ikey)
|
||||
{
|
||||
int fnd;
|
||||
JRB j;
|
||||
|
||||
j = jrb_find_gte_int(n, ikey, &fnd);
|
||||
if (fnd) return j; else return NULL;
|
||||
}
|
||||
|
||||
JRB jrb_find_gte_dbl(JRB n, double dkey, int *fnd)
|
||||
{
|
||||
*fnd = 0;
|
||||
if (!ishead(n)) {
|
||||
fprintf(stderr, "jrb_find_gte_dbl called on non-head %p\n", n);
|
||||
exit(1);
|
||||
}
|
||||
if (n->parent == n) return n;
|
||||
if (dkey == n->blink->key.d) {
|
||||
*fnd = 1;
|
||||
return n->blink;
|
||||
}
|
||||
if (dkey > n->blink->key.d) return n;
|
||||
else n = n->parent;
|
||||
while (1) {
|
||||
if (isext(n)) return n;
|
||||
if (dkey == getlext(n)->key.d) {
|
||||
*fnd = 1;
|
||||
return getlext(n);
|
||||
}
|
||||
n = (dkey < getlext(n)->key.d) ? n->flink : n->blink;
|
||||
}
|
||||
}
|
||||
|
||||
JRB jrb_find_dbl(JRB n, double dkey)
|
||||
{
|
||||
int fnd;
|
||||
JRB j;
|
||||
|
||||
j = jrb_find_gte_dbl(n, dkey, &fnd);
|
||||
if (fnd) return j; else return NULL;
|
||||
}
|
||||
|
||||
JRB jrb_find_gte_gen(JRB n, Jval key,int (*fxn)(Jval, Jval), int *fnd)
|
||||
{
|
||||
int cmp;
|
||||
@ -549,59 +445,6 @@ void jrb_delete_node(JRB n)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void jrb_print_tree(JRB t, int level)
|
||||
{
|
||||
int i;
|
||||
if (ishead(t) && t->parent == t) {
|
||||
printf("tree %p is empty\n", t);
|
||||
} else if (ishead(t)) {
|
||||
printf("Head: %p. Root = %p\n", t, t->parent);
|
||||
jrb_print_tree(t->parent, 0);
|
||||
} else {
|
||||
if (isext(t)) {
|
||||
for (i = 0; i < level; i++) putchar(' ');
|
||||
printf("Ext node %p: %c,%c: p=%p, k=%s\n",
|
||||
t, isred(t)?'R':'B', isleft(t)?'l':'r', t->parent, t->key.s);
|
||||
} else {
|
||||
jrb_print_tree(t->flink, level+2);
|
||||
jrb_print_tree(t->blink, level+2);
|
||||
for (i = 0; i < level; i++) putchar(' ');
|
||||
printf("Int node %p: %c,%c: l=%p, r=%p, p=%p, lr=(%s,%s)\n",
|
||||
t, isred(t)?'R':'B', isleft(t)?'l':'r', t->flink,
|
||||
t->blink,
|
||||
t->parent, getlext(t)->key.s, getrext(t)->key.s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void jrb_iprint_tree(JRB t, int level)
|
||||
{
|
||||
int i;
|
||||
if (ishead(t) && t->parent == t) {
|
||||
printf("tree %p is empty\n", t);
|
||||
} else if (ishead(t)) {
|
||||
printf("Head: %p. Root = %p, < = %p, > = %p\n",
|
||||
t, t->parent, t->blink, t->flink);
|
||||
jrb_iprint_tree(t->parent, 0);
|
||||
} else {
|
||||
if (isext(t)) {
|
||||
for (i = 0; i < level; i++) putchar(' ');
|
||||
printf("Ext node %p: %c,%c: p=%p, <=%p, >=%p k=%d\n",
|
||||
t, isred(t)?'R':'B', isleft(t)?'l':'r', t->parent,
|
||||
t->blink, t->flink, t->key.i);
|
||||
} else {
|
||||
jrb_iprint_tree(t->flink, level+2);
|
||||
jrb_iprint_tree(t->blink, level+2);
|
||||
for (i = 0; i < level; i++) putchar(' ');
|
||||
printf("Int node %p: %c,%c: l=%p, r=%p, p=%p, lr=(%d,%d)\n",
|
||||
t, isred(t)?'R':'B', isleft(t)?'l':'r', t->flink,
|
||||
t->blink,
|
||||
t->parent, getlext(t)->key.i, getrext(t)->key.i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int jrb_nblack(JRB n)
|
||||
{
|
||||
int nb;
|
||||
@ -650,40 +493,6 @@ Jval jrb_val(JRB n)
|
||||
return n->val;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static JRB jrb_insert_a(JRB nd, Jval key, Jval val)
|
||||
{
|
||||
return jrb_insert_b(nd->flink, key, val);
|
||||
}
|
||||
#endif
|
||||
|
||||
JRB jrb_insert_str(JRB tree, char *key, Jval val)
|
||||
{
|
||||
Jval k;
|
||||
int fnd;
|
||||
|
||||
k.s = key;
|
||||
return jrb_insert_b(jrb_find_gte_str(tree, key, &fnd), k, val);
|
||||
}
|
||||
|
||||
JRB jrb_insert_int(JRB tree, int ikey, Jval val)
|
||||
{
|
||||
Jval k;
|
||||
int fnd;
|
||||
|
||||
k.i = ikey;
|
||||
return jrb_insert_b(jrb_find_gte_int(tree, ikey, &fnd), k, val);
|
||||
}
|
||||
|
||||
JRB jrb_insert_dbl(JRB tree, double dkey, Jval val)
|
||||
{
|
||||
Jval k;
|
||||
int fnd;
|
||||
|
||||
k.d = dkey;
|
||||
return jrb_insert_b(jrb_find_gte_dbl(tree, dkey, &fnd), k, val);
|
||||
}
|
||||
|
||||
JRB jrb_insert_gen(JRB tree, Jval key, Jval val,
|
||||
int (*func)(Jval, Jval))
|
||||
{
|
||||
|
@ -67,17 +67,11 @@ extern JRB make_jrb(void); /* Creates a new rb-tree */
|
||||
jrb_insert uses strcmp() as comparison funcion. jrb_inserti uses <>=,
|
||||
jrb_insertg uses func() */
|
||||
|
||||
extern JRB jrb_insert_str(JRB tree, char *key, Jval val);
|
||||
extern JRB jrb_insert_int(JRB tree, int ikey, Jval val);
|
||||
extern JRB jrb_insert_dbl(JRB tree, double dkey, Jval val);
|
||||
extern JRB jrb_insert_gen(JRB tree, Jval key, Jval val, int (*func)(Jval,Jval));
|
||||
|
||||
/* returns an external node in t whose value is equal k. Returns NULL if
|
||||
there is no such node in the tree */
|
||||
|
||||
extern JRB jrb_find_str(JRB root, char *key);
|
||||
extern JRB jrb_find_int(JRB root, int ikey);
|
||||
extern JRB jrb_find_dbl(JRB root, double dkey);
|
||||
extern JRB jrb_find_gen(JRB root, Jval, int (*func)(Jval, Jval));
|
||||
|
||||
|
||||
@ -85,9 +79,6 @@ extern JRB jrb_find_gen(JRB root, Jval, int (*func)(Jval, Jval));
|
||||
k or whose value is the smallest value greater than k. Sets found to
|
||||
1 if the key was found, and 0 otherwise. */
|
||||
|
||||
extern JRB jrb_find_gte_str(JRB root, char *key, int *found);
|
||||
extern JRB jrb_find_gte_int(JRB root, int ikey, int *found);
|
||||
extern JRB jrb_find_gte_dbl(JRB root, double dkey, int *found);
|
||||
extern JRB jrb_find_gte_gen(JRB root, Jval key,
|
||||
int (*func)(Jval, Jval), int *found);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user