fts2_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 _FTS2_HASH_H_
00018 #define _FTS2_HASH_H_
00019 
00020 /* Forward declarations of structures. */
00021 typedef struct fts2Hash fts2Hash;
00022 typedef struct fts2HashElem fts2HashElem;
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 fts2Hash {
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   fts2HashElem *first;    /* The first element of the array */
00037   int htsize;             /* Number of buckets in the hash table */
00038   struct _fts2ht {        /* the hash table */
00039     int count;               /* Number of entries with this hash */
00040     fts2HashElem *chain;     /* Pointer to first entry with this hash */
00041   } *ht;
00042 };
00043 
00044 /* Each element in the hash table is an instance of the following 
00045 ** structure.  All elements are stored on a single doubly-linked list.
00046 **
00047 ** Again, this structure is intended to be opaque, but it can't really
00048 ** be opaque because it is used by macros.
00049 */
00050 struct fts2HashElem {
00051   fts2HashElem *next, *prev; /* Next and previous elements in the table */
00052   void *data;                /* Data associated with this element */
00053   void *pKey; int nKey;      /* Key associated with this element */
00054 };
00055 
00056 /*
00057 ** There are 2 different modes of operation for a hash table:
00058 **
00059 **   FTS2_HASH_STRING        pKey points to a string that is nKey bytes long
00060 **                           (including the null-terminator, if any).  Case
00061 **                           is respected in comparisons.
00062 **
00063 **   FTS2_HASH_BINARY        pKey points to binary data nKey bytes long. 
00064 **                           memcmp() is used to compare keys.
00065 **
00066 ** A copy of the key is made if the copyKey parameter to fts2HashInit is 1.  
00067 */
00068 #define FTS2_HASH_STRING    1
00069 #define FTS2_HASH_BINARY    2
00070 
00071 /*
00072 ** Access routines.  To delete, insert a NULL pointer.
00073 */
00074 void sqlite3Fts2HashInit(fts2Hash*, int keytype, int copyKey);
00075 void *sqlite3Fts2HashInsert(fts2Hash*, const void *pKey, int nKey, void *pData);
00076 void *sqlite3Fts2HashFind(const fts2Hash*, const void *pKey, int nKey);
00077 void sqlite3Fts2HashClear(fts2Hash*);
00078 
00079 /*
00080 ** Shorthand for the functions above
00081 */
00082 #define fts2HashInit   sqlite3Fts2HashInit
00083 #define fts2HashInsert sqlite3Fts2HashInsert
00084 #define fts2HashFind   sqlite3Fts2HashFind
00085 #define fts2HashClear  sqlite3Fts2HashClear
00086 
00087 /*
00088 ** Macros for looping over all elements of a hash table.  The idiom is
00089 ** like this:
00090 **
00091 **   fts2Hash h;
00092 **   fts2HashElem *p;
00093 **   ...
00094 **   for(p=fts2HashFirst(&h); p; p=fts2HashNext(p)){
00095 **     SomeStructure *pData = fts2HashData(p);
00096 **     // do something with pData
00097 **   }
00098 */
00099 #define fts2HashFirst(H)  ((H)->first)
00100 #define fts2HashNext(E)   ((E)->next)
00101 #define fts2HashData(E)   ((E)->data)
00102 #define fts2HashKey(E)    ((E)->pKey)
00103 #define fts2HashKeysize(E) ((E)->nKey)
00104 
00105 /*
00106 ** Number of entries in a hash table
00107 */
00108 #define fts2HashCount(H)  ((H)->count)
00109 
00110 #endif /* _FTS2_HASH_H_ */

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