Eneboo - Documentación para desarrolladores
src/libmysql_std/include/my_tree.h
Ir a la documentación de este archivo.
00001 /* Copyright (C) 2000 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00015 
00016 #ifndef _tree_h
00017 #define _tree_h
00018 #ifdef  __cplusplus
00019 extern "C" {
00020 #endif
00021 
00022 #include "my_base.h"            /* get 'enum ha_rkey_function' */
00023 
00024 /* Worst case tree is half full. This gives use 2^(MAX_TREE_HEIGHT/2) leafs */
00025 #define MAX_TREE_HEIGHT 64
00026 
00027 #define ELEMENT_KEY(tree,element)\
00028 (tree->offset_to_key ? (void*)((byte*) element+tree->offset_to_key) :\
00029                         *((void**) (element+1)))
00030 
00031 #define tree_set_pointer(element,ptr) *((byte **) (element+1))=((byte*) (ptr))
00032 
00033 #define TREE_NO_DUPS 1
00034 
00035 typedef enum { left_root_right, right_root_left } TREE_WALK;
00036 typedef uint32 element_count;
00037 typedef int (*tree_walk_action)(void *,element_count,void *);
00038 
00039 typedef enum { free_init, free_free, free_end } TREE_FREE;
00040 typedef void (*tree_element_free)(void*, TREE_FREE, void *);
00041 
00042 #ifdef MSDOS
00043 typedef struct st_tree_element {
00044   struct st_tree_element *left,*right;
00045   unsigned long count;
00046   uchar    colour;                      /* black is marked as 1 */
00047 } TREE_ELEMENT;
00048 #else
00049 typedef struct st_tree_element {
00050   struct st_tree_element *left,*right;
00051   uint32 count:31,
00052          colour:1;                      /* black is marked as 1 */
00053 } TREE_ELEMENT;
00054 #endif /* MSDOS */
00055 
00056 #define ELEMENT_CHILD(element, offs) (*(TREE_ELEMENT**)((char*)element + offs))
00057 
00058 typedef struct st_tree {
00059   TREE_ELEMENT *root,null_element;
00060   TREE_ELEMENT **parents[MAX_TREE_HEIGHT];
00061   uint offset_to_key,elements_in_tree,size_of_element;
00062   ulong memory_limit, allocated;
00063   qsort_cmp2 compare;
00064   void *custom_arg;
00065   MEM_ROOT mem_root;
00066   my_bool with_delete;
00067   tree_element_free free;
00068   uint flag;
00069 } TREE;
00070 
00071         /* Functions on whole tree */
00072 void init_tree(TREE *tree, ulong default_alloc_size, ulong memory_limit,
00073                int size, qsort_cmp2 compare, my_bool with_delete,
00074                tree_element_free free_element, void *custom_arg);
00075 void delete_tree(TREE*);
00076 void reset_tree(TREE*);
00077   /* similar to delete tree, except we do not my_free() blocks in mem_root
00078    */
00079 #define is_tree_inited(tree) ((tree)->root != 0)
00080 
00081         /* Functions on leafs */
00082 TREE_ELEMENT *tree_insert(TREE *tree,void *key, uint key_size, 
00083                           void *custom_arg);
00084 void *tree_search(TREE *tree, void *key, void *custom_arg);
00085 int tree_walk(TREE *tree,tree_walk_action action,
00086               void *argument, TREE_WALK visit);
00087 int tree_delete(TREE *tree, void *key, uint key_size, void *custom_arg);
00088 void *tree_search_key(TREE *tree, const void *key, 
00089                       TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos,
00090                       enum ha_rkey_function flag, void *custom_arg);
00091 void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents, 
00092                         TREE_ELEMENT ***last_pos, int child_offs);
00093 void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs, 
00094                        int r_offs);
00095 ha_rows tree_record_pos(TREE *tree, const void *key, 
00096                      enum ha_rkey_function search_flag, void *custom_arg);
00097 
00098 #define TREE_ELEMENT_EXTRA_SIZE (sizeof(TREE_ELEMENT) + sizeof(void*))
00099 
00100 #ifdef  __cplusplus
00101 }
00102 #endif
00103 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'