/home66/gary/public_html/cloudy/c08_branch/source/hash.h

Go to the documentation of this file.
00001 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
00002  * others.  For conditions of distribution and use see copyright notice in license.txt */
00003 
00004 #ifndef _HASH_H_
00005 #define _HASH_H_
00006 
00007 typedef struct entry entry;
00008 /* Public data for hash element 
00009          -- data can either be an [i]nteger or a [p]ointer to something else,
00010    reverse access to the key from the data can also be useful */
00011 typedef struct {
00012         union {
00013     void *p;   
00014     int i;
00015         };
00016         void *key;
00017   size_t lkey;    /* Length of key */
00018 } data_u;
00019 
00020 struct entry { /* Structure of individual entries in list */
00021   data_u data; /* Data value    */
00022   unsigned long hashval; /* Cache hash value for use in later expansions */
00023   entry *next; /* Next item in list */
00024 };
00025 
00026 typedef struct {
00027   unsigned long size, /* Size of active part of hash table */
00028     frontmask,        /* Mask for front part of hash table */
00029     fullmask,         /* Mask for both parts of hash table */
00030     space,            /* Table space allocated at present */
00031     nelem;            /* Number of elements present */
00032   void (*freedata)(void *data); /* Function used to free data section */
00033   entry **tab;        /* Table of entry lists */
00034   /* Hash function used for this table */
00035   unsigned long (*hashfunction)(const void *t, const size_t len); 
00036 } hashtab;
00037 
00038 /* Create new hash table */
00039 extern hashtab *newhash(void (*freedata)(void *));
00040 
00041 /* Remove all of hash table */
00042 extern void freehash(hashtab *table);
00043 
00044 /* Look up entry */
00045 extern data_u *lookup(const void *key, size_t lkey, const hashtab *table);
00046 
00047 /* Add new entry */
00048 extern data_u *addentry(const void *key, size_t lkey, hashtab *table, int *exists);
00049 
00050 /* Determine maximum chain length */
00051 extern int maxchain(const hashtab *table);
00052 
00053 /* Make list of data values */
00054 extern unsigned long makelist(const hashtab *table, data_u **list, 
00055                                                                                                                         const unsigned long nlist, int (*maskfun)(data_u *dat));
00056 
00057 /* Make list of data values */
00058 extern unsigned long makeplist(const hashtab *table, void **list, 
00059                                                                                                                         const unsigned long nlist, int (*maskfun)(data_u *dat));
00060 
00061 #endif /* _HASH_H_ */

Generated on Mon Feb 16 12:01:15 2009 for cloudy by  doxygen 1.4.7