completion_hash.h
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:2k
源码类别:

MySQL数据库

开发平台:

Visual C++

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