00001 /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB 00002 00003 This library is free software; you can redistribute it and/or 00004 modify it under the terms of the GNU Library General Public 00005 License as published by the Free Software Foundation; either 00006 version 2 of the License, or (at your option) any later version. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public 00014 License along with this library; if not, write to the Free 00015 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00016 MA 02111-1307, USA */ 00017 00018 #ifndef _HASH_ 00019 #define _HASH_ 00020 00021 #define SUCCESS 0 00022 #define FAILURE 1 00023 00024 #include <sys/types.h> 00025 #include <my_sys.h> 00026 00027 typedef struct _entry { 00028 char *str; 00029 struct _entry *pNext; 00030 } entry; 00031 00032 typedef struct bucket 00033 { 00034 uint h; /* Used for numeric indexing */ 00035 char *arKey; 00036 uint nKeyLength; 00037 uint count; 00038 entry *pData; 00039 struct bucket *pNext; 00040 } Bucket; 00041 00042 typedef struct hashtable { 00043 uint nTableSize; 00044 uint initialized; 00045 MEM_ROOT mem_root; 00046 uint(*pHashFunction) (const char *arKey, uint nKeyLength); 00047 Bucket **arBuckets; 00048 } HashTable; 00049 00050 extern int completion_hash_init(HashTable *ht, uint nSize); 00051 extern int completion_hash_update(HashTable *ht, char *arKey, uint nKeyLength, char *str); 00052 extern int hash_exists(HashTable *ht, char *arKey); 00053 extern Bucket *find_all_matches(HashTable *ht, const char *str, uint length, uint *res_length); 00054 extern Bucket *find_longest_match(HashTable *ht, char *str, uint length, uint *res_length); 00055 extern void add_word(HashTable *ht,char *str); 00056 extern void completion_hash_clean(HashTable *ht); 00057 extern int completion_hash_exists(HashTable *ht, char *arKey, uint nKeyLength); 00058 extern void completion_hash_free(HashTable *ht); 00059 00060 #endif /* _HASH_ */
1.4.7

