提交 05486e04 编写于 作者: S stevenj

added rb_tree_shift_keys

darcs-hash:20070906020018-c8de0-ebbcf31bebdb208a5d1ff57aca14a3994f08f549.gz
上级 6477e3e5
......@@ -371,3 +371,16 @@ rb_node *rb_tree_resort(rb_tree *t, rb_node *n)
insert_node(t, n);
return n;
}
/* shift all key pointers by kshift ... this is useful when the keys
are pointers into another array, that has been resized with realloc */
static void shift_keys(rb_node *n, ptrdiff_t kshift) /* assumes n != NIL */
{
n->k += kshift;
if (n->l != NIL) shift_keys(n->l, kshift);
if (n->r != NIL) shift_keys(n->r, kshift);
}
void rb_tree_shift_keys(rb_tree *t, ptrdiff_t kshift)
{
if (t->root != NIL) shift_keys(t->root, kshift);
}
#ifndef REDBLACK_H
#define REDBLACK_H
#include <stddef.h> /* for ptrdiff_t */
#ifdef __cplusplus
extern "C"
{
......@@ -38,6 +40,7 @@ extern rb_node *rb_tree_min(rb_tree *t);
extern rb_node *rb_tree_max(rb_tree *t);
extern rb_node *rb_tree_succ(rb_node *n);
extern rb_node *rb_tree_pred(rb_node *n);
extern void rb_tree_shift_keys(rb_tree *t, ptrdiff_t kshift);
/* To change a key, use rb_tree_find+resort. Removing a node
currently wastes memory unless you change the allocation scheme
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册