1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2002 MySQL AB
|
2 |
||
3 |
This library is free software; you can redistribute it and/or
|
|
4 |
modify it under the terms of the GNU Library General Public
|
|
5 |
License as published by the Free Software Foundation; version 2
|
|
6 |
of the License.
|
|
7 |
||
8 |
This library 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 GNU
|
|
11 |
Library General Public License for more details.
|
|
12 |
||
13 |
You should have received a copy of the GNU Library General Public
|
|
14 |
License along with this library; if not, write to the Free
|
|
15 |
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
|
16 |
MA 02111-1307, USA */
|
|
17 |
||
18 |
#ifndef _HASH_
|
|
19 |
#define _HASH_
|
|
20 |
||
21 |
#define SUCCESS 0
|
|
22 |
#define FAILURE 1
|
|
23 |
||
24 |
#include <sys/types.h> |
|
25 |
#include <my_sys.h> |
|
26 |
||
27 |
typedef struct _entry { |
|
28 |
char *str; |
|
29 |
struct _entry *pNext; |
|
30 |
} entry; |
|
31 |
||
32 |
typedef struct bucket |
|
33 |
{
|
|
34 |
uint h; /* Used for numeric indexing */ |
|
35 |
char *arKey; |
|
36 |
uint nKeyLength; |
|
37 |
uint count; |
|
38 |
entry *pData; |
|
39 |
struct bucket *pNext; |
|
40 |
} Bucket; |
|
41 |
||
42 |
typedef struct hashtable { |
|
43 |
uint nTableSize; |
|
44 |
uint initialized; |
|
45 |
MEM_ROOT mem_root; |
|
46 |
uint(*pHashFunction) (const char *arKey, uint nKeyLength); |
|
47 |
Bucket **arBuckets; |
|
48 |
} HashTable; |
|
49 |
||
50 |
extern int completion_hash_init(HashTable *ht, uint nSize); |
|
51 |
extern int completion_hash_update(HashTable *ht, char *arKey, uint nKeyLength, char *str); |
|
52 |
extern int hash_exists(HashTable *ht, char *arKey); |
|
53 |
extern Bucket *find_all_matches(HashTable *ht, const char *str, uint length, uint *res_length); |
|
54 |
extern Bucket *find_longest_match(HashTable *ht, char *str, uint length, uint *res_length); |
|
55 |
extern void add_word(HashTable *ht,char *str); |
|
56 |
extern void completion_hash_clean(HashTable *ht); |
|
57 |
extern int completion_hash_exists(HashTable *ht, char *arKey, uint nKeyLength); |
|
58 |
extern void completion_hash_free(HashTable *ht); |
|
59 |
||
60 |
#endif /* _HASH_ */ |