mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
[INCLUDE/WINE] Update rbtree.h. CORE-14656
This commit is contained in:
parent
983dc4266c
commit
3c18f2a7c7
1 changed files with 29 additions and 7 deletions
|
@ -107,6 +107,13 @@ static inline struct wine_rb_entry *wine_rb_head(struct wine_rb_entry *iter)
|
|||
return iter;
|
||||
}
|
||||
|
||||
static inline struct wine_rb_entry *wine_rb_tail(struct wine_rb_entry *iter)
|
||||
{
|
||||
if (!iter) return NULL;
|
||||
while (iter->right) iter = iter->right;
|
||||
return iter;
|
||||
}
|
||||
|
||||
static inline struct wine_rb_entry *wine_rb_next(struct wine_rb_entry *iter)
|
||||
{
|
||||
if (iter->right) return wine_rb_head(iter->right);
|
||||
|
@ -114,6 +121,13 @@ static inline struct wine_rb_entry *wine_rb_next(struct wine_rb_entry *iter)
|
|||
return iter->parent;
|
||||
}
|
||||
|
||||
static inline struct wine_rb_entry *wine_rb_prev(struct wine_rb_entry *iter)
|
||||
{
|
||||
if (iter->left) return wine_rb_tail(iter->left);
|
||||
while (iter->parent && iter->parent->left == iter) iter = iter->parent;
|
||||
return iter->parent;
|
||||
}
|
||||
|
||||
static inline struct wine_rb_entry *wine_rb_postorder_head(struct wine_rb_entry *iter)
|
||||
{
|
||||
if (!iter) return NULL;
|
||||
|
@ -139,19 +153,27 @@ static inline struct wine_rb_entry *wine_rb_postorder_next(struct wine_rb_entry
|
|||
/* iterate through the tree using a tree entry */
|
||||
#define WINE_RB_FOR_EACH_ENTRY(elem, tree, type, field) \
|
||||
for ((elem) = WINE_RB_ENTRY_VALUE(wine_rb_head((tree)->root), type, field); \
|
||||
&(elem)->field; \
|
||||
(elem) != WINE_RB_ENTRY_VALUE(0, type, field); \
|
||||
(elem) = WINE_RB_ENTRY_VALUE(wine_rb_next(&elem->field), type, field))
|
||||
|
||||
/* iterate through the tree using using postorder, making it safe to free the entry */
|
||||
#define WINE_RB_FOR_EACH_DESTRUCTOR(cursor, cursor2, tree) \
|
||||
for ((cursor) = wine_rb_postorder_head((tree)->root); \
|
||||
(cursor) && (((cursor2) = wine_rb_postorder_next(cursor)) || 1); \
|
||||
(cursor) = (cursor2))
|
||||
|
||||
/* iterate through the tree using a tree entry and postorder, making it safe to free the entry */
|
||||
#define WINE_RB_FOR_EACH_ENTRY_DESTRUCTOR(elem, elem2, tree, type, field) \
|
||||
for ((elem) = WINE_RB_ENTRY_VALUE(wine_rb_postorder_head((tree)->root), type, field); \
|
||||
(elem) != WINE_RB_ENTRY_VALUE(0, type, field) \
|
||||
&& (((elem2) = WINE_RB_ENTRY_VALUE(wine_rb_postorder_next(&(elem)->field), type, field)) || 1); \
|
||||
(elem) = (elem2))
|
||||
|
||||
|
||||
static inline void wine_rb_postorder(struct wine_rb_tree *tree, wine_rb_traverse_func_t *callback, void *context)
|
||||
{
|
||||
struct wine_rb_entry *iter, *next;
|
||||
|
||||
for (iter = wine_rb_postorder_head(tree->root); iter; iter = next)
|
||||
{
|
||||
next = wine_rb_postorder_next(iter);
|
||||
callback(iter, context);
|
||||
}
|
||||
WINE_RB_FOR_EACH_DESTRUCTOR(iter, next, tree) callback(iter, context);
|
||||
}
|
||||
|
||||
static inline void wine_rb_init(struct wine_rb_tree *tree, wine_rb_compare_func_t compare)
|
||||
|
|
Loading…
Reference in a new issue