Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
hash.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Hash
struct  Hash::_ht
struct  HashElem

Defines

#define SQLITE_HASH_STRING   3
#define SQLITE_HASH_BINARY   4
#define sqliteHashFirst(H)   ((H)->first)
#define sqliteHashNext(E)   ((E)->next)
#define sqliteHashData(E)   ((E)->data)
#define sqliteHashKey(E)   ((E)->pKey)
#define sqliteHashKeysize(E)   ((E)->nKey)
#define sqliteHashCount(H)   ((H)->count)

Typedefs

typedef struct Hash
typedef struct HashElem

Functions

void sqlite3HashInit (Hash *, int keytype, int copyKey)
voidsqlite3HashInsert (Hash *, const void *pKey, int nKey, void *pData)
voidsqlite3HashFind (const Hash *, const void *pKey, int nKey)
void sqlite3HashClear (Hash *)

Class Documentation

struct Hash::_ht

Definition at line 40 of file hash.h.

Collaboration diagram for Hash::_ht:
Class Members
HashElem * chain
int count
struct HashElem

Definition at line 52 of file hash.h.

Collaboration diagram for HashElem:
Class Members
void * data
HashElem * next
int nKey
void * pKey
HashElem * prev

Define Documentation

Definition at line 78 of file hash.h.

Definition at line 77 of file hash.h.

#define sqliteHashCount (   H)    ((H)->count)

Definition at line 109 of file hash.h.

#define sqliteHashData (   E)    ((E)->data)

Definition at line 102 of file hash.h.

#define sqliteHashFirst (   H)    ((H)->first)

Definition at line 100 of file hash.h.

#define sqliteHashKey (   E)    ((E)->pKey)

Definition at line 103 of file hash.h.

#define sqliteHashKeysize (   E)    ((E)->nKey)

Definition at line 104 of file hash.h.

#define sqliteHashNext (   E)    ((E)->next)

Definition at line 101 of file hash.h.


Typedef Documentation

typedef struct Hash

Definition at line 21 of file hash.h.

typedef struct HashElem

Definition at line 22 of file hash.h.


Function Documentation

Definition at line 52 of file hash.c.

                               {
  HashElem *elem;         /* For looping over all elements of the table */

  assert( pH!=0 );
  elem = pH->first;
  pH->first = 0;
  if( pH->ht ) pH->xFree(pH->ht);
  pH->ht = 0;
  pH->htsize = 0;
  while( elem ){
    HashElem *next_elem = elem->next;
    if( pH->copyKey && elem->pKey ){
      pH->xFree(elem->pKey);
    }
    pH->xFree(elem);
    elem = next_elem;
  }
  pH->count = 0;
}

Here is the caller graph for this function:

void* sqlite3HashFind ( const Hash ,
const void pKey,
int  nKey 
)

Definition at line 310 of file hash.c.

                                                                 {
  int h;             /* A hash on key */
  HashElem *elem;    /* The element that matches key */
  int (*xHash)(const void*,int);  /* The hash function */

  if( pH==0 || pH->ht==0 ) return 0;
  xHash = hashFunction(pH->keyClass);
  assert( xHash!=0 );
  h = (*xHash)(pKey,nKey);
  assert( (pH->htsize & (pH->htsize-1))==0 );
  elem = findElementGivenHash(pH,pKey,nKey, h & (pH->htsize-1));
  return elem ? elem->data : 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqlite3HashInit ( Hash ,
int  keytype,
int  copyKey 
)

Definition at line 32 of file hash.c.

                                                           {
  assert( pNew!=0 );
  assert( keyClass>=SQLITE_HASH_STRING && keyClass<=SQLITE_HASH_BINARY );
  pNew->keyClass = keyClass;
#if 0
  if( keyClass==SQLITE_HASH_POINTER || keyClass==SQLITE_HASH_INT ) copyKey = 0;
#endif
  pNew->copyKey = copyKey;
  pNew->first = 0;
  pNew->count = 0;
  pNew->htsize = 0;
  pNew->ht = 0;
  pNew->xMalloc = sqlite3MallocX;
  pNew->xFree = sqlite3FreeX;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* sqlite3HashInsert ( Hash ,
const void pKey,
int  nKey,
void pData 
)

Definition at line 339 of file hash.c.

                                                                         {
  int hraw;             /* Raw hash value of the key */
  int h;                /* the hash of the key modulo hash table size */
  HashElem *elem;       /* Used to loop thru the element list */
  HashElem *new_elem;   /* New element added to the pH */
  int (*xHash)(const void*,int);  /* The hash function */

  assert( pH!=0 );
  xHash = hashFunction(pH->keyClass);
  assert( xHash!=0 );
  hraw = (*xHash)(pKey, nKey);
  assert( (pH->htsize & (pH->htsize-1))==0 );
  h = hraw & (pH->htsize-1);
  elem = findElementGivenHash(pH,pKey,nKey,h);
  if( elem ){
    void *old_data = elem->data;
    if( data==0 ){
      removeElementGivenHash(pH,elem,h);
    }else{
      elem->data = data;
    }
    return old_data;
  }
  if( data==0 ) return 0;
  new_elem = (HashElem*)pH->xMalloc( sizeof(HashElem) );
  if( new_elem==0 ) return data;
  if( pH->copyKey && pKey!=0 ){
    new_elem->pKey = pH->xMalloc( nKey );
    if( new_elem->pKey==0 ){
      pH->xFree(new_elem);
      return data;
    }
    memcpy((void*)new_elem->pKey, pKey, nKey);
  }else{
    new_elem->pKey = (void*)pKey;
  }
  new_elem->nKey = nKey;
  pH->count++;
  if( pH->htsize==0 ){
    rehash(pH,8);
    if( pH->htsize==0 ){
      pH->count = 0;
      pH->xFree(new_elem);
      return data;
    }
  }
  if( pH->count > pH->htsize ){
    rehash(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);
  new_elem->data = data;
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: