~drizzle-trunk/drizzle/development

1410.4.2 by Djellel E. Difallah
removing my
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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1410.4.2 by Djellel E. Difallah
removing my
15
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
16
#pragma once
1410.4.2 by Djellel E. Difallah
removing my
17
18
#include <unistd.h>
19
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <drizzled/base.h>		/* get 'enum ha_rkey_function' */
21
#include <drizzled/qsort_cmp.h>
22
#include <drizzled/memory/root.h>
1410.4.2 by Djellel E. Difallah
removing my
23
24
namespace drizzled
25
{
26
27
/* Worst case tree is half full. This gives use 2^(MAX_TREE_HEIGHT/2) leafs */
28
static const int MAX_TREE_HEIGHT= 64;
29
30
static const int TREE_NO_DUPS= 1;
31
32
typedef enum { left_root_right, right_root_left } TREE_WALK;
33
typedef int (*tree_walk_action)(void *,uint32_t,void *);
34
35
typedef enum { free_init, free_free, free_end } TREE_FREE;
36
typedef void (*tree_element_free)(void*, TREE_FREE, void *);
37
38
typedef struct st_tree_element {
39
  struct st_tree_element *left,*right;
40
  uint32_t count:31,
41
	 colour:1;			/* black is marked as 1 */
42
} TREE_ELEMENT;
43
44
static const int TREE_ELEMENT_EXTRA_SIZE= (sizeof(TREE_ELEMENT) + sizeof(void*));
45
46
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;
51
  size_t memory_limit;
52
  size_t allocated;
53
  qsort_cmp2 compare;
54
  void *custom_arg;
55
  memory::Root mem_root;
56
  bool with_delete;
57
  tree_element_free free;
58
  uint32_t flag;
59
} TREE;
60
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*);
67
68
/* 
69
  similar to delete tree, except we do not free() blocks in mem_root
70
*/
71
#define is_tree_inited(tree) ((tree)->root != 0)
72
73
/* Functions on leafs */
74
TREE_ELEMENT *tree_insert(TREE *tree,void *key, uint32_t key_size,
75
                          void *custom_arg);
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,
85
                       int r_offs);
86
ha_rows tree_record_pos(TREE *tree, const void *key,
87
                        enum ha_rkey_function search_flag, void *custom_arg);
88
89
} /* namespace drizzled */
90