Eneboo - Documentación para desarrolladores
src/libmysql_macosx/include/heap.h
Ir a la documentación de este archivo.
00001 /* Copyright (C) 2000,2004 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; either version 2 of the License, or
00006    (at your option) any later version.
00007 
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011    GNU General Public License for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; if not, write to the Free Software
00015    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00016 
00017 /* This file should be included when using heap_database_functions */
00018 /* Author: Michael Widenius */
00019 
00020 #ifndef _heap_h
00021 #define _heap_h
00022 #ifdef  __cplusplus
00023 extern "C" {
00024 #endif
00025 
00026 #ifndef _my_base_h
00027 #include <my_base.h>
00028 #endif
00029 #ifdef THREAD
00030 #include <my_pthread.h>
00031 #include <thr_lock.h>
00032 #endif
00033 
00034 #include "my_handler.h"
00035 #include "my_tree.h"
00036 
00037         /* defines used by heap-funktions */
00038 
00039 #define HP_MAX_LEVELS   4               /* 128^5 records is enough */
00040 #define HP_PTRS_IN_NOD  128
00041 
00042         /* struct used with heap_funktions */
00043 
00044 typedef struct st_heapinfo              /* Struct from heap_info */
00045 {
00046   ulong records;                        /* Records in database */
00047   ulong deleted;                        /* Deleted records in database */
00048   ulong max_records;
00049   ulong data_length;
00050   ulong index_length;
00051   uint reclength;                       /* Length of one record */
00052   int errkey;
00053   ulonglong auto_increment;
00054 } HEAPINFO;
00055 
00056 
00057         /* Structs used by heap-database-handler */
00058 
00059 typedef struct st_heap_ptrs
00060 {
00061   byte *blocks[HP_PTRS_IN_NOD];         /* pointers to HP_PTRS or records */
00062 } HP_PTRS;
00063 
00064 struct st_level_info
00065 {
00066   /* Number of unused slots in *last_blocks HP_PTRS block (0 for 0th level) */
00067   uint free_ptrs_in_block;
00068   
00069   /*
00070     Maximum number of records that can be 'contained' inside of each element
00071     of last_blocks array. For level 0 - 1, for level 1 - HP_PTRS_IN_NOD, for 
00072     level 2 - HP_PTRS_IN_NOD^2 and so forth.
00073   */
00074   uint records_under_level;
00075 
00076   /*
00077     Ptr to last allocated HP_PTRS (or records buffer for level 0) on this 
00078     level.
00079   */
00080   HP_PTRS *last_blocks;                 
00081 };
00082 
00083 
00084 /*
00085   Heap table records and hash index entries are stored in HP_BLOCKs.
00086   HP_BLOCK is used as a 'growable array' of fixed-size records. Size of record
00087   is recbuffer bytes.
00088   The internal representation is as follows:
00089   HP_BLOCK is a hierarchical structure of 'blocks'.
00090   A block at level 0 is an array records_in_block records. 
00091   A block at higher level is an HP_PTRS structure with pointers to blocks at 
00092   lower levels.
00093   At the highest level there is one top block. It is stored in HP_BLOCK::root.
00094 
00095   See hp_find_block for a description of how record pointer is obtained from 
00096   its index.
00097   See hp_get_new_block 
00098 */
00099 
00100 typedef struct st_heap_block
00101 {
00102   HP_PTRS *root;                        /* Top-level block */ 
00103   struct st_level_info level_info[HP_MAX_LEVELS+1];
00104   uint levels;                          /* number of used levels */
00105   uint records_in_block;                /* Records in one heap-block */
00106   uint recbuffer;                       /* Length of one saved record */
00107   ulong last_allocated; /* number of records there is allocated space for */
00108 } HP_BLOCK;
00109 
00110 struct st_heap_info;                    /* For referense */
00111 
00112 typedef struct st_hp_keydef             /* Key definition with open */
00113 {
00114   uint flag;                            /* HA_NOSAME |HA_NULL_PART_KEY */
00115   uint keysegs;                         /* Number of key-segment */
00116   uint length;                          /* Length of key (automatic) */
00117   uint8 algorithm;                      /* HASH / BTREE */
00118   HA_KEYSEG *seg;
00119   HP_BLOCK block;                       /* Where keys are saved */
00120   /*
00121     Number of buckets used in hash table. Used only to provide
00122     #records estimates for heap key scans.
00123   */
00124   ha_rows hash_buckets; 
00125   TREE rb_tree;
00126   int (*write_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
00127                    const byte *record, byte *recpos);
00128   int (*delete_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
00129                    const byte *record, byte *recpos, int flag);
00130   uint (*get_key_length)(struct st_hp_keydef *keydef, const byte *key);
00131 } HP_KEYDEF;
00132 
00133 typedef struct st_heap_share
00134 {
00135   HP_BLOCK block;
00136   HP_KEYDEF  *keydef;
00137   ulong min_records,max_records;        /* Params to open */
00138   ulong data_length,index_length,max_table_size;
00139   uint records;                         /* records */
00140   uint blength;                         /* records rounded up to 2^n */
00141   uint deleted;                         /* Deleted records in database */
00142   uint reclength;                       /* Length of one record */
00143   uint changed;
00144   uint keys,max_key_length;
00145   uint currently_disabled_keys;    /* saved value from "keys" when disabled */
00146   uint open_count;
00147   byte *del_link;                       /* Link to next block with del. rec */
00148   my_string name;                       /* Name of "memory-file" */
00149 #ifdef THREAD
00150   THR_LOCK lock;
00151   pthread_mutex_t intern_lock;          /* Locking for use with _locking */
00152 #endif
00153   my_bool delete_on_close;
00154   LIST open_list;
00155   uint auto_key;
00156   uint auto_key_type;                   /* real type of the auto key segment */
00157   ulonglong auto_increment;
00158 } HP_SHARE;
00159 
00160 struct st_hp_hash_info;
00161 
00162 typedef struct st_heap_info
00163 {
00164   HP_SHARE *s;
00165   byte *current_ptr;
00166   struct st_hp_hash_info *current_hash_ptr;
00167   ulong current_record,next_block;
00168   int lastinx,errkey;
00169   int  mode;                            /* Mode of file (READONLY..) */
00170   uint opt_flag,update;
00171   byte *lastkey;                        /* Last used key with rkey */
00172   byte *recbuf;                         /* Record buffer for rb-tree keys */
00173   enum ha_rkey_function last_find_flag;
00174   TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1];
00175   TREE_ELEMENT **last_pos;
00176   uint lastkey_len;
00177   my_bool implicit_emptied;
00178 #ifdef THREAD
00179   THR_LOCK_DATA lock;
00180 #endif
00181   LIST open_list;
00182 } HP_INFO;
00183 
00184 
00185 typedef struct st_heap_create_info
00186 {
00187   uint auto_key;                        /* keynr [1 - maxkey] for auto key */
00188   uint auto_key_type;
00189   ulong max_table_size;
00190   ulonglong auto_increment;
00191   my_bool with_auto_increment;
00192 } HP_CREATE_INFO;
00193 
00194         /* Prototypes for heap-functions */
00195 
00196 extern HP_INFO *heap_open(const char *name, int mode);
00197 extern int heap_close(HP_INFO *info);
00198 extern int heap_write(HP_INFO *info,const byte *buff);
00199 extern int heap_update(HP_INFO *info,const byte *old,const byte *newdata);
00200 extern int heap_rrnd(HP_INFO *info,byte *buf,byte *pos);
00201 extern int heap_scan_init(HP_INFO *info);
00202 extern int heap_scan(register HP_INFO *info, byte *record);
00203 extern int heap_delete(HP_INFO *info,const byte *buff);
00204 extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag);
00205 extern int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
00206                        uint reclength, ulong max_records, ulong min_records,
00207                        HP_CREATE_INFO *create_info);
00208 extern int heap_delete_table(const char *name);
00209 extern int heap_extra(HP_INFO *info,enum ha_extra_function function);
00210 extern int heap_rename(const char *old_name,const char *new_name);
00211 extern int heap_panic(enum ha_panic_function flag);
00212 extern int heap_rsame(HP_INFO *info,byte *record,int inx);
00213 extern int heap_rnext(HP_INFO *info,byte *record);
00214 extern int heap_rprev(HP_INFO *info,byte *record);
00215 extern int heap_rfirst(HP_INFO *info,byte *record,int inx);
00216 extern int heap_rlast(HP_INFO *info,byte *record,int inx);
00217 extern void heap_clear(HP_INFO *info);
00218 extern void heap_clear_keys(HP_INFO *info);
00219 extern int heap_disable_indexes(HP_INFO *info);
00220 extern int heap_enable_indexes(HP_INFO *info);
00221 extern int heap_indexes_are_disabled(HP_INFO *info);
00222 extern void heap_update_auto_increment(HP_INFO *info, const byte *record);
00223 ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key,
00224                                key_range *max_key);
00225 int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key, 
00226               uint key_len, enum ha_rkey_function find_flag);
00227 extern gptr heap_find(HP_INFO *info,int inx,const byte *key);
00228 extern int heap_check_heap(HP_INFO *info, my_bool print_status);
00229 extern byte *heap_position(HP_INFO *info);
00230 
00231 /* The following is for programs that uses the old HEAP interface where
00232    pointer to rows where a long instead of a (byte*).
00233 */
00234 
00235 #if defined(WANT_OLD_HEAP_VERSION) || defined(OLD_HEAP_VERSION)
00236 extern int heap_rrnd_old(HP_INFO *info,byte *buf,ulong pos);
00237 extern ulong heap_position_old(HP_INFO *info);
00238 #endif
00239 #ifdef OLD_HEAP_VERSION
00240 typedef ulong HEAP_PTR;
00241 #define heap_position(A) heap_position_old(A)
00242 #define heap_rrnd(A,B,C) heap_rrnd_old(A,B,C)
00243 #else
00244 typedef byte *HEAP_PTR;
00245 #endif
00246 
00247 #ifdef  __cplusplus
00248 }
00249 #endif
00250 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'