blob: fa33cfd25986c50b6c2dbc26843008be3006c4cc [file] [log] [blame]
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001/* listhash/libtar_listhash.h. Generated from listhash.h.in by configure. */
2
3/*
4** Copyright 1998-2002 University of Illinois Board of Trustees
5** Copyright 1998-2002 Mark D. Roth
6** All rights reserved.
7**
8** libtar_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
13*/
14
15#ifndef libtar_LISTHASH_H
16#define libtar_LISTHASH_H
17
18
19/***** list.c **********************************************************/
20
21/*
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
25*/
26typedef int (*libtar_cmpfunc_t)(void *, void *);
27
28/*
29** Free function (for freeing allocated memory in each element)
30*/
31typedef void (*libtar_freefunc_t)(void *);
32
33/*
34** Plugin function for libtar_list_iterate()
35*/
36typedef int (*libtar_iterate_func_t)(void *, void *);
37
38/*
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
43*/
44typedef int (*libtar_matchfunc_t)(void *, void *);
45
46
47struct libtar_node
48{
49 void *data;
50 struct libtar_node *next;
51 struct libtar_node *prev;
52};
53typedef struct libtar_node *libtar_listptr_t;
54
55struct libtar_list
56{
57 libtar_listptr_t first;
58 libtar_listptr_t last;
59 libtar_cmpfunc_t cmpfunc;
60 int flags;
61 unsigned int nents;
62};
63typedef struct libtar_list libtar_list_t;
64
65
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 */
70
71
72/* reset a list pointer */
73void libtar_listptr_reset(libtar_listptr_t *);
74
75/* retrieve the data being pointed to */
76void *libtar_listptr_data(libtar_listptr_t *);
77
78/* creates a new, empty list */
79libtar_list_t *libtar_list_new(int, libtar_cmpfunc_t);
80
81/* call a function for every element in a list */
82int libtar_list_iterate(libtar_list_t *,
83 libtar_iterate_func_t, void *);
84
85/* empty the list */
86void libtar_list_empty(libtar_list_t *,
87 libtar_freefunc_t);
88
89/* remove and free() the entire list */
90void libtar_list_free(libtar_list_t *,
91 libtar_freefunc_t);
92
93/* add elements */
94int libtar_list_add(libtar_list_t *, void *);
95
96/* removes an element from the list - returns -1 on error */
97void libtar_list_del(libtar_list_t *,
98 libtar_listptr_t *);
99
100/* returns 1 when valid data is returned, or 0 at end of list */
101int libtar_list_next(libtar_list_t *,
102 libtar_listptr_t *);
103
104/* returns 1 when valid data is returned, or 0 at end of list */
105int libtar_list_prev(libtar_list_t *,
106 libtar_listptr_t *);
107
108/* return 1 if the data matches a list entry, 0 otherwise */
109int libtar_list_search(libtar_list_t *,
110 libtar_listptr_t *, void *,
111 libtar_matchfunc_t);
112
113/* return number of elements from list */
114unsigned int libtar_list_nents(libtar_list_t *);
115
116/* adds elements from a string delimited by delim */
117int libtar_list_add_str(libtar_list_t *, char *, char *);
118
119/* string matching function */
120int libtar_str_match(char *, char *);
121
122
123/***** hash.c **********************************************************/
124
125/*
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
130*/
131typedef unsigned int (*libtar_hashfunc_t)(void *, unsigned int);
132
133
134struct libtar_hashptr
135{
136 int bucket;
137 libtar_listptr_t node;
138};
139typedef struct libtar_hashptr libtar_hashptr_t;
140
141struct libtar_hash
142{
143 int numbuckets;
144 libtar_list_t **table;
145 libtar_hashfunc_t hashfunc;
146 unsigned int nents;
147};
148typedef struct libtar_hash libtar_hash_t;
149
150
151/* reset a hash pointer */
152void libtar_hashptr_reset(libtar_hashptr_t *);
153
154/* retrieve the data being pointed to */
155void *libtar_hashptr_data(libtar_hashptr_t *);
156
157/* default hash function, optimized for 7-bit strings */
158unsigned int libtar_str_hashfunc(char *, unsigned int);
159
160/* return number of elements from hash */
161unsigned int libtar_hash_nents(libtar_hash_t *);
162
163/* create a new hash */
164libtar_hash_t *libtar_hash_new(int, libtar_hashfunc_t);
165
166/* empty the hash */
167void libtar_hash_empty(libtar_hash_t *,
168 libtar_freefunc_t);
169
170/* delete all the libtar_nodes of the hash and clean up */
171void libtar_hash_free(libtar_hash_t *,
172 libtar_freefunc_t);
173
174/* returns 1 when valid data is returned, or 0 at end of list */
175int libtar_hash_next(libtar_hash_t *,
176 libtar_hashptr_t *);
177
178/* return 1 if the data matches a list entry, 0 otherwise */
179int libtar_hash_search(libtar_hash_t *,
180 libtar_hashptr_t *, void *,
181 libtar_matchfunc_t);
182
183/* return 1 if the key matches a list entry, 0 otherwise */
184int libtar_hash_getkey(libtar_hash_t *,
185 libtar_hashptr_t *, void *,
186 libtar_matchfunc_t);
187
188/* inserting data */
189int libtar_hash_add(libtar_hash_t *, void *);
190
191/* delete an entry */
192int libtar_hash_del(libtar_hash_t *,
193 libtar_hashptr_t *);
194
195#endif /* ! libtar_LISTHASH_H */
196