~drizzle-trunk/drizzle/development

1 by brian
clean slate
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
/* Dynamic hashing of record with different key-length */
17
18
#ifndef _hash_h
19
#define _hash_h
20
#ifdef	__cplusplus
21
extern "C" {
22
#endif
23
24
/*
25
  Overhead to store an element in hash
26
  Can be used to approximate memory consumption for a hash
27
 */
28
#define HASH_OVERHEAD (sizeof(char*)*2)
29
30
/* flags for hash_init */
31
#define HASH_UNIQUE     1       /* hash_insert fails on duplicate key */
32
146 by Brian Aker
my_bool cleanup.
33
typedef uchar *(*hash_get_key)(const uchar *,size_t*,bool);
1 by brian
clean slate
34
typedef void (*hash_free_key)(void *);
35
36
typedef struct st_hash {
37
  size_t key_offset,key_length;		/* Length of key if const length */
38
  size_t blength;
298 by Brian Aker
ulong conversion.
39
  uint32_t records;
1 by brian
clean slate
40
  uint flags;
41
  DYNAMIC_ARRAY array;				/* Place for hash_keys */
42
  hash_get_key get_key;
43
  void (*free)(void *);
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
44
  const CHARSET_INFO *charset;
1 by brian
clean slate
45
} HASH;
46
47
/* A search iterator state */
48
typedef uint HASH_SEARCH_STATE;
49
50
#define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,0,B,C,D,E,F,G,H CALLER_INFO)
51
#define hash_init2(A,B,C,D,E,F,G,H,I) _hash_init(A,B,C,D,E,F,G,H,I CALLER_INFO)
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
52
bool _hash_init(HASH *hash, uint growth_size, const CHARSET_INFO * const charset,
298 by Brian Aker
ulong conversion.
53
		   uint32_t default_array_elements, size_t key_offset,
1 by brian
clean slate
54
		   size_t key_length, hash_get_key get_key,
55
		   void (*free_element)(void*), uint flags CALLER_INFO_PROTO);
56
void hash_free(HASH *tree);
57
void my_hash_reset(HASH *hash);
298 by Brian Aker
ulong conversion.
58
uchar *hash_element(HASH *hash,uint32_t idx);
1 by brian
clean slate
59
uchar *hash_search(const HASH *info, const uchar *key, size_t length);
60
uchar *hash_first(const HASH *info, const uchar *key, size_t length,
61
                HASH_SEARCH_STATE *state);
62
uchar *hash_next(const HASH *info, const uchar *key, size_t length,
63
                 HASH_SEARCH_STATE *state);
146 by Brian Aker
my_bool cleanup.
64
bool my_hash_insert(HASH *info,const uchar *data);
65
bool hash_delete(HASH *hash,uchar *record);
66
bool hash_update(HASH *hash,uchar *record,uchar *old_key,size_t old_key_length);
1 by brian
clean slate
67
void hash_replace(HASH *hash, HASH_SEARCH_STATE *state, uchar *new_row);
68
212.6.14 by Mats Kindahl
Removing redundant use of casts in mysys for memcmp(), memcpy(), memset(), and memmove().
69
#define hash_clear(H) memset((H), 0, sizeof(*(H)))
1 by brian
clean slate
70
#define hash_inited(H) ((H)->array.buffer != 0)
71
#define hash_init_opt(A,B,C,D,E,F,G,H) \
72
          (!hash_inited(A) && _hash_init(A,0,B,C,D,E,F,G, H CALLER_INFO))
73
74
#ifdef	__cplusplus
75
}
76
#endif
77
#endif