| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 ** (an arbitrary prime)in the hash function provided | 65 ** (an arbitrary prime)in the hash function provided |
| 66 ** no fewer collisions than the no-op *1. */ | 66 ** no fewer collisions than the no-op *1. */ |
| 67 #define BITVEC_HASH(X) (((X)*1)%BITVEC_NINT) | 67 #define BITVEC_HASH(X) (((X)*1)%BITVEC_NINT) |
| 68 | 68 |
| 69 #define BITVEC_NPTR (BITVEC_USIZE/sizeof(Bitvec *)) | 69 #define BITVEC_NPTR (BITVEC_USIZE/sizeof(Bitvec *)) |
| 70 | 70 |
| 71 | 71 |
| 72 /* | 72 /* |
| 73 ** A bitmap is an instance of the following structure. | 73 ** A bitmap is an instance of the following structure. |
| 74 ** | 74 ** |
| 75 ** This bitmap records the existance of zero or more bits | 75 ** This bitmap records the existence of zero or more bits |
| 76 ** with values between 1 and iSize, inclusive. | 76 ** with values between 1 and iSize, inclusive. |
| 77 ** | 77 ** |
| 78 ** There are three possible representations of the bitmap. | 78 ** There are three possible representations of the bitmap. |
| 79 ** If iSize<=BITVEC_NBIT, then Bitvec.u.aBitmap[] is a straight | 79 ** If iSize<=BITVEC_NBIT, then Bitvec.u.aBitmap[] is a straight |
| 80 ** bitmap. The least significant bit is bit 1. | 80 ** bitmap. The least significant bit is bit 1. |
| 81 ** | 81 ** |
| 82 ** If iSize>BITVEC_NBIT and iDivisor==0 then Bitvec.u.aHash[] is | 82 ** If iSize>BITVEC_NBIT and iDivisor==0 then Bitvec.u.aHash[] is |
| 83 ** a hash table that will hold up to BITVEC_MXHASH distinct values. | 83 ** a hash table that will hold up to BITVEC_MXHASH distinct values. |
| 84 ** | 84 ** |
| 85 ** Otherwise, the value i is redirected into one of BITVEC_NPTR | 85 ** Otherwise, the value i is redirected into one of BITVEC_NPTR |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 int sqlite3BitvecBuiltinTest(int sz, int *aOp){ | 333 int sqlite3BitvecBuiltinTest(int sz, int *aOp){ |
| 334 Bitvec *pBitvec = 0; | 334 Bitvec *pBitvec = 0; |
| 335 unsigned char *pV = 0; | 335 unsigned char *pV = 0; |
| 336 int rc = -1; | 336 int rc = -1; |
| 337 int i, nx, pc, op; | 337 int i, nx, pc, op; |
| 338 void *pTmpSpace; | 338 void *pTmpSpace; |
| 339 | 339 |
| 340 /* Allocate the Bitvec to be tested and a linear array of | 340 /* Allocate the Bitvec to be tested and a linear array of |
| 341 ** bits to act as the reference */ | 341 ** bits to act as the reference */ |
| 342 pBitvec = sqlite3BitvecCreate( sz ); | 342 pBitvec = sqlite3BitvecCreate( sz ); |
| 343 pV = sqlite3_malloc( (sz+7)/8 + 1 ); | 343 pV = sqlite3MallocZero( (sz+7)/8 + 1 ); |
| 344 pTmpSpace = sqlite3_malloc(BITVEC_SZ); | 344 pTmpSpace = sqlite3_malloc(BITVEC_SZ); |
| 345 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end; | 345 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end; |
| 346 memset(pV, 0, (sz+7)/8 + 1); | |
| 347 | 346 |
| 348 /* NULL pBitvec tests */ | 347 /* NULL pBitvec tests */ |
| 349 sqlite3BitvecSet(0, 1); | 348 sqlite3BitvecSet(0, 1); |
| 350 sqlite3BitvecClear(0, 1, pTmpSpace); | 349 sqlite3BitvecClear(0, 1, pTmpSpace); |
| 351 | 350 |
| 352 /* Run the program */ | 351 /* Run the program */ |
| 353 pc = 0; | 352 pc = 0; |
| 354 while( (op = aOp[pc])!=0 ){ | 353 while( (op = aOp[pc])!=0 ){ |
| 355 switch( op ){ | 354 switch( op ){ |
| 356 case 1: | 355 case 1: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 398 } |
| 400 | 399 |
| 401 /* Free allocated structure */ | 400 /* Free allocated structure */ |
| 402 bitvec_end: | 401 bitvec_end: |
| 403 sqlite3_free(pTmpSpace); | 402 sqlite3_free(pTmpSpace); |
| 404 sqlite3_free(pV); | 403 sqlite3_free(pV); |
| 405 sqlite3BitvecDestroy(pBitvec); | 404 sqlite3BitvecDestroy(pBitvec); |
| 406 return rc; | 405 return rc; |
| 407 } | 406 } |
| 408 #endif /* SQLITE_OMIT_BUILTIN_TEST */ | 407 #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| OLD | NEW |