~vlad-lesin/percona-server/mysql-5.0.33-original

« back to all changes in this revision

Viewing changes to include/hash.h

  • Committer: Vlad Lesin
  • Date: 2012-07-31 09:21:34 UTC
  • Revision ID: vladislav.lesin@percona.com-20120731092134-zfodx022b7992wsi
VirginĀ 5.0.33

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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; either version 2 of the License, or
 
6
   (at your option) any later version.
 
7
 
 
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.
 
12
 
 
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 */
 
16
 
 
17
/* Dynamic hashing of record with different key-length */
 
18
 
 
19
#ifndef _hash_h
 
20
#define _hash_h
 
21
#ifdef  __cplusplus
 
22
extern "C" {
 
23
#endif
 
24
 
 
25
/*
 
26
  Overhead to store an element in hash
 
27
  Can be used to approximate memory consumption for a hash
 
28
 */
 
29
#define HASH_OVERHEAD (sizeof(char*)*2)
 
30
 
 
31
typedef byte *(*hash_get_key)(const byte *,uint*,my_bool);
 
32
typedef void (*hash_free_key)(void *);
 
33
 
 
34
typedef struct st_hash {
 
35
  uint key_offset,key_length;           /* Length of key if const length */
 
36
  uint records, blength;
 
37
  uint flags;
 
38
  DYNAMIC_ARRAY array;                          /* Place for hash_keys */
 
39
  hash_get_key get_key;
 
40
  void (*free)(void *);
 
41
  CHARSET_INFO *charset;
 
42
} HASH;
 
43
 
 
44
/* A search iterator state */
 
45
typedef uint HASH_SEARCH_STATE;
 
46
 
 
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 */
 
65
 
 
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))
 
70
 
 
71
#ifdef  __cplusplus
 
72
}
 
73
#endif
 
74
#endif