1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
/* @configure_input@ */
/*
** Copyright 1998-2002 University of Illinois Board of Trustees
** Copyright 1998-2002 Mark D. Roth
** All rights reserved.
**
** @LISTHASH_PREFIX@_listhash.h - header file for listhash module
**
** Mark D. Roth <roth@uiuc.edu>
** Campus Information Technologies and Educational Services
** University of Illinois at Urbana-Champaign
*/
#ifndef @LISTHASH_PREFIX@_LISTHASH_H
#define @LISTHASH_PREFIX@_LISTHASH_H
/***** list.c **********************************************************/
/*
** Comparison function (used to determine order of elements in a list)
** returns less than, equal to, or greater than 0
** if data1 is less than, equal to, or greater than data2
*/
typedef int (*@LISTHASH_PREFIX@_cmpfunc_t)(void *, void *);
/*
** Free function (for freeing allocated memory in each element)
*/
typedef void (*@LISTHASH_PREFIX@_freefunc_t)(void *);
/*
** Plugin function for @LISTHASH_PREFIX@_list_iterate()
*/
typedef int (*@LISTHASH_PREFIX@_iterate_func_t)(void *, void *);
/*
** Matching function (used to find elements in a list)
** first argument is the data to search for
** second argument is the list element it's being compared to
** returns 0 if no match is found, non-zero otherwise
*/
typedef int (*@LISTHASH_PREFIX@_matchfunc_t)(void *, void *);
struct @LISTHASH_PREFIX@_node
{
void *data;
struct @LISTHASH_PREFIX@_node *next;
struct @LISTHASH_PREFIX@_node *prev;
};
typedef struct @LISTHASH_PREFIX@_node *@LISTHASH_PREFIX@_listptr_t;
struct @LISTHASH_PREFIX@_list
{
@LISTHASH_PREFIX@_listptr_t first;
@LISTHASH_PREFIX@_listptr_t last;
@LISTHASH_PREFIX@_cmpfunc_t cmpfunc;
int flags;
unsigned int nents;
};
typedef struct @LISTHASH_PREFIX@_list @LISTHASH_PREFIX@_list_t;
/* values for flags */
#define LIST_USERFUNC 0 /* use cmpfunc() to order */
#define LIST_STACK 1 /* new elements go in front */
#define LIST_QUEUE 2 /* new elements go at the end */
/* reset a list pointer */
void @LISTHASH_PREFIX@_listptr_reset(@LISTHASH_PREFIX@_listptr_t *);
/* retrieve the data being pointed to */
void *@LISTHASH_PREFIX@_listptr_data(@LISTHASH_PREFIX@_listptr_t *);
/* creates a new, empty list */
@LISTHASH_PREFIX@_list_t *@LISTHASH_PREFIX@_list_new(int, @LISTHASH_PREFIX@_cmpfunc_t);
/* call a function for every element in a list */
int @LISTHASH_PREFIX@_list_iterate(@LISTHASH_PREFIX@_list_t *,
@LISTHASH_PREFIX@_iterate_func_t, void *);
/* empty the list */
void @LISTHASH_PREFIX@_list_empty(@LISTHASH_PREFIX@_list_t *,
@LISTHASH_PREFIX@_freefunc_t);
/* remove and free() the entire list */
void @LISTHASH_PREFIX@_list_free(@LISTHASH_PREFIX@_list_t *,
@LISTHASH_PREFIX@_freefunc_t);
/* add elements */
int @LISTHASH_PREFIX@_list_add(@LISTHASH_PREFIX@_list_t *, void *);
/* removes an element from the list - returns -1 on error */
void @LISTHASH_PREFIX@_list_del(@LISTHASH_PREFIX@_list_t *,
@LISTHASH_PREFIX@_listptr_t *);
/* returns 1 when valid data is returned, or 0 at end of list */
int @LISTHASH_PREFIX@_list_next(@LISTHASH_PREFIX@_list_t *,
@LISTHASH_PREFIX@_listptr_t *);
/* returns 1 when valid data is returned, or 0 at end of list */
int @LISTHASH_PREFIX@_list_prev(@LISTHASH_PREFIX@_list_t *,
@LISTHASH_PREFIX@_listptr_t *);
/* return 1 if the data matches a list entry, 0 otherwise */
int @LISTHASH_PREFIX@_list_search(@LISTHASH_PREFIX@_list_t *,
@LISTHASH_PREFIX@_listptr_t *, void *,
@LISTHASH_PREFIX@_matchfunc_t);
/* return number of elements from list */
unsigned int @LISTHASH_PREFIX@_list_nents(@LISTHASH_PREFIX@_list_t *);
/* adds elements from a string delimited by delim */
int @LISTHASH_PREFIX@_list_add_str(@LISTHASH_PREFIX@_list_t *, char *, char *);
/* string matching function */
int @LISTHASH_PREFIX@_str_match(char *, char *);
/***** hash.c **********************************************************/
/*
** Hashing function (determines which bucket the given key hashes into)
** first argument is the key to hash
** second argument is the total number of buckets
** returns the bucket number
*/
typedef unsigned int (*@LISTHASH_PREFIX@_hashfunc_t)(void *, unsigned int);
struct @LISTHASH_PREFIX@_hashptr
{
int bucket;
@LISTHASH_PREFIX@_listptr_t node;
};
typedef struct @LISTHASH_PREFIX@_hashptr @LISTHASH_PREFIX@_hashptr_t;
struct @LISTHASH_PREFIX@_hash
{
int numbuckets;
@LISTHASH_PREFIX@_list_t **table;
@LISTHASH_PREFIX@_hashfunc_t hashfunc;
unsigned int nents;
};
typedef struct @LISTHASH_PREFIX@_hash @LISTHASH_PREFIX@_hash_t;
/* reset a hash pointer */
void @LISTHASH_PREFIX@_hashptr_reset(@LISTHASH_PREFIX@_hashptr_t *);
/* retrieve the data being pointed to */
void *@LISTHASH_PREFIX@_hashptr_data(@LISTHASH_PREFIX@_hashptr_t *);
/* default hash function, optimized for 7-bit strings */
unsigned int @LISTHASH_PREFIX@_str_hashfunc(char *, unsigned int);
/* return number of elements from hash */
unsigned int @LISTHASH_PREFIX@_hash_nents(@LISTHASH_PREFIX@_hash_t *);
/* create a new hash */
@LISTHASH_PREFIX@_hash_t *@LISTHASH_PREFIX@_hash_new(int, @LISTHASH_PREFIX@_hashfunc_t);
/* empty the hash */
void @LISTHASH_PREFIX@_hash_empty(@LISTHASH_PREFIX@_hash_t *,
@LISTHASH_PREFIX@_freefunc_t);
/* delete all the @LISTHASH_PREFIX@_nodes of the hash and clean up */
void @LISTHASH_PREFIX@_hash_free(@LISTHASH_PREFIX@_hash_t *,
@LISTHASH_PREFIX@_freefunc_t);
/* returns 1 when valid data is returned, or 0 at end of list */
int @LISTHASH_PREFIX@_hash_next(@LISTHASH_PREFIX@_hash_t *,
@LISTHASH_PREFIX@_hashptr_t *);
/* return 1 if the data matches a list entry, 0 otherwise */
int @LISTHASH_PREFIX@_hash_search(@LISTHASH_PREFIX@_hash_t *,
@LISTHASH_PREFIX@_hashptr_t *, void *,
@LISTHASH_PREFIX@_matchfunc_t);
/* return 1 if the key matches a list entry, 0 otherwise */
int @LISTHASH_PREFIX@_hash_getkey(@LISTHASH_PREFIX@_hash_t *,
@LISTHASH_PREFIX@_hashptr_t *, void *,
@LISTHASH_PREFIX@_matchfunc_t);
/* inserting data */
int @LISTHASH_PREFIX@_hash_add(@LISTHASH_PREFIX@_hash_t *, void *);
/* delete an entry */
int @LISTHASH_PREFIX@_hash_del(@LISTHASH_PREFIX@_hash_t *,
@LISTHASH_PREFIX@_hashptr_t *);
#endif /* ! @LISTHASH_PREFIX@_LISTHASH_H */
|