/* %Z%%M% %I% %E% */

/*
 * Copyright (c) 1990, 1991, 1995 by Wayne C. Gramlich.
 * All rights reserved.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * for any purpose is hereby granted without fee provided that the above
 * copyright notice and this permission are retained.  The author makes
 * no representations about the suitability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 */

/* Hash table implementation definitions: */

#ifndef HASH_DEFS_H
#define hash_defs_h

#ifndef HASH_EXPORTS_H
#include "hash_exports.h"
#endif

struct Hsh_bucket_struct {
	int		index;		/* Bucket hash index */
	Hsh_value	value;		/* Bucket value */
};

struct Hsh_header_struct {
	Hsh_bucket	buckets;	/* Vector of "size" buckets */
	unsigned int	size : 16;	/* Vector size */
	unsigned int	rehash : 8;	/* All bucket indexes masked by
					 * 2**"rehash"-1 are equal */
	unsigned int	limit : 8;	/* Avail. buckets are 2**("limit"-1)
					 * or 0 for none */
};

struct Hsh_struct {
	Hsh_value	handle;		/* Client data/null ret. on lookup */
	Hsh_header	headers;	/* Vector of "length" headers */
	Heap		heap;		/* Heap to allocate from */
	int		length;		/* Length of headers vector */
	int		limit;		/* Grow hash when "size" > "limit" */
	int		min_power;	/* Minimum power of 2 */
	int		mask;		/* mask = 2**"power"-1 */
	int		power;		/* "length" = 2**"power" */
	Hsh_routine_equal routine_equal;/* Equality routine */
	Hsh_routine_hash routine_hash;	/* Hash routine */
	int		size;		/* Total number of buckets in hash */
};

#endif /* HASH_DEFS_H */
