1
/* Copyright (C) 2000 MySQL AB
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; either version 2 of the License, or
6
(at your option) any later version.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
/* Dynamic hashing of record with different key-length */
26
Overhead to store an element in hash
27
Can be used to approximate memory consumption for a hash
29
#define HASH_OVERHEAD (sizeof(char*)*2)
31
typedef byte *(*hash_get_key)(const byte *,uint*,my_bool);
32
typedef void (*hash_free_key)(void *);
34
typedef struct st_hash {
35
uint key_offset,key_length; /* Length of key if const length */
36
uint records, blength;
38
DYNAMIC_ARRAY array; /* Place for hash_keys */
41
CHARSET_INFO *charset;
44
/* A search iterator state */
45
typedef uint HASH_SEARCH_STATE;
47
#define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,B,C,D,E,F,G, H CALLER_INFO)
48
my_bool _hash_init(HASH *hash, CHARSET_INFO *charset,
49
uint default_array_elements, uint key_offset,
50
uint key_length, hash_get_key get_key,
51
void (*free_element)(void*), uint flags CALLER_INFO_PROTO);
52
void hash_free(HASH *tree);
53
void my_hash_reset(HASH *hash);
54
byte *hash_element(HASH *hash,uint idx);
55
gptr hash_search(const HASH *info, const byte *key, uint length);
56
gptr hash_first(const HASH *info, const byte *key, uint length,
57
HASH_SEARCH_STATE *state);
58
gptr hash_next(const HASH *info, const byte *key, uint length,
59
HASH_SEARCH_STATE *state);
60
my_bool my_hash_insert(HASH *info,const byte *data);
61
my_bool hash_delete(HASH *hash,byte *record);
62
my_bool hash_update(HASH *hash,byte *record,byte *old_key,uint old_key_length);
63
void hash_replace(HASH *hash, HASH_SEARCH_STATE *state, byte *new_row);
64
my_bool hash_check(HASH *hash); /* Only in debug library */
66
#define hash_clear(H) bzero((char*) (H),sizeof(*(H)))
67
#define hash_inited(H) ((H)->array.buffer != 0)
68
#define hash_init_opt(A,B,C,D,E,F,G,H) \
69
(!hash_inited(A) && _hash_init(A,B,C,D,E,F,G, H CALLER_INFO))