changed hash value calculation.

func name changed from hashValue() to hashIndex().  the
func really calculated a index anyway.
changed hash func impl.  essentually it was calculating a hash value
from a hash value.  this is a implementation thing.

From-SVN: r66
This commit is contained in:
Dennis Glatting 1991-11-21 22:27:06 +00:00
parent c97e400f30
commit 7e8ead54c2
1 changed files with 12 additions and 29 deletions

View File

@ -16,10 +16,13 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *
$Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.4 1991/11/19 12:34:41 dennisg Exp dennisg $ $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.5 1991/11/20 23:29:20 dennisg Exp dennisg $
$Author: dennisg $ $Author: dennisg $
$Date: 1991/11/19 12:34:41 $ $Date: 1991/11/20 23:29:20 $
$Log: hash.c,v $ $Log: hash.c,v $
* Revision 0.5 1991/11/20 23:29:20 dennisg
* converted hashIndex() to a inline.
*
* Revision 0.4 1991/11/19 12:34:41 dennisg * Revision 0.4 1991/11/19 12:34:41 dennisg
* bug in hash_delete(). It was using void* to obtain nodes to * bug in hash_delete(). It was using void* to obtain nodes to
* pass to hash_remove(). The value passed to hash_removed() is a * pass to hash_remove(). The value passed to hash_removed() is a
@ -60,24 +63,18 @@
(((cache)->sizeOfHash * 175 ) / 100 ) (((cache)->sizeOfHash * 175 ) / 100 )
static inline u_int hashValue( Cache_t theCache, void* aKey ) { static inline u_int hashIndex( Cache_t theCache, void* aKey ) {
u_int hash = 0;
int i;
assert( theCache->numberOfMaskBits );
for( i = 0; i < ( sizeof( aKey ) * 8 ); i += theCache->numberOfMaskBits )
hash ^= (( u_int )aKey ) >> i ;
return ( hash & theCache->mask ) % theCache->sizeOfHash; assert (sizeof (u_int) == sizeof (void*));
return ((u_int)aKey) % theCache->sizeOfHash ;
} }
Cache_t hash_new( u_int sizeOfHash ) { Cache_t hash_new( u_int sizeOfHash ) {
Cache_t retCache; Cache_t retCache;
int i;
assert( sizeOfHash ); assert( sizeOfHash );
@ -98,20 +95,6 @@ Cache_t hash_new( u_int sizeOfHash ) {
retCache->sizeOfHash = sizeOfHash; retCache->sizeOfHash = sizeOfHash;
/* Calculate the number of
bits required to represent
the hash mask. */
retCache->numberOfMaskBits =
ceil( log( retCache->sizeOfHash ) / log( 2 ));
/* Form a bit mask for the
hash. */
for( i = 0; i < retCache->numberOfMaskBits; ++i )
retCache->mask = ( retCache->mask << 1 ) | 0x01 ;
assert( retCache->numberOfMaskBits );
assert( retCache->mask );
return retCache; return retCache;
} }
@ -135,7 +118,7 @@ void hash_delete( Cache_t theCache ) {
void hash_add( Cache_t* theCache, void* aKey, void* aValue ) { void hash_add( Cache_t* theCache, void* aKey, void* aValue ) {
u_int indx = hashValue( *theCache, aKey ); u_int indx = hashIndex( *theCache, aKey );
CacheNode_t aCacheNode = calloc( 1, sizeof( CacheNode )); CacheNode_t aCacheNode = calloc( 1, sizeof( CacheNode ));
@ -207,7 +190,7 @@ void hash_add( Cache_t* theCache, void* aKey, void* aValue ) {
void hash_remove( Cache_t theCache, void* aKey ) { void hash_remove( Cache_t theCache, void* aKey ) {
u_int indx = hashValue( theCache, aKey ); u_int indx = hashIndex( theCache, aKey );
CacheNode_t aCacheNode = ( *theCache->theNodeTable )[ indx ]; CacheNode_t aCacheNode = ( *theCache->theNodeTable )[ indx ];
@ -247,7 +230,7 @@ void hash_remove( Cache_t theCache, void* aKey ) {
void* hash_value_for_key( Cache_t theCache, void* aKey ) { void* hash_value_for_key( Cache_t theCache, void* aKey ) {
u_int indx = hashValue( theCache, aKey ); u_int indx = hashIndex( theCache, aKey );
CacheNode_t aCacheNode = ( *theCache->theNodeTable )[ indx ]; CacheNode_t aCacheNode = ( *theCache->theNodeTable )[ indx ];
void* retVal = NULL; void* retVal = NULL;