cloudy  trunk
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hash.h
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #ifndef _HASH_H_
5 #define _HASH_H_
6 
7 typedef struct entry entry;
8 /* Public data for hash element
9  -- data can either be an [i]nteger or a [p]ointer to something else,
10  reverse access to the key from the data can also be useful */
11 typedef struct {
12  union {
13  void *p;
14  int i;
15  };
16  void *key;
17  size_t lkey; /* Length of key */
18 } data_u;
19 
20 struct entry { /* Structure of individual entries in list */
21  data_u data; /* Data value */
22  unsigned long hashval; /* Cache hash value for use in later expansions */
23  entry *next; /* Next item in list */
24 };
25 
26 typedef struct {
27  unsigned long size, /* Size of active part of hash table */
28  frontmask, /* Mask for front part of hash table */
29  fullmask, /* Mask for both parts of hash table */
30  space, /* Table space allocated at present */
31  nelem; /* Number of elements present */
32  void (*freedata)(void *data); /* Function used to free data section */
33  entry **tab; /* Table of entry lists */
34  /* Hash function used for this table */
35  unsigned long (*hashfunction)(const void *t, const size_t len);
36 } hashtab;
37 
38 /* Create new hash table */
39 extern hashtab *newhash(void (*freedata)(void *));
40 
41 /* Remove all of hash table */
42 extern void freehash(hashtab *table);
43 
44 /* Look up entry */
45 extern data_u *lookup(const void *key, size_t lkey, const hashtab *table);
46 
47 /* Add new entry */
48 extern data_u *addentry(const void *key, size_t lkey, hashtab *table, int *exists);
49 
50 /* Determine maximum chain length */
51 extern int maxchain(const hashtab *table);
52 
53 /* Make list of data values */
54 extern unsigned long makelist(const hashtab *table, data_u **list,
55  const unsigned long nlist, int (*maskfun)(data_u *dat));
56 
57 /* Make list of data values */
58 extern unsigned long makeplist(const hashtab *table, void **list,
59  const unsigned long nlist, int (*maskfun)(data_u *dat));
60 
61 #endif /* _HASH_H_ */

Generated for cloudy by doxygen 1.8.1.1