fts1_hash.h

Go to the documentation of this file.
00001 /*
00002 ** 2001 September 22
00003 **
00004 ** The author disclaims copyright to this source code.  In place of
00005 ** a legal notice, here is a blessing:
00006 **
00007 **    May you do good and not evil.
00008 **    May you find forgiveness for yourself and forgive others.
00009 **    May you share freely, never taking more than you give.
00010 **
00011 *************************************************************************
00012 ** This is the header file for the generic hash-table implemenation
00013 ** used in SQLite.  We've modified it slightly to serve as a standalone
00014 ** hash table implementation for the full-text indexing module.
00015 **
00016 */
00017 #ifndef _FTS1_HASH_H_
00018 #define _FTS1_HASH_H_
00019 
00020 /* Forward declarations of structures. */
00021 typedef struct fts1Hash fts1Hash;
00022 typedef struct fts1HashElem fts1HashElem;
00023 
00024 /* A complete hash table is an instance of the following structure.
00025 ** The internals of this structure are intended to be opaque -- client
00026 ** code should not attempt to access or modify the fields of this structure
00027 ** directly.  Change this structure only by using the routines below.
00028 ** However, many of the "procedures" and "functions" for modifying and
00029 ** accessing this structure are really macros, so we can't really make
00030 ** this structure opaque.
00031 */
00032 struct fts1Hash {
00033   char keyClass;          /* HASH_INT, _POINTER, _STRING, _BINARY */
00034   char copyKey;           /* True if copy of key made on insert */
00035   int count;              /* Number of entries in this table */
00036   fts1HashElem *first;    /* The first element of the array */
00037   void *(*xMalloc)(int);  /* malloc() function to use */
00038   void (*xFree)(void *);  /* free() function to use */
00039   int htsize;             /* Number of buckets in the hash table */
00040   struct _fts1ht {        /* the hash table */
00041     int count;               /* Number of entries with this hash */
00042     fts1HashElem *chain;     /* Pointer to first entry with this hash */
00043   } *ht;
00044 };
00045 
00046 /* Each element in the hash table is an instance of the following 
00047 ** structure.  All elements are stored on a single doubly-linked list.
00048 **
00049 ** Again, this structure is intended to be opaque, but it can't really
00050 ** be opaque because it is used by macros.
00051 */
00052 struct fts1HashElem {
00053   fts1HashElem *next, *prev; /* Next and previous elements in the table */
00054   void *data;                /* Data associated with this element */
00055   void *pKey; int nKey;      /* Key associated with this element */
00056 };
00057 
00058 /*
00059 ** There are 2 different modes of operation for a hash table:
00060 **
00061 **   FTS1_HASH_STRING        pKey points to a string that is nKey bytes long
00062 **                           (including the null-terminator, if any).  Case
00063 **                           is respected in comparisons.
00064 **
00065 **   FTS1_HASH_BINARY        pKey points to binary data nKey bytes long. 
00066 **                           memcmp() is used to compare keys.
00067 **
00068 ** A copy of the key is made if the copyKey parameter to fts1HashInit is 1.  
00069 */
00070 #define FTS1_HASH_STRING    1
00071 #define FTS1_HASH_BINARY    2
00072 
00073 /*
00074 ** Access routines.  To delete, insert a NULL pointer.
00075 */
00076 void sqlite3Fts1HashInit(fts1Hash*, int keytype, int copyKey);
00077 void *sqlite3Fts1HashInsert(fts1Hash*, const void *pKey, int nKey, void *pData);
00078 void *sqlite3Fts1HashFind(const fts1Hash*, const void *pKey, int nKey);
00079 void sqlite3Fts1HashClear(fts1Hash*);
00080 
00081 /*
00082 ** Shorthand for the functions above
00083 */
00084 #define fts1HashInit   sqlite3Fts1HashInit
00085 #define fts1HashInsert sqlite3Fts1HashInsert
00086 #define fts1HashFind   sqlite3Fts1HashFind
00087 #define fts1HashClear  sqlite3Fts1HashClear
00088 
00089 /*
00090 ** Macros for looping over all elements of a hash table.  The idiom is
00091 ** like this:
00092 **
00093 **   fts1Hash h;
00094 **   fts1HashElem *p;
00095 **   ...
00096 **   for(p=fts1HashFirst(&h); p; p=fts1HashNext(p)){
00097 **     SomeStructure *pData = fts1HashData(p);
00098 **     // do something with pData
00099 **   }
00100 */
00101 #define fts1HashFirst(H)  ((H)->first)
00102 #define fts1HashNext(E)   ((E)->next)
00103 #define fts1HashData(E)   ((E)->data)
00104 #define fts1HashKey(E)    ((E)->pKey)
00105 #define fts1HashKeysize(E) ((E)->nKey)
00106 
00107 /*
00108 ** Number of entries in a hash table
00109 */
00110 #define fts1HashCount(H)  ((H)->count)
00111 
00112 #endif /* _FTS1_HASH_H_ */

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:53 2011 by Doxygen 1.6.1