OLD | NEW |
1 /* | 1 /* |
2 ** 2001 September 22 | 2 ** 2001 September 22 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
11 ************************************************************************* | 11 ************************************************************************* |
12 ** This is the implementation of generic hash-tables used in SQLite. | 12 ** This is the implementation of generic hash-tables used in SQLite. |
13 ** We've modified it slightly to serve as a standalone hash table | 13 ** We've modified it slightly to serve as a standalone hash table |
14 ** implementation for the full-text indexing module. | 14 ** implementation for the full-text indexing module. |
15 */ | 15 */ |
16 | 16 |
17 /* | 17 /* |
18 ** The code in this file is only compiled if: | 18 ** The code in this file is only compiled if: |
19 ** | 19 ** |
20 ** * The FTS3 module is being built as an extension | 20 ** * The FTS3 module is being built as an extension |
21 ** (in which case SQLITE_CORE is not defined), or | 21 ** (in which case SQLITE_CORE is not defined), or |
22 ** | 22 ** |
23 ** * The FTS3 module is being built into the core of | 23 ** * The FTS3 module is being built into the core of |
24 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined). | 24 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined). |
25 */ | 25 */ |
| 26 #include "fts3Int.h" |
26 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) | 27 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
27 | 28 |
28 #include <assert.h> | 29 #include <assert.h> |
29 #include <stdlib.h> | 30 #include <stdlib.h> |
30 #include <string.h> | 31 #include <string.h> |
31 | 32 |
32 #include "sqlite3.h" | |
33 #include "fts3_hash.h" | 33 #include "fts3_hash.h" |
34 | 34 |
35 /* | 35 /* |
36 ** Malloc and Free functions | 36 ** Malloc and Free functions |
37 */ | 37 */ |
38 static void *fts3HashMalloc(int n){ | 38 static void *fts3HashMalloc(int n){ |
39 void *p = sqlite3_malloc(n); | 39 void *p = sqlite3_malloc(n); |
40 if( p ){ | 40 if( p ){ |
41 memset(p, 0, n); | 41 memset(p, 0, n); |
42 } | 42 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 elem = next_elem; | 89 elem = next_elem; |
90 } | 90 } |
91 pH->count = 0; | 91 pH->count = 0; |
92 } | 92 } |
93 | 93 |
94 /* | 94 /* |
95 ** Hash and comparison functions when the mode is FTS3_HASH_STRING | 95 ** Hash and comparison functions when the mode is FTS3_HASH_STRING |
96 */ | 96 */ |
97 static int fts3StrHash(const void *pKey, int nKey){ | 97 static int fts3StrHash(const void *pKey, int nKey){ |
98 const char *z = (const char *)pKey; | 98 const char *z = (const char *)pKey; |
99 int h = 0; | 99 unsigned h = 0; |
100 if( nKey<=0 ) nKey = (int) strlen(z); | 100 if( nKey<=0 ) nKey = (int) strlen(z); |
101 while( nKey > 0 ){ | 101 while( nKey > 0 ){ |
102 h = (h<<3) ^ h ^ *z++; | 102 h = (h<<3) ^ h ^ *z++; |
103 nKey--; | 103 nKey--; |
104 } | 104 } |
105 return h & 0x7fffffff; | 105 return (int)(h & 0x7fffffff); |
106 } | 106 } |
107 static int fts3StrCompare(const void *pKey1, int n1, const void *pKey2, int n2){ | 107 static int fts3StrCompare(const void *pKey1, int n1, const void *pKey2, int n2){ |
108 if( n1!=n2 ) return 1; | 108 if( n1!=n2 ) return 1; |
109 return strncmp((const char*)pKey1,(const char*)pKey2,n1); | 109 return strncmp((const char*)pKey1,(const char*)pKey2,n1); |
110 } | 110 } |
111 | 111 |
112 /* | 112 /* |
113 ** Hash and comparison functions when the mode is FTS3_HASH_BINARY | 113 ** Hash and comparison functions when the mode is FTS3_HASH_BINARY |
114 */ | 114 */ |
115 static int fts3BinHash(const void *pKey, int nKey){ | 115 static int fts3BinHash(const void *pKey, int nKey){ |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 pH->count++; | 374 pH->count++; |
375 assert( pH->htsize>0 ); | 375 assert( pH->htsize>0 ); |
376 assert( (pH->htsize & (pH->htsize-1))==0 ); | 376 assert( (pH->htsize & (pH->htsize-1))==0 ); |
377 h = hraw & (pH->htsize-1); | 377 h = hraw & (pH->htsize-1); |
378 fts3HashInsertElement(pH, &pH->ht[h], new_elem); | 378 fts3HashInsertElement(pH, &pH->ht[h], new_elem); |
379 new_elem->data = data; | 379 new_elem->data = data; |
380 return 0; | 380 return 0; |
381 } | 381 } |
382 | 382 |
383 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ | 383 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ |
OLD | NEW |