13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#ifndef MYSYS_MY_TREE_H
17
#define MYSYS_MY_TREE_H
19
#include <drizzled/base.h> /* get 'enum ha_rkey_function' */
20
#include <mysys/my_sys.h>
21
#include "drizzled/qsort_cmp.h"
22
#include <drizzled/base.h> /* get 'enum ha_rkey_function' */
24
27
/* Worst case tree is half full. This gives use 2^(MAX_TREE_HEIGHT/2) leafs */
25
28
#define MAX_TREE_HEIGHT 64
27
30
#define ELEMENT_KEY(tree,element)\
28
(tree->offset_to_key ? (void*)((uchar*) element+tree->offset_to_key) :\
31
(tree->offset_to_key ? (void*)((unsigned char*) element+tree->offset_to_key) :\
29
32
*((void**) (element+1)))
31
#define tree_set_pointer(element,ptr) *((uchar **) (element+1))=((uchar*) (ptr))
34
#define tree_set_pointer(element,ptr) *((unsigned char **) (element+1))=((unsigned char*) (ptr))
33
36
#define TREE_NO_DUPS 1
35
38
typedef enum { left_root_right, right_root_left } TREE_WALK;
36
typedef uint32_t element_count;
37
typedef int (*tree_walk_action)(void *,element_count,void *);
39
typedef int (*tree_walk_action)(void *,uint32_t,void *);
39
41
typedef enum { free_init, free_free, free_end } TREE_FREE;
40
42
typedef void (*tree_element_free)(void*, TREE_FREE, void *);
50
52
typedef struct st_tree {
51
53
TREE_ELEMENT *root,null_element;
52
54
TREE_ELEMENT **parents[MAX_TREE_HEIGHT];
53
uint offset_to_key,elements_in_tree,size_of_element;
54
uint32_t memory_limit, allocated;
55
uint32_t offset_to_key, elements_in_tree, size_of_element;
55
58
qsort_cmp2 compare;
59
62
tree_element_free free;
63
/* Functions on whole tree */
64
void init_tree(TREE *tree, uint32_t default_alloc_size, uint32_t memory_limit,
65
int size, qsort_cmp2 compare, bool with_delete,
66
/* Functions on whole tree */
67
void init_tree(TREE *tree, size_t default_alloc_size, uint32_t memory_limit,
68
uint32_t size, qsort_cmp2 compare, bool with_delete,
66
69
tree_element_free free_element, void *custom_arg);
67
70
void delete_tree(TREE*);
68
71
void reset_tree(TREE*);
69
/* similar to delete tree, except we do not my_free() blocks in mem_root
74
similar to delete tree, except we do not free() blocks in mem_root
71
76
#define is_tree_inited(tree) ((tree)->root != 0)
73
/* Functions on leafs */
74
TREE_ELEMENT *tree_insert(TREE *tree,void *key, uint key_size,
78
/* Functions on leafs */
79
TREE_ELEMENT *tree_insert(TREE *tree,void *key, uint32_t key_size,
76
void *tree_search(TREE *tree, void *key, void *custom_arg);
77
81
int tree_walk(TREE *tree,tree_walk_action action,
78
82
void *argument, TREE_WALK visit);
79
int tree_delete(TREE *tree, void *key, uint key_size, void *custom_arg);
80
void *tree_search_key(TREE *tree, const void *key,
83
int tree_delete(TREE *tree, void *key, uint32_t key_size, void *custom_arg);
84
void *tree_search_key(TREE *tree, const void *key,
81
85
TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos,
82
86
enum ha_rkey_function flag, void *custom_arg);
83
void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents,
87
void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents,
84
88
TREE_ELEMENT ***last_pos, int child_offs);
85
void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs,
89
void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs,
87
ha_rows tree_record_pos(TREE *tree, const void *key,
88
enum ha_rkey_function search_flag, void *custom_arg);
91
ha_rows tree_record_pos(TREE *tree, const void *key,
92
enum ha_rkey_function search_flag, void *custom_arg);
90
94
#define TREE_ELEMENT_EXTRA_SIZE (sizeof(TREE_ELEMENT) + sizeof(void*))
100
#endif /* MYSYS_MY_TREE_H */