Commit eedb4710 by Dennis Glatting

Cleaned up file format for a distribution.

From-SVN: r111
parent b61e1345
......@@ -16,10 +16,14 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
$Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.8 1991/11/24 01:20:02 dennisg Exp dennisg $
$Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.9 1991/12/03 02:01:23 dennisg Exp dennisg $
$Author: dennisg $
$Date: 1991/11/24 01:20:02 $
$Date: 1991/12/03 02:01:23 $
$Log: hash.c,v $
* Revision 0.9 1991/12/03 02:01:23 dennisg
* fixed assert macro.
* added memory allocation adjustment macro for hash size allocation.
*
* Revision 0.8 1991/11/24 01:20:02 dennisg
* changed shorts back to ints.
* the efficiency gained didn't out weight the grossness of the code.
......@@ -58,41 +62,41 @@
#include <hash.h>
#include <hash-inline.h>
#include <hash-inline.h>
#include <ObjC.h>
#include <ObjC-private.h>
#include <ObjC-private.h>
#include <assert.h>
#include <libc.h>
#include <math.h>
/* These two macros determine
when a hash table is full and
by how much it should be
expanded respectively.
These equations are
percentages. */
#define FULLNESS(cache) \
((((cache)->sizeOfHash * 75 ) / 100) <= (cache)->entriesInHash)
#define EXPANSION(cache) \
(((cache)->sizeOfHash * 175 ) / 100 )
#define MEMORY_ALLOCATION_ADJUST(i) \
((i&0x01)?i:(i-1))
/* These two macros determine
when a hash table is full and
by how much it should be
expanded respectively.
These equations are
percentages. */
#define FULLNESS(cache) \
((((cache)->sizeOfHash * 75 ) / 100) <= (cache)->entriesInHash)
#define EXPANSION(cache) \
(((cache)->sizeOfHash * 175 ) / 100 )
#define MEMORY_ALLOCATION_ADJUST(i) \
((i&0x01)?i:(i-1))
Cache_t hash_new (u_int sizeOfHash) {
Cache_t retCache;
assert(sizeOfHash);
/* Memory is allocated on this
machine in even address
chunks. Therefore the
modulus must be odd. */
sizeOfHash = MEMORY_ALLOCATION_ADJUST(sizeOfHash);
/* Memory is allocated on this
machine in even address
chunks. Therefore the
modulus must be odd. */
sizeOfHash = MEMORY_ALLOCATION_ADJUST(sizeOfHash);
/* Allocate the cache
structure. calloc () insures
......@@ -108,7 +112,7 @@ Cache_t hash_new (u_int sizeOfHash) {
retCache->theNodeTable = calloc (sizeOfHash, sizeof (CacheNode_t));
assert(retCache->theNodeTable);
retCache->sizeOfHash = sizeOfHash;
retCache->sizeOfHash = sizeOfHash;
return retCache;
}
......@@ -163,44 +167,44 @@ void hash_add (Cache_t* theCache, void* aKey, void* aValue) {
first element on the list. */
(* (*theCache)->theNodeTable)[ indx ] = aCacheNode;
/* Bump the number of entries
in the cache. */
++ (*theCache)->entriesInHash;
/* Check the hash table's
fullness. We're going
to expand if it is above
the fullness level. */
if (FULLNESS (*theCache)) {
/* The hash table has reached
its fullness level. Time to
expand it.
I'm using a slow method
here but is built on other
primitive functions thereby
increasing its
correctness. */
CacheNode_t aNode = NULL;
Cache_t newCache =
hash_new (MEMORY_ALLOCATION_ADJUST( EXPANSION (*theCache)));
DEBUG_PRINTF (stderr, "Expanding cache %#x from %d to %d\n",
*theCache, (*theCache)->sizeOfHash, newCache->sizeOfHash);
/* Copy the nodes from the
first hash table to the
new one. */
while (aNode = hash_next (*theCache, aNode))
hash_add (&newCache, aNode->theKey, aNode->theValue);
/* Trash the old cache. */
hash_delete (*theCache);
/* Return a pointer to the new
hash table. */
*theCache = newCache;
}
/* Bump the number of entries
in the cache. */
++ (*theCache)->entriesInHash;
/* Check the hash table's
fullness. We're going
to expand if it is above
the fullness level. */
if (FULLNESS (*theCache)) {
/* The hash table has reached
its fullness level. Time to
expand it.
I'm using a slow method
here but is built on other
primitive functions thereby
increasing its
correctness. */
CacheNode_t aNode = NULL;
Cache_t newCache =
hash_new (MEMORY_ALLOCATION_ADJUST( EXPANSION (*theCache)));
DEBUG_PRINTF (stderr, "Expanding cache %#x from %d to %d\n",
*theCache, (*theCache)->sizeOfHash, newCache->sizeOfHash);
/* Copy the nodes from the
first hash table to the
new one. */
while (aNode = hash_next (*theCache, aNode))
hash_add (&newCache, aNode->theKey, aNode->theValue);
/* Trash the old cache. */
hash_delete (*theCache);
/* Return a pointer to the new
hash table. */
*theCache = newCache;
}
}
......@@ -237,10 +241,10 @@ void hash_remove (Cache_t theCache, void* aKey) {
} while (!removed && aCacheNode);
assert(removed);
}
/* Decrement the number of
entries in the hash table. */
--theCache->entriesInHash;
/* Decrement the number of
entries in the hash table. */
--theCache->entriesInHash;
}
......
......@@ -21,10 +21,14 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
$Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.h,v 0.6 1991/11/24 01:20:02 dennisg Exp dennisg $
$Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.h,v 0.7 1991/12/03 02:01:23 dennisg Exp dennisg $
$Author: dennisg $
$Date: 1991/11/24 01:20:02 $
$Date: 1991/12/03 02:01:23 $
$Log: hash.h,v $
* Revision 0.7 1991/12/03 02:01:23 dennisg
* fixed assert macro.
* added memory allocation adjustment macro for hash size allocation.
*
* Revision 0.6 1991/11/24 01:20:02 dennisg
* changed shorts back to ints.
* the efficiency gained didn't out weight the grossness of the code.
......@@ -98,18 +102,18 @@ typedef struct cache {
*/
CacheNode_t (* theNodeTable)[]; /* Pointer to an array of
hash nodes. */
/*
* Variables used to track the size of the hash
* table so to determine when to resize it.
*/
/*
* Variables used to track the size of the hash
* table so to determine when to resize it.
*/
u_int sizeOfHash, /* Number of buckets
allocated for the hash
table (number of array
entries allocated for
"theNodeTable"). Must be
a power of two. */
entriesInHash; /* Current number of entries
in ther hash table. */
a power of two. */
entriesInHash; /* Current number of entries
in ther hash table. */
/*
* Variables used to implement indexing
* through the hash table.
......@@ -132,12 +136,12 @@ Cache_t hash_new (u_int sizeOfHash);
void hash_delete (Cache_t theCache);
/* Add the key/value pair
to the hash table. If the
hash table reaches a
level of fullnes then
it will be resized.
assert() if the key is
already in the hash. */
hash table reaches a
level of fullnes then
it will be resized.
assert() if the key is
already in the hash. */
void hash_add (Cache_t* theCache, void* aKey, void* aValue);
/* Remove the key/value pair
from the hash table.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment