42#ifdef ONLY_FOR_DOXYGEN
50#ifndef RBT_TRAVERSE_H_PREFIX_
51#define RBT_TRAVERSE_H_PREFIX_ RBT_NODE_H_PREFIX_
54#undef RBT_NODE_TRAVERSE_WITH_KEY
55#define RBT_NODE_TRAVERSE_WITH_KEY RBT_TOKEN_2_W(RBT_TRAVERSE_H_PREFIX_, node_traverse_with_key)
57#undef RBT_NODE_FILTER_WITH_KEY
58#define RBT_NODE_FILTER_WITH_KEY RBT_TOKEN_2_W(RBT_TRAVERSE_H_PREFIX_, node_filter_with_key)
91#ifndef RBT_RESIZE_TO_FIT_KEY
92#define RBT_RESIZE_TO_FIT_KEY(current_size, required_size, fail) \
95 current_size = required_size * 2; \
96 if (current_size < required_size) \
99 if (current_size < required_size) \
146 RBT_KEY_SIZE_T size, pins, bytes, tmp, height;
169#ifdef RBT_KEY_SIZE_FIXED
171 key_data.
key = (RBT_PIN_T *) key;
172 size = RBT_KEY_SIZE_FIXED;
180 key_data.
node = node;
187 tmp = key_data.
bytes + bytes;
188#ifndef RBT_KEY_SIZE_FIXED
192 key_data.
key = realloc(key_data.
key, size);
193 if (key_data.
key == NULL)
200 memcpy(((uint8_t *) key_data.
key) + key_data.
bytes, node->
key, bytes);
201 key_data.
bytes += bytes;
209 va_start(func_args, func_v);
210 if (func_v(&key_data, height, func_args) || errno)
217 if (node->
right == NULL)
219 if (node->
left == NULL)
230 _RBT_NODE_STACK_POP(stack, stack_tmp, stack_unused);
240 else if (node->
left == NULL)
255#ifndef RBT_KEY_SIZE_FIXED
257 if (key_data.
key != NULL)
262 _RBT_NODE_STACK_FREE(stack, stack_tmp, stack_unused);
332 int rc, unwanted, is_left, placeholder;
335 RBT_KEY_SIZE_T size, pins, bytes, tmp;
336 _RBT_NODE_FILTER_WITH_KEY_STACK_T * stack, * stack_tmp, * stack_unused;
351 parent_stack_unused = NULL;
359#ifdef RBT_KEY_SIZE_FIXED
361 key_data.
key = (RBT_PIN_T *) key;
362 size = RBT_KEY_SIZE_FIXED;
370 key_data.
node = node;
377 tmp = key_data.
bytes + bytes;
378#ifndef RBT_KEY_SIZE_FIXED
382 key_data.
key = realloc(key_data.
key, size);
383 if (key_data.
key == NULL)
390 memcpy(((uint8_t *) key_data.
key) + key_data.
bytes, node->
key, bytes);
391 key_data.
bytes += bytes;
401 if (parent_stack != NULL)
403 debug_printf(
"filtering node: %p (parent: %p)\n", node, parent_stack->
node);
411 va_start(func_args, include_empty);
416 unwanted = func_v(&key_data, func_args);
425 if (parent_stack != NULL)
427 is_left = parent_stack->
node->
left == node;
433 placeholder = (node->
left != NULL) && (node->
right != NULL);
436 sibling_node = parent_stack->
node->
right;
440 sibling_node = parent_stack->
node->
left;
452 if (tmp_node != node)
459 if (parent_stack->
node->
right == sibling_node)
462 key_data.
bytes -= bytes;
469 node = parent_stack->
node;
470 _RBT_NODE_STACK_POP(parent_stack, parent_stack_tmp, parent_stack_unused);
471 if (stack != NULL && stack->parent_stack->node == node)
473 _RBT_NODE_STACK_POP(stack, stack_tmp, stack_unused);
477 key_data.
bytes = stack->bytes_in_key_prefix;
495 key_data.
bytes = stack->bytes_in_key_prefix;
496 while (parent_stack != NULL && parent_stack != stack->parent_stack)
498 _RBT_NODE_STACK_POP(parent_stack, parent_stack_tmp, parent_stack_unused);
500 _RBT_NODE_STACK_POP(stack, stack_tmp, stack_unused);
530 if (node->
left != NULL)
532 _RBT_NODE_STACK_ALLOCATE(parent_stack, parent_stack_tmp, parent_stack_unused,
RBT_NODE_STACK_T);
533 parent_stack->
node = node;
534 if (node->
right != NULL)
536 _RBT_NODE_STACK_ALLOCATE(stack, stack_tmp, stack_unused, _RBT_NODE_FILTER_WITH_KEY_STACK_T);
537 stack->node = node->
right;
538 stack->bytes_in_key_prefix = key_data.
bytes;
539 stack->parent_stack = parent_stack;
544 else if (node->
right != NULL)
546 _RBT_NODE_STACK_ALLOCATE(parent_stack, parent_stack_tmp, parent_stack_unused,
RBT_NODE_STACK_T);
547 parent_stack->
node = node;
555 key_data.
bytes = stack->bytes_in_key_prefix;
556 while (parent_stack != NULL && parent_stack != stack->parent_stack)
558 _RBT_NODE_STACK_POP(parent_stack, parent_stack_tmp, parent_stack_unused);
560 _RBT_NODE_STACK_POP(stack, stack_tmp, stack_unused);
567#ifndef RBT_KEY_SIZE_FIXED
569 if (key_data.
key != NULL)
574 _RBT_NODE_STACK_FREE(parent_stack, parent_stack_tmp, parent_stack_unused);
575 _RBT_NODE_STACK_FREE(stack, stack_tmp, stack_unused);
#define debug_printf(fmt,...)
Definition: debug.h:138
#define RBT_DIVMOD(a, b, c, d)
Definition: key.h:224
#define RBT_PIN_SIZE
Definition: key.h:128
#define RBT_PIN_SIZE_BITS
Definition: key.h:133
#define RBT_VALUE_IS_NULL(value)
Definition: node.h:395
int(* RBT_NODE_TRAVERSE_WITH_KEY_FUNCTION_T)(RBT_KEY_DATA_T *key_data, RBT_KEY_SIZE_T height, va_list args)
A tree traversal function.
Definition: node.h:3335
int(* RBT_NODE_FILTER_WITH_KEY_FUNCTION_T)(RBT_KEY_DATA_T *key_data, va_list args)
The function type accepted by RBT_NODE_FILTER_WITH_KEY().
Definition: node.h:3302
RBT_NODE_T * RBT_NODE_REMOVE(RBT_NODE_T *node, RBT_NODE_T *parent_node)
Remove a node from a tree.
Definition: node.h:1379
Rabbit Tree key data type with associated node.
Definition: node.h:478
RBT_KEY_SIZE_T bits
Number of significant bits in the key.
Definition: node.h:492
RBT_PIN_T * key
The key.
Definition: node.h:486
RBT_KEY_SIZE_T bytes
Number of significant bits in the key.
Definition: node.h:502
RBT_NODE_T * node
The associated node.
Definition: node.h:508
Linked list of nodes.
Definition: node.h:617
RBT_NODE_T * node
Definition: node.h:621
Rabbit Tree node type.
Definition: node.h:420
struct RBT_NODE_T * right
Right child node.
Definition: node.h:462
RBT_KEY_SIZE_T bits
Number of significant bits in the key.
Definition: node.h:438
struct RBT_NODE_T * left
Left child node.
Definition: node.h:454
RBT_VALUE_T value
Value associated with the node.
Definition: node.h:446
RBT_PIN_T * key
Key segment associated with this node.
Definition: node.h:428
Linked list for implementing RBT_NODE_TRAVERSE_WITH_KEY's dynamic stack.
Definition: node.h:3255
RBT_KEY_SIZE_T bytes_in_key_prefix
The number of bytes in the key prefix for this node.
Definition: node.h:3266
RBT_KEY_SIZE_T height
The height of the node above the root node (or the depth, depending on how you look at it).
Definition: node.h:3273
RBT_NODE_T * node
The node on the stack.
Definition: node.h:3260
#define RBT_RESIZE_TO_FIT_KEY(current_size, required_size, fail)
Definition: traverse_with_key.h:92
void RBT_NODE_TRAVERSE_WITH_KEY(RBT_NODE_T *node, RBT_NODE_TRAVERSE_WITH_KEY_FUNCTION_T func_v,...)
Definition: traverse_with_key.h:138
void RBT_NODE_FILTER_WITH_KEY(RBT_NODE_T *node, RBT_NODE_FILTER_WITH_KEY_FUNCTION_T func_v, int include_empty,...)
Filter tree nodes.
Definition: traverse_with_key.h:325