1/* Copyright (c) 2000-2002, 2006 MySQL AB
2 Use is subject to license terms
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; version 2
7 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with this library; if not, write to the Free
16 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 MA 02110-1301, USA */
18
19#ifndef _HASH_
20#define _HASH_
21
22#define SUCCESS 0
23#define FAILURE 1
24
25#include <sys/types.h>
26#include <my_sys.h>
27
28typedef struct _entry {
29 char *str;
30 struct _entry *pNext;
31} entry;
32
33typedef struct bucket
34{
35 uint h; /* Used for numeric indexing */
36 char *arKey;
37 uint nKeyLength;
38 uint count;
39 entry *pData;
40 struct bucket *pNext;
41} Bucket;
42
43typedef struct hashtable {
44 uint nTableSize;
45 uint initialized;
46 MEM_ROOT mem_root;
47 uint(*pHashFunction) (const char *arKey, uint nKeyLength);
48 Bucket **arBuckets;
49} HashTable;
50
51extern int completion_hash_init(HashTable *ht, uint nSize);
52extern int completion_hash_update(HashTable *ht, char *arKey, uint nKeyLength, char *str);
53extern int hash_exists(HashTable *ht, char *arKey);
54extern Bucket *find_all_matches(HashTable *ht, const char *str, uint length, uint *res_length);
55extern Bucket *find_longest_match(HashTable *ht, char *str, uint length, uint *res_length);
56extern void add_word(HashTable *ht,char *str);
57extern void completion_hash_clean(HashTable *ht);
58extern int completion_hash_exists(HashTable *ht, char *arKey, uint nKeyLength);
59extern void completion_hash_free(HashTable *ht);
60
61#endif /* _HASH_ */
62