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