~drizzle-trunk/drizzle/development

520.7.1 by Monty Taylor
Moved hash.c to drizzled.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
1 by brian
clean slate
19
20
/* Dynamic hashing of record with different key-length */
21
520.8.3 by Monty Taylor
Moved hash back to mysys.
22
#ifndef MYSYS_HASH_H
23
#define MYSYS_HASH_H
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
24
25
#include <mysys/my_sys.h>
26
27
#ifdef __cplusplus
1 by brian
clean slate
28
extern "C" {
29
#endif
30
31
/*
32
  Overhead to store an element in hash
33
  Can be used to approximate memory consumption for a hash
34
 */
35
#define HASH_OVERHEAD (sizeof(char*)*2)
36
37
/* flags for hash_init */
38
#define HASH_UNIQUE     1       /* hash_insert fails on duplicate key */
39
481 by Brian Aker
Remove all of uchar.
40
typedef unsigned char *(*hash_get_key)(const unsigned char *,size_t*,bool);
1 by brian
clean slate
41
typedef void (*hash_free_key)(void *);
42
43
typedef struct st_hash {
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
44
  /* Length of key if const length */
45
  size_t key_offset,key_length;
1 by brian
clean slate
46
  size_t blength;
298 by Brian Aker
ulong conversion.
47
  uint32_t records;
482 by Brian Aker
Remove uint.
48
  uint32_t flags;
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
49
  /* Place for hash_keys */
50
  DYNAMIC_ARRAY array;
1 by brian
clean slate
51
  hash_get_key get_key;
598.1.1 by Super-User
Fixed solaris build crap.
52
  hash_free_key free;
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
53
  const CHARSET_INFO *charset;
1 by brian
clean slate
54
} HASH;
55
56
/* A search iterator state */
482 by Brian Aker
Remove uint.
57
typedef uint32_t HASH_SEARCH_STATE;
1 by brian
clean slate
58
598.1.1 by Super-User
Fixed solaris build crap.
59
bool
60
_hash_init(HASH *hash,uint32_t growth_size, const CHARSET_INFO * const charset,
61
           uint32_t size, size_t key_offset, size_t key_length,
62
           hash_get_key get_key,
63
           hash_free_key free_element, uint32_t flags);
595 by Brian Aker
Fix, partial, for Sun Studio.
64
#define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,0,B,C,D,E,F,G,H)
65
#define hash_init2(A,B,C,D,E,F,G,H,I) _hash_init(A,B,C,D,E,F,G,H,I)
1 by brian
clean slate
66
void hash_free(HASH *tree);
67
void my_hash_reset(HASH *hash);
481 by Brian Aker
Remove all of uchar.
68
unsigned char *hash_element(HASH *hash,uint32_t idx);
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
69
unsigned char *hash_search(const HASH *info, const unsigned char *key,
70
                           size_t length);
71
unsigned char *hash_first(const HASH *info, const unsigned char *key,
72
                          size_t length, HASH_SEARCH_STATE *state);
73
unsigned char *hash_next(const HASH *info, const unsigned char *key,
74
                         size_t length, HASH_SEARCH_STATE *state);
481 by Brian Aker
Remove all of uchar.
75
bool my_hash_insert(HASH *info,const unsigned char *data);
76
bool hash_delete(HASH *hash,unsigned char *record);
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
77
bool hash_update(HASH *hash,unsigned char *record, unsigned char *old_key,
78
                 size_t old_key_length);
481 by Brian Aker
Remove all of uchar.
79
void hash_replace(HASH *hash, HASH_SEARCH_STATE *state, unsigned char *new_row);
1 by brian
clean slate
80
212.6.14 by Mats Kindahl
Removing redundant use of casts in mysys for memcmp(), memcpy(), memset(), and memmove().
81
#define hash_clear(H) memset((H), 0, sizeof(*(H)))
1 by brian
clean slate
82
#define hash_inited(H) ((H)->array.buffer != 0)
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
83
#define hash_init_opt(A,B,C,D,E,F,G,H)                                  \
575.1.6 by Monty Taylor
Cleaned up some headers for PCH.
84
  (!hash_inited(A) && _hash_init(A,0,B,C,D,E,F,G, H))
1 by brian
clean slate
85
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
86
#ifdef __cplusplus
1 by brian
clean slate
87
}
88
#endif
89
#endif