1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
1241.9.56
by Monty Taylor
More mysys cleaning. |
16 |
#ifndef DRIZZLED_MY_TREE_H
|
17 |
#define DRIZZLED_MY_TREE_H
|
|
18 |
||
19 |
#include <unistd.h> |
|
20 |
||
21 |
#include "drizzled/base.h" /* get 'enum ha_rkey_function' */ |
|
1241.9.45
by Monty Taylor
Added a header for qsort_cmp. |
22 |
#include "drizzled/qsort_cmp.h" |
1241.9.56
by Monty Taylor
More mysys cleaning. |
23 |
#include "drizzled/memory/root.h" |
1241.9.45
by Monty Taylor
Added a header for qsort_cmp. |
24 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
25 |
namespace drizzled |
26 |
{
|
|
1
by brian
clean slate |
27 |
|
28 |
/* Worst case tree is half full. This gives use 2^(MAX_TREE_HEIGHT/2) leafs */
|
|
1241.9.56
by Monty Taylor
More mysys cleaning. |
29 |
static const int MAX_TREE_HEIGHT= 64; |
30 |
||
31 |
static const int TREE_NO_DUPS= 1; |
|
1
by brian
clean slate |
32 |
|
33 |
typedef enum { left_root_right, right_root_left } TREE_WALK; |
|
1241.9.46
by Monty Taylor
Removed some more evil. |
34 |
typedef int (*tree_walk_action)(void *,uint32_t,void *); |
1
by brian
clean slate |
35 |
|
36 |
typedef enum { free_init, free_free, free_end } TREE_FREE; |
|
37 |
typedef void (*tree_element_free)(void*, TREE_FREE, void *); |
|
38 |
||
39 |
typedef struct st_tree_element { |
|
40 |
struct st_tree_element *left,*right; |
|
205
by Brian Aker
uint32 -> uin32_t |
41 |
uint32_t count:31, |
1
by brian
clean slate |
42 |
colour:1; /* black is marked as 1 */ |
43 |
} TREE_ELEMENT; |
|
44 |
||
1241.9.56
by Monty Taylor
More mysys cleaning. |
45 |
static const int TREE_ELEMENT_EXTRA_SIZE= (sizeof(TREE_ELEMENT) + sizeof(void*)); |
46 |
||
1
by brian
clean slate |
47 |
|
48 |
typedef struct st_tree { |
|
49 |
TREE_ELEMENT *root,null_element; |
|
50 |
TREE_ELEMENT **parents[MAX_TREE_HEIGHT]; |
|
1164
by Brian Aker
Small cleanup. |
51 |
uint32_t offset_to_key, elements_in_tree, size_of_element; |
52 |
size_t memory_limit; |
|
53 |
size_t allocated; |
|
1
by brian
clean slate |
54 |
qsort_cmp2 compare; |
55 |
void *custom_arg; |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
56 |
memory::Root mem_root; |
146
by Brian Aker
my_bool cleanup. |
57 |
bool with_delete; |
1
by brian
clean slate |
58 |
tree_element_free free; |
482
by Brian Aker
Remove uint. |
59 |
uint32_t flag; |
1
by brian
clean slate |
60 |
} TREE; |
61 |
||
1164
by Brian Aker
Small cleanup. |
62 |
/* Functions on whole tree */
|
1238.1.3
by Brian Aker
ICC fixes/fix for solaris. |
63 |
void init_tree(TREE *tree, size_t default_alloc_size, uint32_t memory_limit, |
1164
by Brian Aker
Small cleanup. |
64 |
uint32_t size, qsort_cmp2 compare, bool with_delete, |
1
by brian
clean slate |
65 |
tree_element_free free_element, void *custom_arg); |
66 |
void delete_tree(TREE*); |
|
67 |
void reset_tree(TREE*); |
|
1164
by Brian Aker
Small cleanup. |
68 |
|
69 |
/*
|
|
70 |
similar to delete tree, except we do not free() blocks in mem_root
|
|
71 |
*/
|
|
1
by brian
clean slate |
72 |
#define is_tree_inited(tree) ((tree)->root != 0)
|
73 |
||
1164
by Brian Aker
Small cleanup. |
74 |
/* Functions on leafs */
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
75 |
TREE_ELEMENT *tree_insert(TREE *tree,void *key, uint32_t key_size, |
1
by brian
clean slate |
76 |
void *custom_arg); |
77 |
int tree_walk(TREE *tree,tree_walk_action action, |
|
78 |
void *argument, TREE_WALK visit); |
|
482
by Brian Aker
Remove uint. |
79 |
int tree_delete(TREE *tree, void *key, uint32_t key_size, void *custom_arg); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
80 |
void *tree_search_key(TREE *tree, const void *key, |
1
by brian
clean slate |
81 |
TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos, |
82 |
enum ha_rkey_function flag, void *custom_arg); |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
83 |
void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents, |
1
by brian
clean slate |
84 |
TREE_ELEMENT ***last_pos, int child_offs); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
85 |
void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs, |
1
by brian
clean slate |
86 |
int r_offs); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
87 |
ha_rows tree_record_pos(TREE *tree, const void *key, |
1164
by Brian Aker
Small cleanup. |
88 |
enum ha_rkey_function search_flag, void *custom_arg); |
1
by brian
clean slate |
89 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
90 |
} /* namespace drizzled */ |
1122.2.10
by Monty Taylor
Fixed all of the include guards. |
91 |
|
1241.9.56
by Monty Taylor
More mysys cleaning. |
92 |
#endif /* DRIZZLED_MY_TREE_H */ |