completion_hash.h 1.86 KB
Newer Older
1
/* Copyright (C) 2000-2002 MySQL AB
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2

3
   This program is free software; you can redistribute it and/or
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4
   modify it under the terms of the GNU Library General Public
5 6
   License as published by the Free Software Foundation; version 2
   of the License.
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
7

8
   This program is distributed in the hope that it will be useful,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
9 10 11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
12

bk@work.mysql.com's avatar
bk@work.mysql.com committed
13 14 15 16 17 18 19 20 21 22 23 24
   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
   MA 02111-1307, USA */

#ifndef _HASH_
#define _HASH_

#define SUCCESS 0
#define FAILURE 1

#include <sys/types.h>
25
#include <my_sys.h>
bk@work.mysql.com's avatar
bk@work.mysql.com committed
26 27 28 29 30 31

typedef struct _entry {
	char *str;
	struct _entry *pNext;
} entry;

32 33 34 35 36 37 38 39
typedef struct bucket
{
  uint h;					/* Used for numeric indexing */
  char *arKey;
  uint nKeyLength;
  uint count;
  entry *pData;
  struct bucket *pNext;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
40 41 42
} Bucket;

typedef struct hashtable {
43 44 45
  uint nTableSize;
  uint initialized;
  MEM_ROOT mem_root;
46
  uint(*pHashFunction) (const char *arKey, uint nKeyLength);
47
  Bucket **arBuckets;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
48 49 50 51 52
} HashTable;

extern int completion_hash_init(HashTable *ht, uint nSize);
extern int completion_hash_update(HashTable *ht, char *arKey, uint nKeyLength, char *str);
extern int hash_exists(HashTable *ht, char *arKey);
53
extern Bucket *find_all_matches(HashTable *ht, const char *str, uint length, uint *res_length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
54 55 56 57 58 59
extern Bucket *find_longest_match(HashTable *ht, char *str, uint length, uint *res_length);
extern void add_word(HashTable *ht,char *str);
extern void completion_hash_clean(HashTable *ht);
extern int completion_hash_exists(HashTable *ht, char *arKey, uint nKeyLength);
extern void completion_hash_free(HashTable *ht);

60
#endif /* _HASH_ */