Drizzled Public API Documentation

my_hash.h
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, Inc.
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  */
19 
20 /* Dynamic hashing of record with different key-length */
21 
22 #pragma once
23 
24 #include <drizzled/dynamic_array.h>
25 
26 namespace drizzled {
27 
28 /*
29  Overhead to store an element in hash
30  Can be used to approximate memory consumption for a hash
31  */
32 #define HASH_OVERHEAD (sizeof(char*)*2)
33 
34 /* flags for hash_init */
35 #define HASH_UNIQUE 1 /* hash_insert fails on duplicate key */
36 
37 typedef unsigned char *(*hash_get_key)(const unsigned char *,size_t*,bool);
38 typedef void (*hash_free_key)(void *);
39 
40 struct HASH_LINK
41 {
42  /* index to next key */
43  uint32_t next;
44  /* data for current entry */
45  unsigned char *data;
46 } ;
47 
48 struct charset_info_st;
49 
50 struct HASH
51 {
52  // typedef std::vector<HASH_LINK> array_t;
53  typedef DYNAMIC_ARRAY array_t;
54  /* Length of key if const length */
55  size_t key_offset,key_length;
56  uint32_t blength;
57  uint32_t records;
58  uint32_t flags;
59  /* Place for hash_keys */
60  array_t array;
61  hash_get_key get_key;
62  hash_free_key free;
63  const charset_info_st *charset;
64 };
65 
66 /* A search iterator state */
67 typedef uint32_t HASH_SEARCH_STATE;
68 
69 void
70 _hash_init(HASH *hash,uint32_t growth_size, const charset_info_st* const,
71  uint32_t size, size_t key_offset, size_t key_length,
72  hash_get_key get_key,
73  hash_free_key free_element, uint32_t flags);
74 #define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,0,B,C,D,E,F,G,H)
75 void hash_free(HASH *tree);
76 unsigned char *hash_search(const HASH *info, const unsigned char *key,
77  size_t length);
78 unsigned char *hash_first(const HASH *info, const unsigned char *key, size_t length, HASH_SEARCH_STATE *state);
79 bool my_hash_insert(HASH *info,const unsigned char *data);
80 bool hash_delete(HASH *hash,unsigned char *record);
81 
82 } /* namespace drizzled */
83 
TODO: Rename this file - func.h is stupid.