15 x->child[dir] = y->
child[!dir];
29 x->child[dir] = z->child[!dir];
31 x->red = y->
red =
true;
43 int d =
cmp(data,
x, user);
69 int d = 1,
d2, dep = 0;
79 d =
cmp(data, q->child[
d2], cmp_user);
85 del_link = &q->child[
d2];
96 if (q->red ||
red(q->child[
d])) {
99 if (
red(q->child[!
d])) {
100 if (del_link && *del_link == q) {
101 del_link = &q->child[!
d]->child[
d];
103 p->child[
d2] =
zag(q, !
d, sum);
115 if (!
red(
s->child[0]) && !
red(
s->child[1])) {
117 q->red =
s->red =
true;
119 int d3 =
g->child[0] !=
p;
122 if (del_link && *del_link ==
p) {
123 del_link = &
s->child[
d2]->child[
d2];
127 if (del_link && *del_link ==
p) {
128 del_link = &
s->child[
d2];
132 t->
red = q->red =
true;
142 p->child[q !=
p->child[0]] = q->child[q->child[0] ==
NULL];
157 (*root)->red =
false;
183 }
else if (
red(q->child[0]) &&
red(q->child[1])) {
184 q->child[0]->red = q->child[1]->red =
false;
189 if (q->red &&
p &&
p->red) {
190 int d3 = t ? t->
child[0] !=
g : -1,
d2 =
g->child[0] !=
p;
191 if (
p->child[
d2] == q) {
208 d =
cmp(data, q, cmp_user);
252 int d =
cmp(data, cur, cmp_user);
253 cur = cur->
child[(
d < 0) ? 0 : 1];
256 for (; dep > 0; dep--) {
269 int d =
cmp(data,
x, user);
298 int d =
cmp(data,
x, user);
316 int d =
cmp(data,
x, user);
334 for (;
x;
x =
x->child[dir]) {
350 for (
x =
x->child[!dir];
x;
x =
x->child[dir]) {
385 return cmp_wrap->
cmp(incoming_node->
data, in_tree_node->
data, cmp_wrap->
user);
391 return cmp_wrap->
cmp((
void *)incoming, in_tree_node->
data, cmp_wrap->
user);
397 if (!ret && cmp_wrap->
free) {
409 RZ_LOG_ERROR(
"Failed to allocate new red-black tree root\n");
416 if (!incoming_node) {
417 RZ_LOG_ERROR(
"Failed to allocate new red-black tree node\n");
420 incoming_node->
data = data;
425 if (root_node != (&tree->
root->
node)) {
429 RZ_LOG_ERROR(
"Failed to insert new red-black tree node\n");
444 if (!(tree &&
cmp && tree->
root)) {
451 if (root_node != (&tree->
root->
node)) {
472 if (tree && tree->
root) {
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
static static fork const void static count static fd const char const char static newpath const char static path const char path
RZ_API void Ht_() free(HtName_(Ht) *ht)
static void freefn(HtName_(Ht) *ht, HT_(Kv) *kv)
RZ_API RBIter rz_rbtree_last(RBNode *tree)
RZ_API RZ_OWN RContRBTree * rz_rbtree_cont_newf(RContRBFree f)
RZ_API bool rz_rbtree_cont_delete(RContRBTree *tree, void *data, RContRBCmp cmp, void *user)
RZ_API RBNode * rz_rbtree_upper_bound(RBNode *x, void *data, RBComparator cmp, void *user)
RZ_API void rz_rbtree_cont_free(RContRBTree *tree)
static RBNode * zig_zag(RBNode *x, int dir, RBNodeSum sum)
RZ_API bool rz_rbtree_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *user)
Returns true if the node was inserted successfully.
RZ_API RBNode * rz_rbtree_lower_bound(RBNode *x, void *data, RBComparator cmp, void *user)
RZ_API bool rz_rbtree_aug_update_sum(RBNode *root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum)
Returns true if the sum has been updated, false if node has not been found.
static void cont_node_free(RBNode *node, void *user)
RZ_API bool rz_rbtree_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user)
Returns true if a node with an equal key is deleted.
static RBIter _first(RBNode *x, int dir)
RZ_API bool rz_rbtree_cont_insert(RContRBTree *tree, void *data, RContRBCmp cmp, void *user)
static int cont_rbtree_cmp_wrapper(const void *incoming, const RBNode *in_tree, void *user)
RZ_API void rz_rbtree_free(RZ_NULLABLE RBNode *x, RBNodeFree freefn, void *user)
RZ_API bool rz_rbtree_aug_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user, RBNodeSum sum)
Returns true if a node with an equal key is deleted.
static bool red(RBNode *x)
RZ_API RBIter rz_rbtree_lower_bound_forward(RBNode *root, void *data, RBComparator cmp, void *user)
RZ_API RBNode * rz_rbtree_find(RBNode *x, void *data, RBComparator cmp, void *user)
static RBNode * zag(RBNode *x, int dir, RBNodeSum sum)
RZ_API void * rz_rbtree_cont_find(RContRBTree *tree, void *data, RContRBCmp cmp, void *user)
RZ_API RBIter rz_rbtree_first(RBNode *tree)
RZ_API RZ_OWN RContRBTree * rz_rbtree_cont_new(void)
RZ_API void rz_rbtree_iter_next(RBIter *it)
static int cont_rbtree_free_cmp_wrapper(const void *data, const RBNode *in_tree, void *user)
static RBIter bound_iter(RBNode *x, void *data, RBComparator cmp, bool upper, void *user)
RZ_API void rz_rbtree_iter_prev(RBIter *it)
static int cont_rbtree_search_cmp_wrapper(const void *incoming, const RBNode *in_tree, void *user)
static void _next(RBIter *it, int dir)
RZ_API bool rz_rbtree_aug_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum)
Returns true if the node was inserted successfully.
struct rcrb_cmp_wrap_t RCRBCmpWrap
RZ_API RBIter rz_rbtree_upper_bound_backward(RBNode *root, void *data, RBComparator cmp, void *user)
#define rz_return_val_if_fail(expr, val)
#define RZ_LOG_ERROR(fmtstr,...)
void(* RContRBFree)(void *)
void(* RBNodeFree)(RBNode *node, void *user)
void(* RBNodeSum)(RBNode *node)
#define RZ_RBTREE_MAX_HEIGHT
int(* RContRBCmp)(void *incoming, void *in, void *user)
int(* RBComparator)(const void *incoming, const RBNode *in_tree, void *user)
#define container_of(ptr, type, member)
RBNode * path[RZ_RBTREE_MAX_HEIGHT]
struct rz_rb_node_t * child[2]