/* listhash/fget_listhash.h.  Generated from listhash.h.in by configure. */

/*
**  Copyright 1998-2002 University of Illinois Board of Trustees
**  Copyright 1998-2002 Mark D. Roth
**  All rights reserved.
**
**  fget_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 fget_LISTHASH_H
#define fget_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 (*fget_cmpfunc_t)(void *, void *);

/*
** Free function (for freeing allocated memory in each element)
*/
typedef void (*fget_freefunc_t)(void *);

/*
** Plugin function for fget_list_iterate()
*/
typedef int (*fget_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 (*fget_matchfunc_t)(void *, void *);


struct fget_node
{
	void *data;
	struct fget_node *next;
	struct fget_node *prev;
};
typedef struct fget_node *fget_listptr_t;

struct fget_list
{
	fget_listptr_t first;
	fget_listptr_t last;
	fget_cmpfunc_t cmpfunc;
	int flags;
	unsigned int nents;
};
typedef struct fget_list fget_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 fget_listptr_reset(fget_listptr_t *);

/* retrieve the data being pointed to */
void *fget_listptr_data(fget_listptr_t *);

/* creates a new, empty list */
fget_list_t *fget_list_new(int, fget_cmpfunc_t);

/* call a function for every element in a list */
int fget_list_iterate(fget_list_t *,
				   fget_iterate_func_t, void *);

/* empty the list */
void fget_list_empty(fget_list_t *,
				  fget_freefunc_t);

/* remove and free() the entire list */
void fget_list_free(fget_list_t *,
				 fget_freefunc_t);

/* add elements */
int fget_list_add(fget_list_t *, void *);

/* removes an element from the list - returns -1 on error */
void fget_list_del(fget_list_t *,
				fget_listptr_t *);

/* returns 1 when valid data is returned, or 0 at end of list */
int fget_list_next(fget_list_t *,
				fget_listptr_t *);

/* returns 1 when valid data is returned, or 0 at end of list */
int fget_list_prev(fget_list_t *,
				fget_listptr_t *);

/* return 1 if the data matches a list entry, 0 otherwise */
int fget_list_search(fget_list_t *,
				  fget_listptr_t *, void *,
				  fget_matchfunc_t);

/* return number of elements from list */
unsigned int fget_list_nents(fget_list_t *);

/* adds elements from a string delimited by delim */
int fget_list_add_str(fget_list_t *, char *, char *);

/* string matching function */
int fget_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 (*fget_hashfunc_t)(void *, unsigned int);


struct fget_hashptr
{
	int bucket;
	fget_listptr_t node;
};
typedef struct fget_hashptr fget_hashptr_t;

struct fget_hash
{
	int numbuckets;
	fget_list_t **table;
	fget_hashfunc_t hashfunc;
	unsigned int nents;
};
typedef struct fget_hash fget_hash_t;


/* reset a hash pointer */
void fget_hashptr_reset(fget_hashptr_t *);

/* retrieve the data being pointed to */
void *fget_hashptr_data(fget_hashptr_t *);

/* default hash function, optimized for 7-bit strings */
unsigned int fget_str_hashfunc(char *, unsigned int);

/* return number of elements from hash */
unsigned int fget_hash_nents(fget_hash_t *);

/* create a new hash */
fget_hash_t *fget_hash_new(int, fget_hashfunc_t);

/* empty the hash */
void fget_hash_empty(fget_hash_t *,
				  fget_freefunc_t);

/* delete all the fget_nodes of the hash and clean up */
void fget_hash_free(fget_hash_t *,
				 fget_freefunc_t);

/* returns 1 when valid data is returned, or 0 at end of list */
int fget_hash_next(fget_hash_t *,
				fget_hashptr_t *);

/* return 1 if the data matches a list entry, 0 otherwise */
int fget_hash_search(fget_hash_t *,
				  fget_hashptr_t *, void *,
				  fget_matchfunc_t);

/* return 1 if the key matches a list entry, 0 otherwise */
int fget_hash_getkey(fget_hash_t *,
				  fget_hashptr_t *, void *,
				  fget_matchfunc_t);

/* inserting data */
int fget_hash_add(fget_hash_t *, void *);

/* delete an entry */
int fget_hash_del(fget_hash_t *,
			       fget_hashptr_t *);

#endif /* ! fget_LISTHASH_H */



syntax highlighted by Code2HTML, v. 0.9.1