#include <my_global.h>#include <m_string.h>#include <my_sys.h>#include "completion_hash.h"Include dependency graph for completion_hash.cc:

Go to the source code of this file.
Functions | |
| uint | hashpjw (const char *arKey, uint nKeyLength) |
| int | completion_hash_init (HashTable *ht, uint nSize) |
| int | completion_hash_update (HashTable *ht, char *arKey, uint nKeyLength, char *str) |
| static Bucket * | completion_hash_find (HashTable *ht, const char *arKey, uint nKeyLength) |
| int | completion_hash_exists (HashTable *ht, char *arKey, uint nKeyLength) |
| Bucket * | find_all_matches (HashTable *ht, const char *str, uint length, uint *res_length) |
| Bucket * | find_longest_match (HashTable *ht, char *str, uint length, uint *res_length) |
| void | completion_hash_clean (HashTable *ht) |
| void | completion_hash_free (HashTable *ht) |
| void | add_word (HashTable *ht, char *str) |
| void add_word | ( | HashTable * | ht, | |
| char * | str | |||
| ) |
Definition at line 221 of file completion_hash.cc.
References completion_hash_update(), ht, and pos().
Referenced by build_completion_hash(), and simple_parser_parse().
00222 { 00223 int i; 00224 char *pos=str; 00225 for (i=1; *pos; i++, pos++) 00226 completion_hash_update(ht, str, i, str); 00227 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void completion_hash_clean | ( | HashTable * | ht | ) |
Definition at line 207 of file completion_hash.cc.
References hashtable::arBuckets, bzero, free_root(), ht, hashtable::mem_root, MYF, and hashtable::nTableSize.
Referenced by build_completion_hash(), and completion_hash_free().
00208 { 00209 free_root(&ht->mem_root,MYF(0)); 00210 bzero((char*) ht->arBuckets,ht->nTableSize*sizeof(Bucket *)); 00211 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 138 of file completion_hash.cc.
References hashtable::arBuckets, h, ht, hashtable::nTableSize, p, hashtable::pHashFunction, and strcmp().
Referenced by build_completion_hash().
00139 { 00140 uint h, nIndex; 00141 Bucket *p; 00142 00143 h = ht->pHashFunction(arKey, nKeyLength); 00144 nIndex = h % ht->nTableSize; 00145 00146 p = ht->arBuckets[nIndex]; 00147 while (p) 00148 { 00149 if ((p->h == h) && (p->nKeyLength == nKeyLength)) 00150 { 00151 if (!strcmp(p->arKey, arKey)) { 00152 return 1; 00153 } 00154 } 00155 p = p->pNext; 00156 } 00157 return 0; 00158 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static Bucket* completion_hash_find | ( | HashTable * | ht, | |
| const char * | arKey, | |||
| uint | nKeyLength | |||
| ) | [static] |
Definition at line 115 of file completion_hash.cc.
References hashtable::arBuckets, h, ht, memcmp(), hashtable::nTableSize, p, and hashtable::pHashFunction.
Referenced by find_all_matches(), and find_longest_match().
00117 { 00118 uint h, nIndex; 00119 Bucket *p; 00120 00121 h = ht->pHashFunction(arKey, nKeyLength); 00122 nIndex = h % ht->nTableSize; 00123 00124 p = ht->arBuckets[nIndex]; 00125 while (p) 00126 { 00127 if ((p->h == h) && (p->nKeyLength == nKeyLength)) { 00128 if (!memcmp(p->arKey, arKey, nKeyLength)) { 00129 return p; 00130 } 00131 } 00132 p = p->pNext; 00133 } 00134 return (Bucket*) 0; 00135 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void completion_hash_free | ( | HashTable * | ht | ) |
Definition at line 214 of file completion_hash.cc.
References hashtable::arBuckets, completion_hash_clean(), ht, my_free, and MYF.
Referenced by mysql_end().
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 44 of file completion_hash.cc.
References hashtable::arBuckets, FAILURE, hashpjw(), ht, init_alloc_root(), hashtable::initialized, hashtable::mem_root, my_malloc(), MY_WME, MY_ZEROFILL, MYF, hashtable::nTableSize, hashtable::pHashFunction, and SUCCESS.
Referenced by main().
00045 { 00046 ht->arBuckets = (Bucket **) my_malloc(nSize* sizeof(Bucket *), 00047 MYF(MY_ZEROFILL | MY_WME)); 00048 00049 if (!ht->arBuckets) 00050 { 00051 ht->initialized = 0; 00052 return FAILURE; 00053 } 00054 init_alloc_root(&ht->mem_root, 8192, 0); 00055 ht->pHashFunction = hashpjw; 00056 ht->nTableSize = nSize; 00057 ht->initialized = 1; 00058 return SUCCESS; 00059 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 62 of file completion_hash.cc.
References alloc_root(), hashtable::arBuckets, FAILURE, h, ht, hashtable::mem_root, memcmp(), n, hashtable::nTableSize, p, hashtable::pHashFunction, and SUCCESS.
Referenced by add_word().
00064 { 00065 uint h, nIndex; 00066 00067 Bucket *p; 00068 00069 h = ht->pHashFunction(arKey, nKeyLength); 00070 nIndex = h % ht->nTableSize; 00071 00072 if (nKeyLength <= 0) { 00073 return FAILURE; 00074 } 00075 p = ht->arBuckets[nIndex]; 00076 while (p) 00077 { 00078 if ((p->h == h) && (p->nKeyLength == nKeyLength)) { 00079 if (!memcmp(p->arKey, arKey, nKeyLength)) { 00080 entry *n; 00081 00082 if (!(n = (entry *) alloc_root(&ht->mem_root,sizeof(entry)))) 00083 return FAILURE; 00084 n->pNext = p->pData; 00085 n->str = str; 00086 p->pData = n; 00087 p->count++; 00088 00089 return SUCCESS; 00090 } 00091 } 00092 p = p->pNext; 00093 } 00094 00095 if (!(p = (Bucket *) alloc_root(&ht->mem_root, sizeof(Bucket)))) 00096 return FAILURE; 00097 00098 p->arKey = arKey; 00099 p->nKeyLength = nKeyLength; 00100 p->h = h; 00101 00102 if (!(p->pData = (entry*) alloc_root(&ht->mem_root, sizeof(entry)))) 00103 return FAILURE; 00104 00105 p->pData->str = str; 00106 p->pData->pNext = 0; 00107 p->count = 1; 00108 00109 p->pNext = ht->arBuckets[nIndex]; 00110 ht->arBuckets[nIndex] = p; 00111 00112 return SUCCESS; 00113 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 160 of file completion_hash.cc.
References completion_hash_find(), and ht.
Referenced by new_command_generator().
00162 { 00163 Bucket *b; 00164 00165 b = completion_hash_find(ht,str,length); 00166 if (!b) { 00167 *res_length = 0; 00168 return (Bucket*) 0; 00169 } else { 00170 *res_length = length; 00171 return b; 00172 } 00173 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 175 of file completion_hash.cc.
References completion_hash_find(), count, bucket::count, ht, bucket::pData, and _entry::str.
00177 { 00178 Bucket *b,*return_b; 00179 char *s; 00180 uint count; 00181 uint lm; 00182 00183 b = completion_hash_find(ht,str,length); 00184 if (!b) { 00185 *res_length = 0; 00186 return (Bucket*) 0; 00187 } 00188 00189 count = b->count; 00190 lm = length; 00191 s = b->pData->str; 00192 00193 return_b = b; 00194 while (s[lm]!=0 && (b=completion_hash_find(ht,s,lm+1))) { 00195 if (b->count<count) { 00196 *res_length=lm; 00197 return return_b; 00198 } 00199 return_b=b; 00200 lm++; 00201 } 00202 *res_length=lm; 00203 return return_b; 00204 }
Here is the call graph for this function:

Definition at line 30 of file completion_hash.cc.
References h.
Referenced by completion_hash_init().
00031 { 00032 uint h = 0, g, i; 00033 00034 for (i = 0; i < nKeyLength; i++) { 00035 h = (h << 4) + arKey[i]; 00036 if ((g = (h & 0xF0000000))) { 00037 h = h ^ (g >> 24); 00038 h = h ^ g; 00039 } 00040 } 00041 return h; 00042 }
Here is the caller graph for this function:

1.4.7

