~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_tree.h

  • Committer: Monty Taylor
  • Date: 2009-09-22 23:50:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20090922235012-i0a3bs91f6krqduc
Fixed multi_malloc.h include guard.
Added include guard checking script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
16
#ifndef MYSYS_MY_TREE_H
 
17
#define MYSYS_MY_TREE_H
 
18
 
 
19
#ifdef  __cplusplus
 
20
extern "C" {
 
21
#endif
 
22
 
 
23
#include <drizzled/base.h>              /* get 'enum ha_rkey_function' */
 
24
#include <mysys/my_sys.h>
 
25
 
 
26
/* Worst case tree is half full. This gives use 2^(MAX_TREE_HEIGHT/2) leafs */
 
27
#define MAX_TREE_HEIGHT 64
 
28
 
 
29
#define ELEMENT_KEY(tree,element)\
 
30
(tree->offset_to_key ? (void*)((unsigned char*) element+tree->offset_to_key) :\
 
31
                        *((void**) (element+1)))
 
32
 
 
33
#define tree_set_pointer(element,ptr) *((unsigned char **) (element+1))=((unsigned char*) (ptr))
 
34
 
 
35
#define TREE_NO_DUPS 1
 
36
 
 
37
typedef enum { left_root_right, right_root_left } TREE_WALK;
 
38
typedef uint32_t element_count;
 
39
typedef int (*tree_walk_action)(void *,element_count,void *);
 
40
 
 
41
typedef enum { free_init, free_free, free_end } TREE_FREE;
 
42
typedef void (*tree_element_free)(void*, TREE_FREE, void *);
 
43
 
 
44
typedef struct st_tree_element {
 
45
  struct st_tree_element *left,*right;
 
46
  uint32_t count:31,
 
47
         colour:1;                      /* black is marked as 1 */
 
48
} TREE_ELEMENT;
 
49
 
 
50
#define ELEMENT_CHILD(element, offs) (*(TREE_ELEMENT**)((char*)element + offs))
 
51
 
 
52
typedef struct st_tree {
 
53
  TREE_ELEMENT *root,null_element;
 
54
  TREE_ELEMENT **parents[MAX_TREE_HEIGHT];
 
55
  uint32_t offset_to_key,elements_in_tree,size_of_element;
 
56
  uint32_t memory_limit, allocated;
 
57
  qsort_cmp2 compare;
 
58
  void *custom_arg;
 
59
  MEM_ROOT mem_root;
 
60
  bool with_delete;
 
61
  tree_element_free free;
 
62
  uint32_t flag;
 
63
} TREE;
 
64
 
 
65
        /* Functions on whole tree */
 
66
void init_tree(TREE *tree, uint32_t default_alloc_size, uint32_t memory_limit,
 
67
               int size, qsort_cmp2 compare, bool with_delete,
 
68
               tree_element_free free_element, void *custom_arg);
 
69
void delete_tree(TREE*);
 
70
void reset_tree(TREE*);
 
71
  /* similar to delete tree, except we do not free() blocks in mem_root
 
72
   */
 
73
#define is_tree_inited(tree) ((tree)->root != 0)
 
74
 
 
75
        /* Functions on leafs */
 
76
TREE_ELEMENT *tree_insert(TREE *tree,void *key, uint32_t key_size,
 
77
                          void *custom_arg);
 
78
void *tree_search(TREE *tree, void *key, void *custom_arg);
 
79
int tree_walk(TREE *tree,tree_walk_action action,
 
80
              void *argument, TREE_WALK visit);
 
81
int tree_delete(TREE *tree, void *key, uint32_t key_size, void *custom_arg);
 
82
void *tree_search_key(TREE *tree, const void *key,
 
83
                      TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos,
 
84
                      enum ha_rkey_function flag, void *custom_arg);
 
85
void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents,
 
86
                        TREE_ELEMENT ***last_pos, int child_offs);
 
87
void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs,
 
88
                       int r_offs);
 
89
ha_rows tree_record_pos(TREE *tree, const void *key,
 
90
                     enum ha_rkey_function search_flag, void *custom_arg);
 
91
 
 
92
#define TREE_ELEMENT_EXTRA_SIZE (sizeof(TREE_ELEMENT) + sizeof(void*))
 
93
 
 
94
#ifdef  __cplusplus
 
95
}
 
96
#endif
 
97
 
 
98
#endif /* MYSYS_MY_TREE_H */