diff options
author | Igor Sysoev <igor@sysoev.ru> | 2017-03-14 19:02:30 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2017-03-14 19:02:30 +0300 |
commit | 979108f0ef30ad8053946c47d52f80efd06c2fee (patch) | |
tree | 11242efa6beed73d7f4afa99dab9f60b8e8cb559 /src/nxt_rbtree.c | |
parent | aa047be6b95aa1694c84f326ef78775f97283cb7 (diff) | |
download | unit-979108f0ef30ad8053946c47d52f80efd06c2fee.tar.gz unit-979108f0ef30ad8053946c47d52f80efd06c2fee.tar.bz2 |
Importing memory cache pool changes from nJScript.
Diffstat (limited to 'src/nxt_rbtree.c')
-rw-r--r-- | src/nxt_rbtree.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/nxt_rbtree.c b/src/nxt_rbtree.c index 3fa5287d..fd64486f 100644 --- a/src/nxt_rbtree.c +++ b/src/nxt_rbtree.c @@ -492,3 +492,37 @@ nxt_rbtree_parent_relink(nxt_rbtree_node_t *subst, nxt_rbtree_node_t *node) link = (node == parent->left) ? &parent->left : &parent->right; *link = subst; } + + +nxt_rbtree_node_t * +nxt_rbtree_destroy_next(nxt_rbtree_t *tree, nxt_rbtree_node_t **next) +{ + nxt_rbtree_node_t *node, *subst, *parent, *sentinel; + + sentinel = nxt_rbtree_sentinel(tree); + + /* Find the leftmost node. */ + for (node = *next; node->left != sentinel; node = node->left); + + /* Replace the leftmost node with its right child. */ + subst = node->right; + parent = node->parent; + + parent->left = subst; + subst->parent = parent; + + /* + * The right child is used as the next start node. If the right child + * is the sentinel then parent of the leftmost node is used as the next + * start node. The parent of the root node is the sentinel so after + * the single root node will be replaced with the sentinel, the next + * start node will be equal to the sentinel and iteration will stop. + */ + if (subst == sentinel) { + subst = parent; + } + + *next = subst; + + return node; +} |