OLD | NEW |
1 /* | 1 /* |
2 ** 2008 February 16 | 2 ** 2008 February 16 |
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 ** |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 u32 h; | 170 u32 h; |
171 if( p==0 ) return SQLITE_OK; | 171 if( p==0 ) return SQLITE_OK; |
172 assert( i>0 ); | 172 assert( i>0 ); |
173 assert( i<=p->iSize ); | 173 assert( i<=p->iSize ); |
174 i--; | 174 i--; |
175 while((p->iSize > BITVEC_NBIT) && p->iDivisor) { | 175 while((p->iSize > BITVEC_NBIT) && p->iDivisor) { |
176 u32 bin = i/p->iDivisor; | 176 u32 bin = i/p->iDivisor; |
177 i = i%p->iDivisor; | 177 i = i%p->iDivisor; |
178 if( p->u.apSub[bin]==0 ){ | 178 if( p->u.apSub[bin]==0 ){ |
179 p->u.apSub[bin] = sqlite3BitvecCreate( p->iDivisor ); | 179 p->u.apSub[bin] = sqlite3BitvecCreate( p->iDivisor ); |
180 if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM; | 180 if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM_BKPT; |
181 } | 181 } |
182 p = p->u.apSub[bin]; | 182 p = p->u.apSub[bin]; |
183 } | 183 } |
184 if( p->iSize<=BITVEC_NBIT ){ | 184 if( p->iSize<=BITVEC_NBIT ){ |
185 p->u.aBitmap[i/BITVEC_SZELEM] |= 1 << (i&(BITVEC_SZELEM-1)); | 185 p->u.aBitmap[i/BITVEC_SZELEM] |= 1 << (i&(BITVEC_SZELEM-1)); |
186 return SQLITE_OK; | 186 return SQLITE_OK; |
187 } | 187 } |
188 h = BITVEC_HASH(i++); | 188 h = BITVEC_HASH(i++); |
189 /* if there wasn't a hash collision, and this doesn't */ | 189 /* if there wasn't a hash collision, and this doesn't */ |
190 /* completely fill the hash, then just add it without */ | 190 /* completely fill the hash, then just add it without */ |
(...skipping 14 matching lines...) Expand all Loading... |
205 } while( p->u.aHash[h] ); | 205 } while( p->u.aHash[h] ); |
206 /* we didn't find it in the hash. h points to the first */ | 206 /* we didn't find it in the hash. h points to the first */ |
207 /* available free spot. check to see if this is going to */ | 207 /* available free spot. check to see if this is going to */ |
208 /* make our hash too "full". */ | 208 /* make our hash too "full". */ |
209 bitvec_set_rehash: | 209 bitvec_set_rehash: |
210 if( p->nSet>=BITVEC_MXHASH ){ | 210 if( p->nSet>=BITVEC_MXHASH ){ |
211 unsigned int j; | 211 unsigned int j; |
212 int rc; | 212 int rc; |
213 u32 *aiValues = sqlite3StackAllocRaw(0, sizeof(p->u.aHash)); | 213 u32 *aiValues = sqlite3StackAllocRaw(0, sizeof(p->u.aHash)); |
214 if( aiValues==0 ){ | 214 if( aiValues==0 ){ |
215 return SQLITE_NOMEM; | 215 return SQLITE_NOMEM_BKPT; |
216 }else{ | 216 }else{ |
217 memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash)); | 217 memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash)); |
218 memset(p->u.apSub, 0, sizeof(p->u.apSub)); | 218 memset(p->u.apSub, 0, sizeof(p->u.apSub)); |
219 p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR; | 219 p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR; |
220 rc = sqlite3BitvecSet(p, i); | 220 rc = sqlite3BitvecSet(p, i); |
221 for(j=0; j<BITVEC_NINT; j++){ | 221 for(j=0; j<BITVEC_NINT; j++){ |
222 if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]); | 222 if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]); |
223 } | 223 } |
224 sqlite3StackFree(0, aiValues); | 224 sqlite3StackFree(0, aiValues); |
225 return rc; | 225 return rc; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 286 } |
287 | 287 |
288 /* | 288 /* |
289 ** Return the value of the iSize parameter specified when Bitvec *p | 289 ** Return the value of the iSize parameter specified when Bitvec *p |
290 ** was created. | 290 ** was created. |
291 */ | 291 */ |
292 u32 sqlite3BitvecSize(Bitvec *p){ | 292 u32 sqlite3BitvecSize(Bitvec *p){ |
293 return p->iSize; | 293 return p->iSize; |
294 } | 294 } |
295 | 295 |
296 #ifndef SQLITE_OMIT_BUILTIN_TEST | 296 #ifndef SQLITE_UNTESTABLE |
297 /* | 297 /* |
298 ** Let V[] be an array of unsigned characters sufficient to hold | 298 ** Let V[] be an array of unsigned characters sufficient to hold |
299 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N. | 299 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N. |
300 ** Then the following macros can be used to set, clear, or test | 300 ** Then the following macros can be used to set, clear, or test |
301 ** individual bits within V. | 301 ** individual bits within V. |
302 */ | 302 */ |
303 #define SETBIT(V,I) V[I>>3] |= (1<<(I&7)) | 303 #define SETBIT(V,I) V[I>>3] |= (1<<(I&7)) |
304 #define CLEARBIT(V,I) V[I>>3] &= ~(1<<(I&7)) | 304 #define CLEARBIT(V,I) V[I>>3] &= ~(1<<(I&7)) |
305 #define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0 | 305 #define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0 |
306 | 306 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 401 } |
402 } | 402 } |
403 | 403 |
404 /* Free allocated structure */ | 404 /* Free allocated structure */ |
405 bitvec_end: | 405 bitvec_end: |
406 sqlite3_free(pTmpSpace); | 406 sqlite3_free(pTmpSpace); |
407 sqlite3_free(pV); | 407 sqlite3_free(pV); |
408 sqlite3BitvecDestroy(pBitvec); | 408 sqlite3BitvecDestroy(pBitvec); |
409 return rc; | 409 return rc; |
410 } | 410 } |
411 #endif /* SQLITE_OMIT_BUILTIN_TEST */ | 411 #endif /* SQLITE_UNTESTABLE */ |
OLD | NEW |