~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/hash.h

  • Committer: Brian Aker
  • Date: 2008-08-11 04:55:59 UTC
  • Revision ID: brian@tangent.org-20080811045559-azgfc343y0igyzsz
ulong cleanup, remove log code from myisam.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
/* 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 */
19
15
 
20
16
/* Dynamic hashing of record with different key-length */
21
17
 
22
 
#ifndef MYSYS_HASH_H
23
 
#define MYSYS_HASH_H
24
 
 
25
 
#include <mysys/my_sys.h>
26
 
 
27
 
#ifdef __cplusplus
 
18
#ifndef _hash_h
 
19
#define _hash_h
 
20
#ifdef  __cplusplus
28
21
extern "C" {
29
22
#endif
30
23
 
37
30
/* flags for hash_init */
38
31
#define HASH_UNIQUE     1       /* hash_insert fails on duplicate key */
39
32
 
40
 
typedef unsigned char *(*hash_get_key)(const unsigned char *,size_t*,bool);
 
33
typedef uchar *(*hash_get_key)(const uchar *,size_t*,bool);
41
34
typedef void (*hash_free_key)(void *);
42
35
 
43
36
typedef struct st_hash {
44
 
  /* Length of key if const length */
45
 
  size_t key_offset,key_length;
 
37
  size_t key_offset,key_length;         /* Length of key if const length */
46
38
  size_t blength;
47
39
  uint32_t records;
48
 
  uint32_t flags;
49
 
  /* Place for hash_keys */
50
 
  DYNAMIC_ARRAY array;
 
40
  uint flags;
 
41
  DYNAMIC_ARRAY array;                          /* Place for hash_keys */
51
42
  hash_get_key get_key;
52
 
  hash_free_key free;
 
43
  void (*free)(void *);
53
44
  const CHARSET_INFO *charset;
54
45
} HASH;
55
46
 
56
47
/* A search iterator state */
57
 
typedef uint32_t HASH_SEARCH_STATE;
 
48
typedef uint HASH_SEARCH_STATE;
58
49
 
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);
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)
 
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)
 
52
bool _hash_init(HASH *hash, uint growth_size, const CHARSET_INFO * const charset,
 
53
                   uint32_t default_array_elements, size_t key_offset,
 
54
                   size_t key_length, hash_get_key get_key,
 
55
                   void (*free_element)(void*), uint flags CALLER_INFO_PROTO);
66
56
void hash_free(HASH *tree);
67
57
void my_hash_reset(HASH *hash);
68
 
unsigned char *hash_element(HASH *hash,uint32_t idx);
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);
75
 
bool my_hash_insert(HASH *info,const unsigned char *data);
76
 
bool hash_delete(HASH *hash,unsigned char *record);
77
 
bool hash_update(HASH *hash,unsigned char *record, unsigned char *old_key,
78
 
                 size_t old_key_length);
79
 
void hash_replace(HASH *hash, HASH_SEARCH_STATE *state, unsigned char *new_row);
 
58
uchar *hash_element(HASH *hash,uint32_t idx);
 
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);
 
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);
 
67
void hash_replace(HASH *hash, HASH_SEARCH_STATE *state, uchar *new_row);
80
68
 
81
69
#define hash_clear(H) memset((H), 0, sizeof(*(H)))
82
70
#define hash_inited(H) ((H)->array.buffer != 0)
83
 
#define hash_init_opt(A,B,C,D,E,F,G,H)                                  \
84
 
  (!hash_inited(A) && _hash_init(A,0,B,C,D,E,F,G, H))
 
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))
85
73
 
86
 
#ifdef __cplusplus
 
74
#ifdef  __cplusplus
87
75
}
88
76
#endif
89
77
#endif