35
35
typedef enum { free_init, free_free, free_end } TREE_FREE;
36
36
typedef void (*tree_element_free)(void*, TREE_FREE, void *);
38
typedef struct st_tree_element {
39
struct st_tree_element *left,*right;
41
colour:1; /* black is marked as 1 */
44
static const int TREE_ELEMENT_EXTRA_SIZE= (sizeof(TREE_ELEMENT) + sizeof(void*));
47
typedef struct st_tree {
48
TREE_ELEMENT *root,null_element;
49
TREE_ELEMENT **parents[MAX_TREE_HEIGHT];
50
uint32_t offset_to_key, elements_in_tree, size_of_element;
55
memory::Root mem_root;
57
tree_element_free free;
61
/* Functions on whole tree */
62
void init_tree(TREE *tree, size_t default_alloc_size, uint32_t memory_limit,
63
uint32_t size, qsort_cmp2 compare, bool with_delete,
64
tree_element_free free_element, void *custom_arg);
65
void delete_tree(TREE*);
66
void reset_tree(TREE*);
69
similar to delete tree, except we do not free() blocks in mem_root
71
#define is_tree_inited(tree) ((tree)->root != 0)
73
/* Functions on leafs */
74
TREE_ELEMENT *tree_insert(TREE *tree,void *key, uint32_t key_size,
76
int tree_walk(TREE *tree,tree_walk_action action,
77
void *argument, TREE_WALK visit);
78
int tree_delete(TREE *tree, void *key, uint32_t key_size, void *custom_arg);
79
void *tree_search_key(TREE *tree, const void *key,
80
TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos,
81
enum ha_rkey_function flag, void *custom_arg);
82
void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents,
83
TREE_ELEMENT ***last_pos, int child_offs);
84
void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs,
86
ha_rows tree_record_pos(TREE *tree, const void *key,
87
enum ha_rkey_function search_flag, void *custom_arg);
42
Tree_Element *left,*right;
44
colour:1; /* black is marked as 1 */
47
static const int TREE_ELEMENT_EXTRA_SIZE= (sizeof(Tree_Element) + sizeof(void*));
50
* red-black binary tree class
52
* NOTE: unused search code removed 11/2011
57
Tree_Element *root, null_element;
59
Tree_Element **parents[MAX_TREE_HEIGHT];
60
uint32_t offset_to_key, elements_in_tree, size_of_element;
64
memory::Root mem_root;
66
tree_element_free free;
70
void* getCustomArg() {
73
Tree_Element* getRoot() {
76
void setRoot(Tree_Element* root_arg) {
79
uint32_t getElementsInTree() {
80
return elements_in_tree;
83
void init_tree(size_t default_alloc_size, uint32_t memory_limit,
84
uint32_t size, qsort_cmp2 compare, bool with_delete,
85
tree_element_free free_element, void *custom_arg);
88
return this->root != 0;
94
Tree_Element *tree_insert(void *key, uint32_t key_size, void *custom_arg);
95
int tree_walk(tree_walk_action action, void *argument, TREE_WALK visit);
98
void free_tree(myf free_flags);
100
void* element_key(Tree_Element* element);
101
void delete_tree_element(Tree_Element* element);
102
int tree_walk_left_root_right(Tree_Element* element, tree_walk_action action, void* argument);
103
int tree_walk_right_root_left(Tree_Element* element, tree_walk_action action, void* argument);
105
void left_rotate(Tree_Element **parent,Tree_Element *element);
106
void right_rotate(Tree_Element **parent, Tree_Element *element);
107
void rb_insert(Tree_Element ***parent, Tree_Element *element);
89
110
} /* namespace drizzled */