0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-03 15:41:54 +00:00

The other direction of searching and traversing

This commit is contained in:
Jan Maria Matejka 2018-12-03 14:24:09 +01:00
parent db1577e902
commit d8bd7b599b

View File

@ -144,6 +144,19 @@
out = *pointer; \
out; \
})
#define REDBLACK_FIND_DOWN(type, name, key, compare, root, what) ({ \
type **pointer, *prev = NULL, *out; \
REDBLACK_FIND_POINTER(name, key, compare, root, what, pointer) \
prev = *pointer; \
if (!*pointer && prev) \
if (pointer == &(REDBLACK_LEFT_CHILD(name, prev))) \
out = REDBLACK_PREV(type, name, prev); \
else \
out = prev; \
else \
out = *pointer; \
out; \
})
#define REDBLACK_FIRST(type, name, root) ({ \
type *first = root; \
@ -171,6 +184,24 @@
where; \
})
#define REDBLACK_PREV(type, name, node) ({ \
type *where = node; \
if (REDBLACK_LEFT_CHILD(name, where)) { \
where = REDBLACK_LEFT_CHILD(name, where); \
while (REDBLACK_RIGHT_CHILD(name, where)) \
where = REDBLACK_RIGHT_CHILD(name, where); \
} else \
while (1) { \
type *p = REDBLACK_PARENT(type, name, where); \
int ps = p ? REDBLACK_PARENT_SIDE(name, p, where) : 0; \
where = p; \
if (ps == REDBLACK_LEFT) \
continue; \
break; \
} \
where; \
})
/* Low level tree manipulation */