Source to include/hash.h


0001  #ifndef _HASH_H
0002  #define _HASH_H
0003  /*
0004   * hash.h
0005   *	Data structures for a hashed lookup object
0006   */
0007  #include <sys/types.h>
0008  
0009  /*
0010   * This is the root of the hashed object.  You shouldn't monkey
0011   * with it directly.
0012   */
0013  struct hash {
0014  	int h_hashsize;		/* Width of h_hash array */
0015  	ulong h_hashmask;	/* Bit mask to match array size */
0016  	struct hash_node	/* Chains under each hash value */
0017  		*h_hash[1];
0018  };
0019  
0020  /*
0021   * Hash collision chains.  An internal data structure.
0022   */
0023  struct hash_node {
0024  	struct hash_node *h_next;	/* Next on hash chain */
0025  	long h_key;			/* Key for this node */
0026  	void *h_data;			/*  ...corresponding value */
0027  };
0028  
0029  /*
0030   * Smoke and mirrors to avoid name space pollution
0031   */
0032  #define hash_alloc __hash_alloc
0033  #define hash_insert __hash_insert
0034  #define hash_delete __hash_delete
0035  #define hash_lookup __hash_lookup
0036  #define hash_dealloc __hash_dealloc
0037  #define hash_foreach __hash_foreach
0038  #define hash_size __hash_size
0039  
0040  /*
0041   * Hash routines
0042   */
0043  struct hash *hash_alloc(int);
0044  int hash_insert(struct hash *, long, void *);
0045  int hash_delete(struct hash *, long);
0046  void *hash_lookup(struct hash *, long);
0047  void hash_dealloc(struct hash *);
0048  void hash_foreach(struct hash *, intfun, void *);
0049  uint hash_size(struct hash *);
0050  
0051  #endif /* _HASH_H */