Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

sfghash.h

Go to the documentation of this file.
00001 /*
00002 *
00003 *  sfghash.h
00004 *
00005 *  generic hash table - stores and maps key + data pairs
00006 *
00007 *  Copyright (C) 2001 Marc A Norton
00008 *
00009 */
00010 
00011 #ifndef _SFGHASH_
00012 #define _SFGHASH_
00013 
00014 #include <stdlib.h>
00015 #include <string.h>
00016 #include <time.h>
00017 
00018 #include "sfhashfcn.h"
00019 
00020 /*
00021 *   ERROR DEFINES
00022 */
00023 #define SFGHASH_NOMEM    -2
00024 #define SFGHASH_ERR      -1
00025 #define SFGHASH_OK        0
00026 #define SFGHASH_INTABLE   1
00027 
00028 /* 
00029 *  Flags for ghash_new: userkeys 
00030 */
00031 #define GH_COPYKEYS 0
00032 #define GH_USERKEYS 1
00033 
00034 /*
00035 *   Generic HASH NODE
00036 */
00037 typedef struct _sfghash_node
00038 {
00039   struct _sfghash_node * next, * prev;
00040 
00041   void * key;   /* Copy of, or Pointer to, the Users key */
00042   void * data;  /* Pointer to the users data, this is never copied! */
00043      
00044 } SFGHASH_NODE;
00045 
00046 /*
00047 *    Generic HASH table
00048 */
00049 typedef struct _sfghash
00050 {
00051   SFHASHFCN    * sfhashfcn;
00052   int          keysize;   /* bytes in key, if < 0 -> keys are strings */
00053   int          userkey;   /* user owns the key */
00054 
00055   SFGHASH_NODE ** table;  /* array of node ptr's */
00056   int             nrows;  /* # rows int the hash table use a prime number 211, 9871 */
00057 
00058   unsigned       count;  /* total # nodes in table */
00059 
00060   void         (*userfree)( void * );  
00061 
00062   int            crow;    // findfirst/next row in table
00063   SFGHASH_NODE * cnode; // findfirst/next node ptr
00064 
00065   int splay;
00066 
00067 } SFGHASH, SFDICT;
00068 
00069 
00070 /*
00071 *   HASH PROTOTYPES
00072 */
00073 SFGHASH * sfghash_new( int nrows, int keysize, int userkeys, void (*userfree)(void*p) );
00074 void      sfghash_delete( SFGHASH * h );
00075 int       sfghash_add ( SFGHASH * h, void * key, void * data );
00076 int       sfghash_remove( SFGHASH * h, void * key);
00077 int       sfghash_count( SFGHASH * h);
00078 void    * sfghash_find( SFGHASH * h, void * key );
00079 SFGHASH_NODE * sfghash_findfirst( SFGHASH * h );
00080 SFGHASH_NODE * sfghash_findnext ( SFGHASH * h );
00081 
00082 /*
00083 *  ATOM PROTOTYPES  - A Global Hash of String+Data Pointers
00084 *  this could be generalized to do a Global ptr to ptr map as well....
00085 *  
00086 */
00087 int    sfatom_setsize( int n );
00088 int    sfatom_init();
00089 int    sfatom_reset();
00090 int    sfatom_add(char * str, void * data);
00091 int    sfatom_remove(char * str);
00092 int    sfatom_count();
00093 void * sfatom_find(char * str);
00094 SFGHASH_NODE * sfatom_findfirst();
00095 SFGHASH_NODE * sfatom_findnext();
00096 
00097 #endif
00098 

Generated on Sun May 14 14:51:18 2006 by  doxygen 1.4.2