Changed the format of various sections to conform with GNU standard.

Deleted dependencies on some header files.
Replaced the use of the functions from memory.h with funtions like bzero.
Changed the include format.

From-SVN: r2019
This commit is contained in:
Richard Stallman 1992-09-02 01:59:40 +00:00
parent 4fc473c177
commit f847fb392d

View File

@ -1,5 +1,3 @@
/* -*-c-*- */
/* Copyright (C) 1989, 1992 Free Software Foundation, Inc. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
This file is part of GNU CC. This file is part of GNU CC.
@ -25,10 +23,13 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
the executable file might be covered by the GNU General Public License. */ the executable file might be covered by the GNU General Public License. */
/* /*
$Header: /usr/user/dennis_glatting/ObjC/c-runtime/dispatch/RCS/hash.h,v 0.10 1992/08/18 04:46:58 dglattin Exp $ $Header: /home/fsf/rms/c-runtime/dispatch/RCS/hash.h,v 0.11 1992/08/31 21:15:02 dglattin Exp rms $
$Author: dglattin $ $Author: dglattin $
$Date: 1992/08/18 04:46:58 $ $Date: 1992/08/31 21:15:02 $
$Log: hash.h,v $ $Log: hash.h,v $
* Revision 0.11 1992/08/31 21:15:02 dglattin
* minor documentation changes.
*
* Revision 0.10 1992/08/18 04:46:58 dglattin * Revision 0.10 1992/08/18 04:46:58 dglattin
* Saving a working version before release. * Saving a working version before release.
* *
@ -50,7 +51,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
* Revision 0.5 1991/11/23 22:19:21 dennisg * Revision 0.5 1991/11/23 22:19:21 dennisg
* converted some entries in the hash structure from ints to shorts. * converted some entries in the hash structure from ints to shorts.
* this was done to use a less expensive division instruction * this was done to use a less expensive division instruction
* in the hashIndex () routine. * in the hashIndex routine.
* *
* Revision 0.4 1991/11/21 22:25:19 dennisg * Revision 0.4 1991/11/21 22:25:19 dennisg
* deleted hash mask information from hash struct. * deleted hash mask information from hash struct.
@ -71,18 +72,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _hash_INCLUDE_GNU #ifndef _hash_INCLUDE_GNU
#define _hash_INCLUDE_GNU #define _hash_INCLUDE_GNU
/* If someone is using a c++
compiler then adjust the
types in the file back
to C. */
#ifdef __cplusplus
extern "C" {
#endif
#include <assert.h> #include "assert.h"
#include <sys/types.h> #include "mutex.h"
#include <mutex.h>
/* /*
* This data structure is used to hold items * This data structure is used to hold items
@ -92,16 +85,16 @@ extern "C" {
* Items in the cache are really of type void*. * Items in the cache are really of type void*.
*/ */
typedef struct cache_node { typedef struct cache_node {
struct cache_node* nextNode; /* Pointer to next entry on struct cache_node *nextNode; /* Pointer to next entry on
the list. NULL indicates the list. NULL indicates
end of list. */ end of list. */
void* theKey; /* Key used to locate the void *theKey; /* Key used to locate the
value. Used to locate value. Used to locate
value when more than one value when more than one
key computes the same hash key computes the same hash
value. */ value. */
void* theValue; /* Value stored for the void *theValue; /* Value stored for the
key. */ key. */
} CacheNode, *CacheNode_t; } CacheNode, *CacheNode_t;
@ -112,9 +105,9 @@ typedef struct cache_node {
* *
* Unfortunately there is a mutual data structure reference problem with this * Unfortunately there is a mutual data structure reference problem with this
* typedef. Therefore, to remove compiler warnings the functions passed to * typedef. Therefore, to remove compiler warnings the functions passed to
* hash_new() will have to be casted to this type. * hash_new will have to be casted to this type.
*/ */
typedef u_int (*HashFunc)(void*, void*); typedef unsigned int (*HashFunc)(void*, void*);
/* /*
* This data type is the function that compares two hash keys and returns an * This data type is the function that compares two hash keys and returns an
@ -137,88 +130,72 @@ typedef struct cache {
* Variables used to implement the * Variables used to implement the
* hash itself. * hash itself.
*/ */
CacheNode_t (* theNodeTable)[]; /* Pointer to an array of CacheNode_t (*theNodeTable)[]; /* Pointer to an array of
hash nodes. */ hash nodes. */
/* /*
* Variables used to track the size of the hash * Variables used to track the size of the hash
* table so to determine when to resize it. * table so to determine when to resize it.
*/ */
u_int sizeOfHash, /* Number of buckets unsigned int sizeOfHash, /* Number of buckets
allocated for the hash allocated for the hash
table (number of array table (number of array
entries allocated for entries allocated for
"theNodeTable"). Must be "theNodeTable"). Must be
a power of two. */ a power of two. */
entriesInHash, /* Current number of entries unsigned int entriesInHash, /* Current number of entries
in the hash table. */ in the hash table. */
mask; /* Precomputed mask. */ unsigned int mask; /* Precomputed mask. */
/* /*
* Variables used to implement indexing * Variables used to implement indexing
* through the hash table. * through the hash table.
*/ */
u_int lastBucket; /* Tracks which entry in the unsigned int lastBucket; /* Tracks which entry in the
array where the last value array where the last value
was returned. */ was returned. */
/* Function used to compute /* Function used to compute a hash code given a key.
a hash code given a key. This function is specified when the hash table is created. */
This function is
specified when the hash
table is created. */
HashFunc hashFunc; HashFunc hashFunc;
/* Function used to compare /* Function used to compare two hash keys to determine
two hash keys to determine if they are equal. */
if they are equal. */
CompareFunc compareFunc; CompareFunc compareFunc;
} Cache, *Cache_t; } Cache, *Cache_t;
/* Prototypes for hash /* Allocate and initialize a hash table. */
functions. */
/* Allocate and initialize
a hash table. */
Cache_t Cache_t
hash_new (u_int sizeOfHash, HashFunc aHashFunc, CompareFunc aCompareFunc); hash_new (unsigned int sizeOfHash,
/* Deallocate all of the HashFunc aHashFunc, CompareFunc aCompareFunc);
hash nodes and the cache
itself. */ /* Deallocate all of the hash nodes and the cache itself. */
void void
hash_delete (Cache_t theCache); hash_delete (Cache_t theCache);
/* Add the key/value pair
to the hash table. If the /* Add the key/value pair to the hash table. If the
hash table reaches a hash table reaches a level of fullnes then it will be resized.
level of fullnes then
it will be resized.
assert() if the key is assert if the key is already in the hash. */
already in the hash. */
void void
hash_add (Cache_t* theCache, void* aKey, void* aValue); hash_add (Cache_t *theCache, void *aKey, void *aValue);
/* Remove the key/value pair
from the hash table. /* Remove the key/value pair from the hash table.
assert() if the key isn't assert if the key isn't in the table. */
in the table. */
void void
hash_remove (Cache_t theCache, void* aKey); hash_remove (Cache_t theCache, void *aKey);
/* Used to index through the
hash table. Start with NULL /* Used to index through the hash table. Start with NULL
to get the first entry. to get the first entry.
Successive calls pass the Successive calls pass the value returned previously.
value returned previously. ** Don't modify the hash during this operation ***
** Don't modify the hash
during this operation ***
Cache nodes are returned Cache nodes are returned such that key or value can
such that key or value can be extracted. */
ber extracted. */
CacheNode_t CacheNode_t
hash_next (Cache_t theCache, CacheNode_t aCacheNode); hash_next (Cache_t theCache, CacheNode_t aCacheNode);
/* Used to return a value from /* Used to return a value from a hash table using a given key. */
a hash table using a given
key. */
void* void*
hash_value_for_key (Cache_t theCache, void* aKey); hash_value_for_key (Cache_t theCache, void *aKey);
/************************************************ /************************************************
@ -229,27 +206,26 @@ hash_value_for_key (Cache_t theCache, void* aKey);
************************************************/ ************************************************/
/* Calculate a hash code by /* Calculate a hash code by performing some
performing some manipulation of the key pointer. */
manipulation of the key static inline unsigned int
pointer. */ intHash(Cache_t theCache, void *aKey)
static inline u_int {
intHash(Cache_t theCache, void* aKey) {
assert(sizeof (u_int) == sizeof (aKey)); assert(sizeof (unsigned int) == sizeof (aKey));
return ((u_int)aKey >> (sizeof(void*) - 1)) & theCache->mask ; return ((unsigned int)aKey >> (sizeof(void*) - 1)) & theCache->mask ;
} }
/* Calculate a hash code by
iterating over a NULL
terminate string. */
static inline u_int
strHash(Cache_t theCache, void* aKey) {
u_int ret = 0; /* Calculate a hash code by iterating over a NULL
u_int ctr = 0; terminate string. */
static inline unsigned int
strHash(Cache_t theCache, void *aKey)
{
unsigned int ret = 0;
unsigned int ctr = 0;
while(*(char*)aKey) { while(*(char*)aKey) {
@ -263,24 +239,18 @@ strHash(Cache_t theCache, void* aKey) {
/* Compare two integers. */ /* Compare two integers. */
static inline int static inline int
intCmp(void* k1, void* k2) { intCmp(void *k1, void *k2)
{
return !((int)k1 - (int)k2);
return !((int)k1 - (int)k2);
} }
/* Compare two strings. */ /* Compare two strings. */
static inline int static inline int
strCmp(void* k1, void* k2) { strCmp(void *k1, void *k2)
{
return !strcmp(k1, k2);
return !strcmp( k1, k2 );
} }
#ifdef __cplusplus #endif /* _hash_INCLUDE_GNU */
}
#endif
#endif