annotate sqlite/hash.c @ 1456:6fe7ba6e5489 trunk

[svn] - Don't poll the config database if not using TCP sockets.
author nhjm449
date Mon, 31 Jul 2006 17:06:44 -0700
parents b6b61becdf4e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1434
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2 ** 2001 September 22
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4 ** The author disclaims copyright to this source code. In place of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
5 ** a legal notice, here is a blessing:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
6 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
7 ** May you do good and not evil.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
8 ** May you find forgiveness for yourself and forgive others.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
9 ** May you share freely, never taking more than you give.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
10 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
11 *************************************************************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
12 ** This is the implementation of generic hash-tables
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
13 ** used in SQLite.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
14 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
15 ** $Id: hash.c,v 1.18 2006/02/14 10:48:39 danielk1977 Exp $
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
16 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
17 #include "sqliteInt.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
18 #include <assert.h>
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
19
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
20 /* Turn bulk memory into a hash table object by initializing the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
21 ** fields of the Hash structure.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
22 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
23 ** "pNew" is a pointer to the hash table that is to be initialized.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
24 ** keyClass is one of the constants SQLITE_HASH_INT, SQLITE_HASH_POINTER,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
25 ** SQLITE_HASH_BINARY, or SQLITE_HASH_STRING. The value of keyClass
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
26 ** determines what kind of key the hash table will use. "copyKey" is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
27 ** true if the hash table should make its own private copy of keys and
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
28 ** false if it should just use the supplied pointer. CopyKey only makes
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
29 ** sense for SQLITE_HASH_STRING and SQLITE_HASH_BINARY and is ignored
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
30 ** for other key classes.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
31 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
32 void sqlite3HashInit(Hash *pNew, int keyClass, int copyKey){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
33 assert( pNew!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
34 assert( keyClass>=SQLITE_HASH_STRING && keyClass<=SQLITE_HASH_BINARY );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
35 pNew->keyClass = keyClass;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
36 #if 0
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
37 if( keyClass==SQLITE_HASH_POINTER || keyClass==SQLITE_HASH_INT ) copyKey = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
38 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
39 pNew->copyKey = copyKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
40 pNew->first = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
41 pNew->count = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
42 pNew->htsize = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
43 pNew->ht = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
44 pNew->xMalloc = sqlite3MallocX;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
45 pNew->xFree = sqlite3FreeX;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
46 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
47
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
48 /* Remove all entries from a hash table. Reclaim all memory.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
49 ** Call this routine to delete a hash table or to reset a hash table
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
50 ** to the empty state.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
51 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
52 void sqlite3HashClear(Hash *pH){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
53 HashElem *elem; /* For looping over all elements of the table */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
54
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
55 assert( pH!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
56 elem = pH->first;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
57 pH->first = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
58 if( pH->ht ) pH->xFree(pH->ht);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
59 pH->ht = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
60 pH->htsize = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
61 while( elem ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
62 HashElem *next_elem = elem->next;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
63 if( pH->copyKey && elem->pKey ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
64 pH->xFree(elem->pKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
65 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
66 pH->xFree(elem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
67 elem = next_elem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
68 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
69 pH->count = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
70 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
71
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
72 #if 0 /* NOT USED */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
73 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
74 ** Hash and comparison functions when the mode is SQLITE_HASH_INT
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
75 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
76 static int intHash(const void *pKey, int nKey){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
77 return nKey ^ (nKey<<8) ^ (nKey>>8);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
78 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
79 static int intCompare(const void *pKey1, int n1, const void *pKey2, int n2){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
80 return n2 - n1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
81 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
82 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
83
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
84 #if 0 /* NOT USED */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
85 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
86 ** Hash and comparison functions when the mode is SQLITE_HASH_POINTER
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
87 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
88 static int ptrHash(const void *pKey, int nKey){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
89 uptr x = Addr(pKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
90 return x ^ (x<<8) ^ (x>>8);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
91 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
92 static int ptrCompare(const void *pKey1, int n1, const void *pKey2, int n2){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
93 if( pKey1==pKey2 ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
94 if( pKey1<pKey2 ) return -1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
95 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
96 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
97 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
98
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
99 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
100 ** Hash and comparison functions when the mode is SQLITE_HASH_STRING
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
101 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
102 static int strHash(const void *pKey, int nKey){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
103 const char *z = (const char *)pKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
104 int h = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
105 if( nKey<=0 ) nKey = strlen(z);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
106 while( nKey > 0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
107 h = (h<<3) ^ h ^ sqlite3UpperToLower[(unsigned char)*z++];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
108 nKey--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
109 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
110 return h & 0x7fffffff;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
111 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
112 static int strCompare(const void *pKey1, int n1, const void *pKey2, int n2){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
113 if( n1!=n2 ) return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
114 return sqlite3StrNICmp((const char*)pKey1,(const char*)pKey2,n1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
115 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
116
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
117 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
118 ** Hash and comparison functions when the mode is SQLITE_HASH_BINARY
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
119 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
120 static int binHash(const void *pKey, int nKey){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
121 int h = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
122 const char *z = (const char *)pKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
123 while( nKey-- > 0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
124 h = (h<<3) ^ h ^ *(z++);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
125 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
126 return h & 0x7fffffff;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
127 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
128 static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
129 if( n1!=n2 ) return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
130 return memcmp(pKey1,pKey2,n1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
131 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
132
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
133 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
134 ** Return a pointer to the appropriate hash function given the key class.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
135 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
136 ** The C syntax in this function definition may be unfamilar to some
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
137 ** programmers, so we provide the following additional explanation:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
138 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
139 ** The name of the function is "hashFunction". The function takes a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
140 ** single parameter "keyClass". The return value of hashFunction()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
141 ** is a pointer to another function. Specifically, the return value
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
142 ** of hashFunction() is a pointer to a function that takes two parameters
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
143 ** with types "const void*" and "int" and returns an "int".
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
144 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
145 static int (*hashFunction(int keyClass))(const void*,int){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
146 #if 0 /* HASH_INT and HASH_POINTER are never used */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
147 switch( keyClass ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
148 case SQLITE_HASH_INT: return &intHash;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
149 case SQLITE_HASH_POINTER: return &ptrHash;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
150 case SQLITE_HASH_STRING: return &strHash;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
151 case SQLITE_HASH_BINARY: return &binHash;;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
152 default: break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
153 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
154 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
155 #else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
156 if( keyClass==SQLITE_HASH_STRING ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
157 return &strHash;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
158 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
159 assert( keyClass==SQLITE_HASH_BINARY );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
160 return &binHash;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
161 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
162 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
163 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
164
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
165 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
166 ** Return a pointer to the appropriate hash function given the key class.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
167 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
168 ** For help in interpreted the obscure C code in the function definition,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
169 ** see the header comment on the previous function.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
170 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
171 static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
172 #if 0 /* HASH_INT and HASH_POINTER are never used */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
173 switch( keyClass ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
174 case SQLITE_HASH_INT: return &intCompare;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
175 case SQLITE_HASH_POINTER: return &ptrCompare;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
176 case SQLITE_HASH_STRING: return &strCompare;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
177 case SQLITE_HASH_BINARY: return &binCompare;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
178 default: break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
179 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
180 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
181 #else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
182 if( keyClass==SQLITE_HASH_STRING ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
183 return &strCompare;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
184 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
185 assert( keyClass==SQLITE_HASH_BINARY );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
186 return &binCompare;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
187 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
188 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
189 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
190
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
191 /* Link an element into the hash table
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
192 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
193 static void insertElement(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
194 Hash *pH, /* The complete hash table */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
195 struct _ht *pEntry, /* The entry into which pNew is inserted */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
196 HashElem *pNew /* The element to be inserted */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
197 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
198 HashElem *pHead; /* First element already in pEntry */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
199 pHead = pEntry->chain;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
200 if( pHead ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
201 pNew->next = pHead;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
202 pNew->prev = pHead->prev;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
203 if( pHead->prev ){ pHead->prev->next = pNew; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
204 else { pH->first = pNew; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
205 pHead->prev = pNew;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
206 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
207 pNew->next = pH->first;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
208 if( pH->first ){ pH->first->prev = pNew; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
209 pNew->prev = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
210 pH->first = pNew;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
211 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
212 pEntry->count++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
213 pEntry->chain = pNew;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
214 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
215
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
216
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
217 /* Resize the hash table so that it cantains "new_size" buckets.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
218 ** "new_size" must be a power of 2. The hash table might fail
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
219 ** to resize if sqliteMalloc() fails.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
220 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
221 static void rehash(Hash *pH, int new_size){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
222 struct _ht *new_ht; /* The new hash table */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
223 HashElem *elem, *next_elem; /* For looping over existing elements */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
224 int (*xHash)(const void*,int); /* The hash function */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
225
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
226 assert( (new_size & (new_size-1))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
227 new_ht = (struct _ht *)pH->xMalloc( new_size*sizeof(struct _ht) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
228 if( new_ht==0 ) return;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
229 if( pH->ht ) pH->xFree(pH->ht);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
230 pH->ht = new_ht;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
231 pH->htsize = new_size;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
232 xHash = hashFunction(pH->keyClass);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
233 for(elem=pH->first, pH->first=0; elem; elem = next_elem){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
234 int h = (*xHash)(elem->pKey, elem->nKey) & (new_size-1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
235 next_elem = elem->next;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
236 insertElement(pH, &new_ht[h], elem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
237 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
238 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
239
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
240 /* This function (for internal use only) locates an element in an
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
241 ** hash table that matches the given key. The hash for this key has
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
242 ** already been computed and is passed as the 4th parameter.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
243 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
244 static HashElem *findElementGivenHash(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
245 const Hash *pH, /* The pH to be searched */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
246 const void *pKey, /* The key we are searching for */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
247 int nKey,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
248 int h /* The hash for this key. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
249 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
250 HashElem *elem; /* Used to loop thru the element list */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
251 int count; /* Number of elements left to test */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
252 int (*xCompare)(const void*,int,const void*,int); /* comparison function */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
253
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
254 if( pH->ht ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
255 struct _ht *pEntry = &pH->ht[h];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
256 elem = pEntry->chain;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
257 count = pEntry->count;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
258 xCompare = compareFunction(pH->keyClass);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
259 while( count-- && elem ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
260 if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
261 return elem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
262 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
263 elem = elem->next;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
264 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
265 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
266 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
267 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
268
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
269 /* Remove a single entry from the hash table given a pointer to that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
270 ** element and a hash on the element's key.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
271 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
272 static void removeElementGivenHash(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
273 Hash *pH, /* The pH containing "elem" */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
274 HashElem* elem, /* The element to be removed from the pH */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
275 int h /* Hash value for the element */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
276 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
277 struct _ht *pEntry;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
278 if( elem->prev ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
279 elem->prev->next = elem->next;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
280 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
281 pH->first = elem->next;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
282 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
283 if( elem->next ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
284 elem->next->prev = elem->prev;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
285 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
286 pEntry = &pH->ht[h];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
287 if( pEntry->chain==elem ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
288 pEntry->chain = elem->next;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
289 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
290 pEntry->count--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
291 if( pEntry->count<=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
292 pEntry->chain = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
293 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
294 if( pH->copyKey && elem->pKey ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
295 pH->xFree(elem->pKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
296 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
297 pH->xFree( elem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
298 pH->count--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
299 if( pH->count<=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
300 assert( pH->first==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
301 assert( pH->count==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
302 sqlite3HashClear(pH);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
303 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
304 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
305
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
306 /* Attempt to locate an element of the hash table pH with a key
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
307 ** that matches pKey,nKey. Return the data for this element if it is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
308 ** found, or NULL if there is no match.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
309 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
310 void *sqlite3HashFind(const Hash *pH, const void *pKey, int nKey){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
311 int h; /* A hash on key */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
312 HashElem *elem; /* The element that matches key */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
313 int (*xHash)(const void*,int); /* The hash function */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
314
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
315 if( pH==0 || pH->ht==0 ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
316 xHash = hashFunction(pH->keyClass);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
317 assert( xHash!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
318 h = (*xHash)(pKey,nKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
319 assert( (pH->htsize & (pH->htsize-1))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
320 elem = findElementGivenHash(pH,pKey,nKey, h & (pH->htsize-1));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
321 return elem ? elem->data : 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
322 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
323
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
324 /* Insert an element into the hash table pH. The key is pKey,nKey
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
325 ** and the data is "data".
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
326 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
327 ** If no element exists with a matching key, then a new
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
328 ** element is created. A copy of the key is made if the copyKey
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
329 ** flag is set. NULL is returned.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
330 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
331 ** If another element already exists with the same key, then the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
332 ** new data replaces the old data and the old data is returned.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
333 ** The key is not copied in this instance. If a malloc fails, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
334 ** the new data is returned and the hash table is unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
335 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
336 ** If the "data" parameter to this function is NULL, then the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
337 ** element corresponding to "key" is removed from the hash table.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
338 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
339 void *sqlite3HashInsert(Hash *pH, const void *pKey, int nKey, void *data){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
340 int hraw; /* Raw hash value of the key */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
341 int h; /* the hash of the key modulo hash table size */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
342 HashElem *elem; /* Used to loop thru the element list */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
343 HashElem *new_elem; /* New element added to the pH */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
344 int (*xHash)(const void*,int); /* The hash function */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
345
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
346 assert( pH!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
347 xHash = hashFunction(pH->keyClass);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
348 assert( xHash!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
349 hraw = (*xHash)(pKey, nKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
350 assert( (pH->htsize & (pH->htsize-1))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
351 h = hraw & (pH->htsize-1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
352 elem = findElementGivenHash(pH,pKey,nKey,h);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
353 if( elem ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
354 void *old_data = elem->data;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
355 if( data==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
356 removeElementGivenHash(pH,elem,h);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
357 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
358 elem->data = data;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
359 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
360 return old_data;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
361 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
362 if( data==0 ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
363 new_elem = (HashElem*)pH->xMalloc( sizeof(HashElem) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
364 if( new_elem==0 ) return data;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
365 if( pH->copyKey && pKey!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
366 new_elem->pKey = pH->xMalloc( nKey );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
367 if( new_elem->pKey==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
368 pH->xFree(new_elem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
369 return data;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
370 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
371 memcpy((void*)new_elem->pKey, pKey, nKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
372 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
373 new_elem->pKey = (void*)pKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
374 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
375 new_elem->nKey = nKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
376 pH->count++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
377 if( pH->htsize==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
378 rehash(pH,8);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
379 if( pH->htsize==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
380 pH->count = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
381 pH->xFree(new_elem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
382 return data;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
383 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
384 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
385 if( pH->count > pH->htsize ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
386 rehash(pH,pH->htsize*2);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
387 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
388 assert( pH->htsize>0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
389 assert( (pH->htsize & (pH->htsize-1))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
390 h = hraw & (pH->htsize-1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
391 insertElement(pH, &pH->ht[h], new_elem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
392 new_elem->data = data;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
393 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
394 }