diff options
Diffstat (limited to 'Utilities/cmtar/listhash/listhash.h.in')
-rw-r--r-- | Utilities/cmtar/listhash/listhash.h.in | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/Utilities/cmtar/listhash/listhash.h.in b/Utilities/cmtar/listhash/listhash.h.in new file mode 100644 index 0000000..4ab5fdf --- /dev/null +++ b/Utilities/cmtar/listhash/listhash.h.in @@ -0,0 +1,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 */ + |