1 /* @configure_input@ */
4 ** Copyright 1998-2002 University of Illinois Board of Trustees
5 ** Copyright 1998-2002 Mark D. Roth
6 ** All rights reserved.
8 ** @LISTHASH_PREFIX@_listhash.h - header file for listhash module
10 ** Mark D. Roth <roth@uiuc.edu>
11 ** Campus Information Technologies and Educational Services
12 ** University of Illinois at Urbana-Champaign
15 #ifndef @LISTHASH_PREFIX@_LISTHASH_H
16 #define @LISTHASH_PREFIX@_LISTHASH_H
22 /***** list.c **********************************************************/
25 ** Comparison function (used to determine order of elements in a list)
26 ** returns less than, equal to, or greater than 0
27 ** if data1 is less than, equal to, or greater than data2
29 typedef int (*@LISTHASH_PREFIX@_cmpfunc_t
)(void *, void *);
32 ** Free function (for freeing allocated memory in each element)
34 typedef void (*@LISTHASH_PREFIX@_freefunc_t
)(void *);
37 ** Plugin function for @LISTHASH_PREFIX@_list_iterate()
39 typedef int (*@LISTHASH_PREFIX@_iterate_func_t
)(void *, void *);
42 ** Matching function (used to find elements in a list)
43 ** first argument is the data to search for
44 ** second argument is the list element it's being compared to
45 ** returns 0 if no match is found, non-zero otherwise
47 typedef int (*@LISTHASH_PREFIX@_matchfunc_t
)(void *, void *);
50 struct @LISTHASH_PREFIX@_node
53 struct @LISTHASH_PREFIX@_node
*next
;
54 struct @LISTHASH_PREFIX@_node
*prev
;
56 typedef struct @LISTHASH_PREFIX@_node
*@LISTHASH_PREFIX@_listptr_t
;
58 struct @LISTHASH_PREFIX@_list
60 @LISTHASH_PREFIX@_listptr_t first
;
61 @LISTHASH_PREFIX@_listptr_t last
;
62 @LISTHASH_PREFIX@_cmpfunc_t cmpfunc
;
66 typedef struct @LISTHASH_PREFIX@_list @LISTHASH_PREFIX@_list_t
;
69 /* values for flags */
70 #define LIST_USERFUNC 0 /* use cmpfunc() to order */
71 #define LIST_STACK 1 /* new elements go in front */
72 #define LIST_QUEUE 2 /* new elements go at the end */
75 /* reset a list pointer */
76 void @LISTHASH_PREFIX@
_listptr_reset(@LISTHASH_PREFIX@_listptr_t
*);
78 /* retrieve the data being pointed to */
79 void *@LISTHASH_PREFIX@
_listptr_data(@LISTHASH_PREFIX@_listptr_t
*);
81 /* creates a new, empty list */
82 @LISTHASH_PREFIX@_list_t
*@LISTHASH_PREFIX@
_list_new(int, @LISTHASH_PREFIX@_cmpfunc_t
);
84 /* call a function for every element in a list */
85 int @LISTHASH_PREFIX@
_list_iterate(@LISTHASH_PREFIX@_list_t
*,
86 @LISTHASH_PREFIX@_iterate_func_t
, void *);
89 void @LISTHASH_PREFIX@
_list_empty(@LISTHASH_PREFIX@_list_t
*,
90 @LISTHASH_PREFIX@_freefunc_t
);
92 /* remove and free() the entire list */
93 void @LISTHASH_PREFIX@
_list_free(@LISTHASH_PREFIX@_list_t
*,
94 @LISTHASH_PREFIX@_freefunc_t
);
97 int @LISTHASH_PREFIX@
_list_add(@LISTHASH_PREFIX@_list_t
*, void *);
99 /* removes an element from the list - returns -1 on error */
100 void @LISTHASH_PREFIX@
_list_del(@LISTHASH_PREFIX@_list_t
*,
101 @LISTHASH_PREFIX@_listptr_t
*);
103 /* returns 1 when valid data is returned, or 0 at end of list */
104 int @LISTHASH_PREFIX@
_list_next(@LISTHASH_PREFIX@_list_t
*,
105 @LISTHASH_PREFIX@_listptr_t
*);
107 /* returns 1 when valid data is returned, or 0 at end of list */
108 int @LISTHASH_PREFIX@
_list_prev(@LISTHASH_PREFIX@_list_t
*,
109 @LISTHASH_PREFIX@_listptr_t
*);
111 /* return 1 if the data matches a list entry, 0 otherwise */
112 int @LISTHASH_PREFIX@
_list_search(@LISTHASH_PREFIX@_list_t
*,
113 @LISTHASH_PREFIX@_listptr_t
*, void *,
114 @LISTHASH_PREFIX@_matchfunc_t
);
116 /* return number of elements from list */
117 unsigned int @LISTHASH_PREFIX@
_list_nents(@LISTHASH_PREFIX@_list_t
*);
119 /* adds elements from a string delimited by delim */
120 int @LISTHASH_PREFIX@
_list_add_str(@LISTHASH_PREFIX@_list_t
*, char *, char *);
122 /* string matching function */
123 int @LISTHASH_PREFIX@
_str_match(char *, char *);
126 /***** hash.c **********************************************************/
129 ** Hashing function (determines which bucket the given key hashes into)
130 ** first argument is the key to hash
131 ** second argument is the total number of buckets
132 ** returns the bucket number
134 typedef unsigned int (*@LISTHASH_PREFIX@_hashfunc_t
)(void *, unsigned int);
137 struct @LISTHASH_PREFIX@_hashptr
140 @LISTHASH_PREFIX@_listptr_t node
;
142 typedef struct @LISTHASH_PREFIX@_hashptr @LISTHASH_PREFIX@_hashptr_t
;
144 struct @LISTHASH_PREFIX@_hash
147 @LISTHASH_PREFIX@_list_t
**table
;
148 @LISTHASH_PREFIX@_hashfunc_t hashfunc
;
151 typedef struct @LISTHASH_PREFIX@_hash @LISTHASH_PREFIX@_hash_t
;
154 /* reset a hash pointer */
155 void @LISTHASH_PREFIX@
_hashptr_reset(@LISTHASH_PREFIX@_hashptr_t
*);
157 /* retrieve the data being pointed to */
158 void *@LISTHASH_PREFIX@
_hashptr_data(@LISTHASH_PREFIX@_hashptr_t
*);
160 /* default hash function, optimized for 7-bit strings */
161 unsigned int @LISTHASH_PREFIX@
_str_hashfunc(char *, unsigned int);
163 /* return number of elements from hash */
164 unsigned int @LISTHASH_PREFIX@
_hash_nents(@LISTHASH_PREFIX@_hash_t
*);
166 /* create a new hash */
167 @LISTHASH_PREFIX@_hash_t
*@LISTHASH_PREFIX@
_hash_new(int, @LISTHASH_PREFIX@_hashfunc_t
);
170 void @LISTHASH_PREFIX@
_hash_empty(@LISTHASH_PREFIX@_hash_t
*,
171 @LISTHASH_PREFIX@_freefunc_t
);
173 /* delete all the @LISTHASH_PREFIX@_nodes of the hash and clean up */
174 void @LISTHASH_PREFIX@
_hash_free(@LISTHASH_PREFIX@_hash_t
*,
175 @LISTHASH_PREFIX@_freefunc_t
);
177 /* returns 1 when valid data is returned, or 0 at end of list */
178 int @LISTHASH_PREFIX@
_hash_next(@LISTHASH_PREFIX@_hash_t
*,
179 @LISTHASH_PREFIX@_hashptr_t
*);
181 /* return 1 if the data matches a list entry, 0 otherwise */
182 int @LISTHASH_PREFIX@
_hash_search(@LISTHASH_PREFIX@_hash_t
*,
183 @LISTHASH_PREFIX@_hashptr_t
*, void *,
184 @LISTHASH_PREFIX@_matchfunc_t
);
186 /* return 1 if the key matches a list entry, 0 otherwise */
187 int @LISTHASH_PREFIX@
_hash_getkey(@LISTHASH_PREFIX@_hash_t
*,
188 @LISTHASH_PREFIX@_hashptr_t
*, void *,
189 @LISTHASH_PREFIX@_matchfunc_t
);
192 int @LISTHASH_PREFIX@
_hash_add(@LISTHASH_PREFIX@_hash_t
*, void *);
194 /* delete an entry */
195 int @LISTHASH_PREFIX@
_hash_del(@LISTHASH_PREFIX@_hash_t
*,
196 @LISTHASH_PREFIX@_hashptr_t
*);
202 #endif /* ! @LISTHASH_PREFIX@_LISTHASH_H */