www.pudn.com > streamrtp.rar > hash.h


/*
 * $Id: hash.h,v 1.3 2000/03/01 03:21:02 evangemh Exp $
 */

#ifndef HASH_H
#define HASH_H

#include 

/* structure for hashtable entry */
struct htent {
  unsigned int		hte_key;	/* key; may be pointer	*/
  void	       		*hte_object;	/* pointer to object	*/
  struct htent		*hte_chain;	/* next htent in bucket	*/
};

/* structure for hashtable */
struct ht {
  struct htent		**ht_entries;	/* array of buckets		*/
  int (* ht_hashfcn)(unsigned int, int);/* ptr to hash function		*/
  int (* ht_cmpfcn)(unsigned int, unsigned int);
					/* ptr to comparison function;
					   should return 0 on equal.	*/
  void (* ht_destroykeyfcn)(unsigned int);
					/* ptr to function to destroy
					   or free key			*/
  void (* ht_destroyobjectfcn)(void *);
					/* ptr to function to destroy
					   or free object		*/
  int			ht_size;	/* number of buckets		*/
  int			ht_count;	/* number of items in table	*/

  pthread_mutex_t	ht_writepend;	/* mutexes and counters to	*/
  pthread_mutex_t 	ht_readblk;	/* implement basic readers	*/
  pthread_mutex_t      	ht_writeblk;	/* writers locking with		*/
  pthread_mutex_t	ht_rdcntmutex;	/* priority given to writers.	*/
  pthread_mutex_t	ht_wrcntmutex;
  int			ht_readcnt;
  int			ht_writecnt;
};

/* API calls */
char			*htget(struct ht *, unsigned int);
struct ht		*htnew(int, int(*)(unsigned int, int), int(*)(unsigned int, unsigned int), void(*)(unsigned int), void(*)(void *));
int			htadd(struct ht *, unsigned int, void *);
int			htdel(struct ht *, unsigned int);
int			htdestroy(struct ht *);
int			htcount(struct ht *);
struct htent		**htenum(struct ht *);

/* Internal calls */
struct htent            *htgetent(struct ht *, unsigned int);
void htreaderbegin(struct ht *);
void htreaderend(struct ht *);
void htwriterbegin(struct ht *);
void htwriterend(struct ht *);

/* Hash and comparison functions */
int			hashstring(unsigned int, int);
int                     hashunsignedint(unsigned int, int);
int			unsignedinteq(unsigned int, unsigned int);

#endif