#include "fts3_hash.h"
-static void *malloc_and_zero(int n){
- void *p = malloc(n);
+/*
+** Malloc and Free functions
+*/
+static void *fts3HashMalloc(int n){
+ void *p = sqlite3_malloc(n);
if( p ){
memset(p, 0, n);
}
return p;
}
+static void fts3HashFree(void *p){
+ sqlite3_free(p);
+}
/* Turn bulk memory into a hash table object by initializing the
** fields of the Hash structure.
pNew->count = 0;
pNew->htsize = 0;
pNew->ht = 0;
- pNew->xMalloc = malloc_and_zero;
- pNew->xFree = free;
}
/* Remove all entries from a hash table. Reclaim all memory.
assert( pH!=0 );
elem = pH->first;
pH->first = 0;
- if( pH->ht ) pH->xFree(pH->ht);
+ fts3HashFree(pH->ht);
pH->ht = 0;
pH->htsize = 0;
while( elem ){
fts3HashElem *next_elem = elem->next;
if( pH->copyKey && elem->pKey ){
- pH->xFree(elem->pKey);
+ fts3HashFree(elem->pKey);
}
- pH->xFree(elem);
+ fts3HashFree(elem);
elem = next_elem;
}
pH->count = 0;
/*
** Hash and comparison functions when the mode is FTS3_HASH_STRING
*/
-static int strHash(const void *pKey, int nKey){
+static int fts3StrHash(const void *pKey, int nKey){
const char *z = (const char *)pKey;
int h = 0;
if( nKey<=0 ) nKey = (int) strlen(z);
}
return h & 0x7fffffff;
}
-static int strCompare(const void *pKey1, int n1, const void *pKey2, int n2){
+static int fts3StrCompare(const void *pKey1, int n1, const void *pKey2, int n2){
if( n1!=n2 ) return 1;
return strncmp((const char*)pKey1,(const char*)pKey2,n1);
}
/*
** Hash and comparison functions when the mode is FTS3_HASH_BINARY
*/
-static int binHash(const void *pKey, int nKey){
+static int fts3BinHash(const void *pKey, int nKey){
int h = 0;
const char *z = (const char *)pKey;
while( nKey-- > 0 ){
}
return h & 0x7fffffff;
}
-static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
+static int fts3BinCompare(const void *pKey1, int n1, const void *pKey2, int n2){
if( n1!=n2 ) return 1;
return memcmp(pKey1,pKey2,n1);
}
*/
static int (*hashFunction(int keyClass))(const void*,int){
if( keyClass==FTS3_HASH_STRING ){
- return &strHash;
+ return &fts3StrHash;
}else{
assert( keyClass==FTS3_HASH_BINARY );
- return &binHash;
+ return &fts3BinHash;
}
}
*/
static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
if( keyClass==FTS3_HASH_STRING ){
- return &strCompare;
+ return &fts3StrCompare;
}else{
assert( keyClass==FTS3_HASH_BINARY );
- return &binCompare;
+ return &fts3BinCompare;
}
}
/* Link an element into the hash table
*/
-static void insertElement(
+static void fts3HashInsertElement(
fts3Hash *pH, /* The complete hash table */
struct _fts3ht *pEntry, /* The entry into which pNew is inserted */
fts3HashElem *pNew /* The element to be inserted */
** "new_size" must be a power of 2. The hash table might fail
** to resize if sqliteMalloc() fails.
*/
-static void rehash(fts3Hash *pH, int new_size){
+static void fts3Rehash(fts3Hash *pH, int new_size){
struct _fts3ht *new_ht; /* The new hash table */
fts3HashElem *elem, *next_elem; /* For looping over existing elements */
int (*xHash)(const void*,int); /* The hash function */
assert( (new_size & (new_size-1))==0 );
- new_ht = (struct _fts3ht *)pH->xMalloc( new_size*sizeof(struct _fts3ht) );
+ new_ht = (struct _fts3ht *)fts3HashMalloc( new_size*sizeof(struct _fts3ht) );
if( new_ht==0 ) return;
- if( pH->ht ) pH->xFree(pH->ht);
+ fts3HashFree(pH->ht);
pH->ht = new_ht;
pH->htsize = new_size;
xHash = hashFunction(pH->keyClass);
for(elem=pH->first, pH->first=0; elem; elem = next_elem){
int h = (*xHash)(elem->pKey, elem->nKey) & (new_size-1);
next_elem = elem->next;
- insertElement(pH, &new_ht[h], elem);
+ fts3HashInsertElement(pH, &new_ht[h], elem);
}
}
** hash table that matches the given key. The hash for this key has
** already been computed and is passed as the 4th parameter.
*/
-static fts3HashElem *findElementGivenHash(
+static fts3HashElem *fts3FindElementByHash(
const fts3Hash *pH, /* The pH to be searched */
const void *pKey, /* The key we are searching for */
int nKey,
/* Remove a single entry from the hash table given a pointer to that
** element and a hash on the element's key.
*/
-static void removeElementGivenHash(
+static void fts3RemoveElementByHash(
fts3Hash *pH, /* The pH containing "elem" */
fts3HashElem* elem, /* The element to be removed from the pH */
int h /* Hash value for the element */
pEntry->chain = 0;
}
if( pH->copyKey && elem->pKey ){
- pH->xFree(elem->pKey);
+ fts3HashFree(elem->pKey);
}
- pH->xFree( elem );
+ fts3HashFree( elem );
pH->count--;
if( pH->count<=0 ){
assert( pH->first==0 );
assert( xHash!=0 );
h = (*xHash)(pKey,nKey);
assert( (pH->htsize & (pH->htsize-1))==0 );
- elem = findElementGivenHash(pH,pKey,nKey, h & (pH->htsize-1));
+ elem = fts3FindElementByHash(pH,pKey,nKey, h & (pH->htsize-1));
return elem ? elem->data : 0;
}
hraw = (*xHash)(pKey, nKey);
assert( (pH->htsize & (pH->htsize-1))==0 );
h = hraw & (pH->htsize-1);
- elem = findElementGivenHash(pH,pKey,nKey,h);
+ elem = fts3FindElementByHash(pH,pKey,nKey,h);
if( elem ){
void *old_data = elem->data;
if( data==0 ){
- removeElementGivenHash(pH,elem,h);
+ fts3RemoveElementByHash(pH,elem,h);
}else{
elem->data = data;
}
return old_data;
}
if( data==0 ) return 0;
- new_elem = (fts3HashElem*)pH->xMalloc( sizeof(fts3HashElem) );
+ new_elem = (fts3HashElem*)fts3HashMalloc( sizeof(fts3HashElem) );
if( new_elem==0 ) return data;
if( pH->copyKey && pKey!=0 ){
- new_elem->pKey = pH->xMalloc( nKey );
+ new_elem->pKey = fts3HashMalloc( nKey );
if( new_elem->pKey==0 ){
- pH->xFree(new_elem);
+ fts3HashFree(new_elem);
return data;
}
memcpy((void*)new_elem->pKey, pKey, nKey);
new_elem->nKey = nKey;
pH->count++;
if( pH->htsize==0 ){
- rehash(pH,8);
+ fts3Rehash(pH,8);
if( pH->htsize==0 ){
pH->count = 0;
- pH->xFree(new_elem);
+ fts3HashFree(new_elem);
return data;
}
}
if( pH->count > pH->htsize ){
- rehash(pH,pH->htsize*2);
+ fts3Rehash(pH,pH->htsize*2);
}
assert( pH->htsize>0 );
assert( (pH->htsize & (pH->htsize-1))==0 );
h = hraw & (pH->htsize-1);
- insertElement(pH, &pH->ht[h], new_elem);
+ fts3HashInsertElement(pH, &pH->ht[h], new_elem);
new_elem->data = data;
return 0;
}
-C get\srid\sof\sremaining\sGCC\s4.3\s-Wall\scompiler\swarnings\sby\sinitializing\stwo\svariables\sand\sone\sstructure\sproperly\s(although\sthe\scode\spath\swas\salready\srather\ssafe)\s(CVS\s4439)
-D 2007-09-20T11:34:18
+C Cleanup\sthe\shash\sfunctions\sin\sFTS3.\s(CVS\s4440)
+D 2007-09-20T12:53:28
F Makefile.in cbfb898945536a8f9ea8b897e1586dd1fdbcc5db
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
F ext/fts3/fts3.c 6b390b5054f9267ee5778dccffc856a3d70e7b70
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
-F ext/fts3/fts3_hash.c 84654768178452b00bbc986dd878a8299dc1e3dc
-F ext/fts3/fts3_hash.h af585d6867d478fc0457f64cfaae60e09541e63a
+F ext/fts3/fts3_hash.c 1c2dc969a5b485848fb804c0ac41a046f18a09c9
+F ext/fts3/fts3_hash.h 004b759e1602ff16dfa02fea3ca1c77336ad6798
F ext/fts3/fts3_icu.c 35a5d08fea8f12edecb8a58fdb33452eb8f17948
F ext/fts3/fts3_porter.c a3e823a0a8fbb038750c9aa55043e19bdb08eacb
F ext/fts3/fts3_tokenizer.c 81e7604555b24dce6bc487d8169ca4ef51c71e4c
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P c2ac43a4ef674c0202d5bd1ec57fc25c89d0554e
-R b948484588679e72e10618f1789eb46d
-U rse
-Z 4b5325865a92adc308765583c725dbd7
+P d748694f8d9b14d98b6fe7ceb404754692761705
+R 8fa4ab546f014755f6bea9393d1cafc9
+U drh
+Z ed8c3b918a22b61a19882d5a8de5f03a