Eneboo - Documentación para desarrolladores
|
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 /* Dynamic hashing of record with different key-length */ 00017 00018 #ifndef _hash_h 00019 #define _hash_h 00020 #ifdef __cplusplus 00021 extern "C" { 00022 #endif 00023 00024 /* 00025 Overhead to store an element in hash 00026 Can be used to approximate memory consumption for a hash 00027 */ 00028 #define HASH_OVERHEAD (sizeof(char*)*2) 00029 00030 typedef byte *(*hash_get_key)(const byte *,uint*,my_bool); 00031 typedef void (*hash_free_key)(void *); 00032 00033 typedef struct st_hash { 00034 uint key_offset,key_length; /* Length of key if const length */ 00035 uint records, blength; 00036 uint flags; 00037 DYNAMIC_ARRAY array; /* Place for hash_keys */ 00038 hash_get_key get_key; 00039 void (*free)(void *); 00040 CHARSET_INFO *charset; 00041 } HASH; 00042 00043 /* A search iterator state */ 00044 typedef uint HASH_SEARCH_STATE; 00045 00046 #define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,B,C,D,E,F,G, H CALLER_INFO) 00047 my_bool _hash_init(HASH *hash, CHARSET_INFO *charset, 00048 uint default_array_elements, uint key_offset, 00049 uint key_length, hash_get_key get_key, 00050 void (*free_element)(void*), uint flags CALLER_INFO_PROTO); 00051 void hash_free(HASH *tree); 00052 void my_hash_reset(HASH *hash); 00053 byte *hash_element(HASH *hash,uint idx); 00054 gptr hash_search(const HASH *info, const byte *key, uint length); 00055 gptr hash_first(const HASH *info, const byte *key, uint length, 00056 HASH_SEARCH_STATE *state); 00057 gptr hash_next(const HASH *info, const byte *key, uint length, 00058 HASH_SEARCH_STATE *state); 00059 my_bool my_hash_insert(HASH *info,const byte *data); 00060 my_bool hash_delete(HASH *hash,byte *record); 00061 my_bool hash_update(HASH *hash,byte *record,byte *old_key,uint old_key_length); 00062 void hash_replace(HASH *hash, HASH_SEARCH_STATE *state, byte *new_row); 00063 my_bool hash_check(HASH *hash); /* Only in debug library */ 00064 00065 #define hash_clear(H) bzero((char*) (H),sizeof(*(H))) 00066 #define hash_inited(H) ((H)->array.buffer != 0) 00067 #define hash_init_opt(A,B,C,D,E,F,G,H) \ 00068 (!hash_inited(A) && _hash_init(A,B,C,D,E,F,G, H CALLER_INFO)) 00069 00070 #ifdef __cplusplus 00071 } 00072 #endif 00073 #endif