blob: 48c0d7409de2e9e8be90b0c55e117c8183768bbe [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
James Christopher Adduono6f57f7c2016-03-01 16:01:53 -050018#ifdef __cplusplus
19extern "C" {
20#endif
bigbiff bigbiff9c754052013-01-09 09:09:08 -050021
22/***** list.c **********************************************************/
23
24/*
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
28*/
29typedef int (*libtar_cmpfunc_t)(void *, void *);
30
31/*
32** Free function (for freeing allocated memory in each element)
33*/
34typedef void (*libtar_freefunc_t)(void *);
35
36/*
37** Plugin function for libtar_list_iterate()
38*/
39typedef int (*libtar_iterate_func_t)(void *, void *);
40
41/*
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
46*/
47typedef int (*libtar_matchfunc_t)(void *, void *);
48
49
50struct libtar_node
51{
52 void *data;
53 struct libtar_node *next;
54 struct libtar_node *prev;
55};
56typedef struct libtar_node *libtar_listptr_t;
57
58struct libtar_list
59{
60 libtar_listptr_t first;
61 libtar_listptr_t last;
62 libtar_cmpfunc_t cmpfunc;
63 int flags;
64 unsigned int nents;
65};
66typedef struct libtar_list libtar_list_t;
67
68
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 */
73
74
75/* reset a list pointer */
76void libtar_listptr_reset(libtar_listptr_t *);
77
78/* retrieve the data being pointed to */
79void *libtar_listptr_data(libtar_listptr_t *);
80
81/* creates a new, empty list */
82libtar_list_t *libtar_list_new(int, libtar_cmpfunc_t);
83
84/* call a function for every element in a list */
85int libtar_list_iterate(libtar_list_t *,
86 libtar_iterate_func_t, void *);
87
88/* empty the list */
89void libtar_list_empty(libtar_list_t *,
90 libtar_freefunc_t);
91
92/* remove and free() the entire list */
93void libtar_list_free(libtar_list_t *,
94 libtar_freefunc_t);
95
96/* add elements */
97int libtar_list_add(libtar_list_t *, void *);
98
99/* removes an element from the list - returns -1 on error */
100void libtar_list_del(libtar_list_t *,
101 libtar_listptr_t *);
102
103/* returns 1 when valid data is returned, or 0 at end of list */
104int libtar_list_next(libtar_list_t *,
105 libtar_listptr_t *);
106
107/* returns 1 when valid data is returned, or 0 at end of list */
108int libtar_list_prev(libtar_list_t *,
109 libtar_listptr_t *);
110
111/* return 1 if the data matches a list entry, 0 otherwise */
112int libtar_list_search(libtar_list_t *,
113 libtar_listptr_t *, void *,
114 libtar_matchfunc_t);
115
116/* return number of elements from list */
117unsigned int libtar_list_nents(libtar_list_t *);
118
119/* adds elements from a string delimited by delim */
120int libtar_list_add_str(libtar_list_t *, char *, char *);
121
122/* string matching function */
123int libtar_str_match(char *, char *);
124
125
126/***** hash.c **********************************************************/
127
128/*
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
133*/
134typedef unsigned int (*libtar_hashfunc_t)(void *, unsigned int);
135
136
137struct libtar_hashptr
138{
139 int bucket;
140 libtar_listptr_t node;
141};
142typedef struct libtar_hashptr libtar_hashptr_t;
143
144struct libtar_hash
145{
146 int numbuckets;
147 libtar_list_t **table;
148 libtar_hashfunc_t hashfunc;
149 unsigned int nents;
150};
151typedef struct libtar_hash libtar_hash_t;
152
153
154/* reset a hash pointer */
155void libtar_hashptr_reset(libtar_hashptr_t *);
156
157/* retrieve the data being pointed to */
158void *libtar_hashptr_data(libtar_hashptr_t *);
159
160/* default hash function, optimized for 7-bit strings */
161unsigned int libtar_str_hashfunc(char *, unsigned int);
162
163/* return number of elements from hash */
164unsigned int libtar_hash_nents(libtar_hash_t *);
165
166/* create a new hash */
167libtar_hash_t *libtar_hash_new(int, libtar_hashfunc_t);
168
169/* empty the hash */
170void libtar_hash_empty(libtar_hash_t *,
171 libtar_freefunc_t);
172
173/* delete all the libtar_nodes of the hash and clean up */
174void libtar_hash_free(libtar_hash_t *,
175 libtar_freefunc_t);
176
177/* returns 1 when valid data is returned, or 0 at end of list */
178int libtar_hash_next(libtar_hash_t *,
179 libtar_hashptr_t *);
180
181/* return 1 if the data matches a list entry, 0 otherwise */
182int libtar_hash_search(libtar_hash_t *,
183 libtar_hashptr_t *, void *,
184 libtar_matchfunc_t);
185
186/* return 1 if the key matches a list entry, 0 otherwise */
187int libtar_hash_getkey(libtar_hash_t *,
188 libtar_hashptr_t *, void *,
189 libtar_matchfunc_t);
190
191/* inserting data */
192int libtar_hash_add(libtar_hash_t *, void *);
193
194/* delete an entry */
195int libtar_hash_del(libtar_hash_t *,
196 libtar_hashptr_t *);
197
James Christopher Adduono6f57f7c2016-03-01 16:01:53 -0500198#ifdef __cplusplus
199}
200#endif
201
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500202#endif /* ! libtar_LISTHASH_H */
203