libtar-1.2.11 tarball sources, taken from Debian's orig tar
[libtar.git] / listhash / listhash.h.in
blobacf8ec594958e3482a5bcd05765ea0c8fde8ea08
1 /* @configure_input@ */
3 /*
4 ** Copyright 1998-2002 University of Illinois Board of Trustees
5 ** Copyright 1998-2002 Mark D. Roth
6 ** All rights reserved.
7 **
8 ** @LISTHASH_PREFIX@_listhash.h - header file for listhash module
9 **
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
19 /***** list.c **********************************************************/
22 ** Comparison function (used to determine order of elements in a list)
23 ** returns less than, equal to, or greater than 0
24 ** if data1 is less than, equal to, or greater than data2
26 typedef int (*@LISTHASH_PREFIX@_cmpfunc_t)(void *, void *);
29 ** Free function (for freeing allocated memory in each element)
31 typedef void (*@LISTHASH_PREFIX@_freefunc_t)(void *);
34 ** Plugin function for @LISTHASH_PREFIX@_list_iterate()
36 typedef int (*@LISTHASH_PREFIX@_iterate_func_t)(void *, void *);
39 ** Matching function (used to find elements in a list)
40 ** first argument is the data to search for
41 ** second argument is the list element it's being compared to
42 ** returns 0 if no match is found, non-zero otherwise
44 typedef int (*@LISTHASH_PREFIX@_matchfunc_t)(void *, void *);
47 struct @LISTHASH_PREFIX@_node
49 void *data;
50 struct @LISTHASH_PREFIX@_node *next;
51 struct @LISTHASH_PREFIX@_node *prev;
53 typedef struct @LISTHASH_PREFIX@_node *@LISTHASH_PREFIX@_listptr_t;
55 struct @LISTHASH_PREFIX@_list
57 @LISTHASH_PREFIX@_listptr_t first;
58 @LISTHASH_PREFIX@_listptr_t last;
59 @LISTHASH_PREFIX@_cmpfunc_t cmpfunc;
60 int flags;
61 unsigned int nents;
63 typedef struct @LISTHASH_PREFIX@_list @LISTHASH_PREFIX@_list_t;
66 /* values for flags */
67 #define LIST_USERFUNC 0 /* use cmpfunc() to order */
68 #define LIST_STACK 1 /* new elements go in front */
69 #define LIST_QUEUE 2 /* new elements go at the end */
72 /* reset a list pointer */
73 void @LISTHASH_PREFIX@_listptr_reset(@LISTHASH_PREFIX@_listptr_t *);
75 /* retrieve the data being pointed to */
76 void *@LISTHASH_PREFIX@_listptr_data(@LISTHASH_PREFIX@_listptr_t *);
78 /* creates a new, empty list */
79 @LISTHASH_PREFIX@_list_t *@LISTHASH_PREFIX@_list_new(int, @LISTHASH_PREFIX@_cmpfunc_t);
81 /* call a function for every element in a list */
82 int @LISTHASH_PREFIX@_list_iterate(@LISTHASH_PREFIX@_list_t *,
83 @LISTHASH_PREFIX@_iterate_func_t, void *);
85 /* empty the list */
86 void @LISTHASH_PREFIX@_list_empty(@LISTHASH_PREFIX@_list_t *,
87 @LISTHASH_PREFIX@_freefunc_t);
89 /* remove and free() the entire list */
90 void @LISTHASH_PREFIX@_list_free(@LISTHASH_PREFIX@_list_t *,
91 @LISTHASH_PREFIX@_freefunc_t);
93 /* add elements */
94 int @LISTHASH_PREFIX@_list_add(@LISTHASH_PREFIX@_list_t *, void *);
96 /* removes an element from the list - returns -1 on error */
97 void @LISTHASH_PREFIX@_list_del(@LISTHASH_PREFIX@_list_t *,
98 @LISTHASH_PREFIX@_listptr_t *);
100 /* returns 1 when valid data is returned, or 0 at end of list */
101 int @LISTHASH_PREFIX@_list_next(@LISTHASH_PREFIX@_list_t *,
102 @LISTHASH_PREFIX@_listptr_t *);
104 /* returns 1 when valid data is returned, or 0 at end of list */
105 int @LISTHASH_PREFIX@_list_prev(@LISTHASH_PREFIX@_list_t *,
106 @LISTHASH_PREFIX@_listptr_t *);
108 /* return 1 if the data matches a list entry, 0 otherwise */
109 int @LISTHASH_PREFIX@_list_search(@LISTHASH_PREFIX@_list_t *,
110 @LISTHASH_PREFIX@_listptr_t *, void *,
111 @LISTHASH_PREFIX@_matchfunc_t);
113 /* return number of elements from list */
114 unsigned int @LISTHASH_PREFIX@_list_nents(@LISTHASH_PREFIX@_list_t *);
116 /* adds elements from a string delimited by delim */
117 int @LISTHASH_PREFIX@_list_add_str(@LISTHASH_PREFIX@_list_t *, char *, char *);
119 /* string matching function */
120 int @LISTHASH_PREFIX@_str_match(char *, char *);
123 /***** hash.c **********************************************************/
126 ** Hashing function (determines which bucket the given key hashes into)
127 ** first argument is the key to hash
128 ** second argument is the total number of buckets
129 ** returns the bucket number
131 typedef unsigned int (*@LISTHASH_PREFIX@_hashfunc_t)(void *, unsigned int);
134 struct @LISTHASH_PREFIX@_hashptr
136 int bucket;
137 @LISTHASH_PREFIX@_listptr_t node;
139 typedef struct @LISTHASH_PREFIX@_hashptr @LISTHASH_PREFIX@_hashptr_t;
141 struct @LISTHASH_PREFIX@_hash
143 int numbuckets;
144 @LISTHASH_PREFIX@_list_t **table;
145 @LISTHASH_PREFIX@_hashfunc_t hashfunc;
146 unsigned int nents;
148 typedef struct @LISTHASH_PREFIX@_hash @LISTHASH_PREFIX@_hash_t;
151 /* reset a hash pointer */
152 void @LISTHASH_PREFIX@_hashptr_reset(@LISTHASH_PREFIX@_hashptr_t *);
154 /* retrieve the data being pointed to */
155 void *@LISTHASH_PREFIX@_hashptr_data(@LISTHASH_PREFIX@_hashptr_t *);
157 /* default hash function, optimized for 7-bit strings */
158 unsigned int @LISTHASH_PREFIX@_str_hashfunc(char *, unsigned int);
160 /* return number of elements from hash */
161 unsigned int @LISTHASH_PREFIX@_hash_nents(@LISTHASH_PREFIX@_hash_t *);
163 /* create a new hash */
164 @LISTHASH_PREFIX@_hash_t *@LISTHASH_PREFIX@_hash_new(int, @LISTHASH_PREFIX@_hashfunc_t);
166 /* empty the hash */
167 void @LISTHASH_PREFIX@_hash_empty(@LISTHASH_PREFIX@_hash_t *,
168 @LISTHASH_PREFIX@_freefunc_t);
170 /* delete all the @LISTHASH_PREFIX@_nodes of the hash and clean up */
171 void @LISTHASH_PREFIX@_hash_free(@LISTHASH_PREFIX@_hash_t *,
172 @LISTHASH_PREFIX@_freefunc_t);
174 /* returns 1 when valid data is returned, or 0 at end of list */
175 int @LISTHASH_PREFIX@_hash_next(@LISTHASH_PREFIX@_hash_t *,
176 @LISTHASH_PREFIX@_hashptr_t *);
178 /* return 1 if the data matches a list entry, 0 otherwise */
179 int @LISTHASH_PREFIX@_hash_search(@LISTHASH_PREFIX@_hash_t *,
180 @LISTHASH_PREFIX@_hashptr_t *, void *,
181 @LISTHASH_PREFIX@_matchfunc_t);
183 /* return 1 if the key matches a list entry, 0 otherwise */
184 int @LISTHASH_PREFIX@_hash_getkey(@LISTHASH_PREFIX@_hash_t *,
185 @LISTHASH_PREFIX@_hashptr_t *, void *,
186 @LISTHASH_PREFIX@_matchfunc_t);
188 /* inserting data */
189 int @LISTHASH_PREFIX@_hash_add(@LISTHASH_PREFIX@_hash_t *, void *);
191 /* delete an entry */
192 int @LISTHASH_PREFIX@_hash_del(@LISTHASH_PREFIX@_hash_t *,
193 @LISTHASH_PREFIX@_hashptr_t *);
195 #endif /* ! @LISTHASH_PREFIX@_LISTHASH_H */