pike.git
/
src
/
rbtree.h
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/rbtree.h:1:
/* An implementation of a threaded red/black balanced binary tree. * * Created 2001-04-27 by Martin Stjernholm *
-
* $Id: rbtree.h,v 1.
3
2001/05/01
07
:
52
:
20
mast Exp $
+
* $Id: rbtree.h,v 1.
4
2001/05/01
23
:
53
:
19
mast Exp $
*/ #ifndef RBTREE_H #define RBTREE_H #include "array.h" /* A red/black tree is a binary tree with one extra bit of info in * each node - the color of it. The following properties holds: *
pike.git/src/rbtree.h:241:
free_svalue (_rb_node_to2); \ assign_rb_node_ind_no_free (_rb_node_to2, (node)); \ } while (0) #define push_rb_node_ind(node) do { \ assign_rb_node_ind_no_free (Pike_sp, (node)); \ Pike_sp++; \ } while (0) #define use_rb_node_ind(node, var) \
-
(var = (node)->ind, var.type &= ~RB_IND_FLAG_MASK, var)
+
(var = (node)->ind, var.type &= ~RB_IND_FLAG_MASK,
&
var)
/* Low-level tools, for use with arbitrary data. These only requires * that the nodes begin with the rb_node_hdr struct. */ /* A sliced stack is used to track the way down in a tree, so we can * back up again easily while rebalancing it. The first slice is * allocated on the C stack. */ #define STACK_SLICE_SIZE 20 /* This is in the worst possible case enough for trees of size
pike.git/src/rbtree.h:364:
{n_leaf;} \ else { \ {n_sub;} \ RBSTACK_PUSH (rbstack, node); \ (node) = (node)->next; \ goto PIKE_CONCAT (enter_, label); \ } \ PIKE_CONCAT (leave_, label): \ while (1) { \ {pop;} \
+
PIKE_CONCAT (skip_, label): \
low_rb_last_ = (node); \ RBSTACK_POP (rbstack, node); \ if (!(node)) break; \ if (low_rb_last_ == (node)->prev) \ goto PIKE_CONCAT (between_, label); \ } \ } \ } while (0) #define LOW_RB_DEBUG_TRAVERSE(label, rbstack, node, push, p_leaf, p_sub, between, n_leaf, n_sub, pop) \
pike.git/src/rbtree.h:485:
DO_IF_DEBUG ((node) = 0); \ {insert;} \ switch (low_rb_ins_type_) { \ case 1: low_rb_link_at_next ((tree), rbstack, (node)); break; \ case 2: low_rb_link_at_prev ((tree), rbstack, (node)); break; \ case 3: low_rb_init_root (*(tree) = (node)); break; \ } \ } \ } while (0)
-
/* Used when unlinking nodes. Since an interior node can't be unlinked
-
* we need to move over the data from a leaf node and unlink that
-
* instead. */
-
typedef void low_rb_move_data_fn (struct rb_node_hdr *to,
-
struct rb_node_hdr *from);
+
typedef struct rb_node_hdr *low_rb_copy_fn (struct rb_node_hdr *node); typedef void low_rb_free_fn (struct rb_node_hdr *node); void low_rb_init_root (struct rb_node_hdr *new_root); void low_rb_link_at_prev (struct rb_node_hdr **tree, struct rbstack_ptr rbstack, struct rb_node_hdr *new); void low_rb_link_at_next (struct rb_node_hdr **tree, struct rbstack_ptr rbstack, struct rb_node_hdr *new); struct rb_node_hdr *low_rb_unlink (struct rb_node_hdr **tree, struct rbstack_ptr rbstack,
-
low_rb_move_
data
_
fn
*
move
_
data
);
+
size_t node_size);
+
void
low_rb_
unlink_without_
move
(struct rb
_
node
_
hdr
*
*tree,
+
struct rbstack
_
ptr rbstack
);
struct rb_node_hdr *low_rb_insert (struct rb_node_hdr **tree, low_rb_cmp_fn *cmp_fn, void *key, struct rb_node_hdr *new); void low_rb_add (struct rb_node_hdr **tree, low_rb_cmp_fn *cmp_fn, void *key, struct rb_node_hdr *new); void low_rb_add_after (struct rb_node_hdr **tree, low_rb_cmp_fn *cmp_fn, void *key, struct rb_node_hdr *new, struct rb_node_hdr *existing); struct rb_node_hdr *low_rb_delete (struct rb_node_hdr **tree, low_rb_cmp_fn *cmp_fn, void *key,
-
low
_
rb_move_data_fn
*move
_
data_fn
);
+
size
_
t
node
_
size
);
struct rb_node_hdr *low_rb_delete_node (struct rb_node_hdr **tree, low_rb_cmp_fn *cmp_fn, void *key,
-
low_rb_move_
data
_fn *move_
data
_fn,
+
struct rb_node_hdr *node,
+
size_t node_size);
+
struct rb_node_hdr *
low_rb_
delete_without_
move
(struct rb
_
node
_
hdr **tree,
+
low_rb_cmp_
fn *
cmp_fn, void *key);
+
void low_rb_delete_node_without_
move
(struct rb
_
node
_
hdr **tree,
+
low_rb_cmp_
fn
*cmp_fn
,
void *key,
struct rb_node_hdr *node); struct rb_node_hdr *low_rb_copy (struct rb_node_hdr *tree, low_rb_copy_fn *copy_node_fn); void low_rb_free (struct rb_node_hdr *tree, low_rb_free_fn *free_node_fn); struct rb_node_hdr *low_rb_find_eq (struct rb_node_hdr *tree, low_rb_cmp_fn *cmp_fn, void *key); struct rb_node_hdr *low_rb_find_lt (struct rb_node_hdr *tree, low_rb_cmp_fn *cmp_fn, void *key); struct rb_node_hdr *low_rb_find_gt (struct rb_node_hdr *tree,