Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
6072a4f5
Commit
6072a4f5
authored
Sep 02, 1992
by
Richard Stallman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed some decls.
From-SVN: r2020
parent
f847fb39
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
65 deletions
+62
-65
gcc/objc/hash.c
+62
-65
No files found.
gcc/objc/hash.c
View file @
6072a4f5
/* -*-c-*- */
/* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
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. */
/*
$Header: /
usr/user/dennis_glatting/ObjC/c-runtime/dispatch/RCS/hash.c,v 0.13 1992/08/18 04:46:58 dglattin Exp
$
$Header: /
home/fsf/rms/c-runtime/dispatch/RCS/hash.c,v 0.14 1992/08/31 21:09:15 dglattin Exp rms
$
$Author: dglattin $
$Date: 1992/08/
18 04:46:58
$
$Date: 1992/08/
31 21:09:15
$
$Log: hash.c,v $
* Revision 0.14 1992/08/31 21:09:15 dglattin
* minor documentation changes.
*
* Revision 0.13 1992/08/18 04:46:58 dglattin
* Saving a working version before release.
*
...
...
@@ -52,22 +53,22 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
* the efficiency gained didn't out weight the grossness of the code.
*
* Revision 0.7 1991/11/23 22:18:29 dennisg
* deleted hashIndex
()
and moved it to hash-inline.h
* converted hash_value_for_key
()
to a inline and moved it to hash-inline.h.
* deleted hashIndex and moved it to hash-inline.h
* converted hash_value_for_key to a inline and moved it to hash-inline.h.
*
* Revision 0.6 1991/11/21 22:27:06 dennisg
* changed hash value calculation.
* func name changed from hashValue
() to hashIndex()
. the
* func name changed from hashValue
to hashIndex
. the
* func really calculated a index anyway.
* changed hash func impl. essentially it was calculating a hash value
* from a hash value. this is a implementation thing.
*
* Revision 0.5 1991/11/20 23:29:20 dennisg
* converted hashIndex
()
to a inline.
* converted hashIndex to a inline.
*
* Revision 0.4 1991/11/19 12:34:41 dennisg
* bug in hash_delete
()
. It was using void* to obtain nodes to
* pass to hash_remove
(). The value passed to hash_removed ()
is a
* bug in hash_delete. It was using void* to obtain nodes to
* pass to hash_remove
. The value passed to hash_removed
is a
* entry from the node structure rather than the node itself. Using
* void* removed compiler checking.
* Modified to implement cache expansion.
...
...
@@ -84,53 +85,49 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
*/
#include <hash.h>
#include <objc.h>
#include <objcP.h>
#include <objc-protoP.h>
#include "config.h"
#include "hash.h"
#include "objc.h"
#include "objcP.h"
#include "objc-protoP.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "assert.h"
/* These two macros determine
when a hash table is full and
by how much it should be
expanded respectively.
/* These two macros determine when a hash table is full and
by how much it should be expanded respectively.
These equations are
percentages. */
These equations are percentages. */
#define FULLNESS(cache) \
((((cache)->sizeOfHash * 75
) / 100) <= (cache)->entriesInHash)
((((cache)->sizeOfHash * 75) / 100) <= (cache)->entriesInHash)
#define EXPANSION(cache) \
((cache)->sizeOfHash * 2
)
((cache)->sizeOfHash * 2)
Cache_t
hash_new
(
u_int
sizeOfHash
,
HashFunc
aHashFunc
,
CompareFunc
aCompareFunc
)
{
hash_new
(
u_int
sizeOfHash
,
HashFunc
aHashFunc
,
CompareFunc
aCompareFunc
)
{
Cache_t
retCache
;
/* Pass me a value greater than 0 and a power of 2. */
assert
(
sizeOfHash
);
assert
(
!
(
sizeOfHash
&
(
sizeOfHash
-
1
)));
assert
(
sizeOfHash
);
assert
(
!
(
sizeOfHash
&
(
sizeOfHash
-
1
)));
/* Allocate the cache structure. calloc
()
insures
/* Allocate the cache structure. calloc insures
its initialization for default values. */
retCache
=
calloc
(
1
,
sizeof
(
Cache
));
assert
(
retCache
);
retCache
=
(
Cache_t
)
calloc
(
1
,
sizeof
(
Cache
));
assert
(
retCache
);
/* Allocate the array of buckets for the cache.
calloc() initializes all of the pointers to NULL. */
retCache
->
theNodeTable
=
calloc
(
sizeOfHash
,
sizeof
(
CacheNode_t
));
assert
(
retCache
->
theNodeTable
);
calloc initializes all of the pointers to NULL. */
retCache
->
theNodeTable
=
(
CacheNode_t
*
)
calloc
(
sizeOfHash
,
sizeof
(
CacheNode_t
));
assert
(
retCache
->
theNodeTable
);
retCache
->
sizeOfHash
=
sizeOfHash
;
/* This should work for all processor architectures? */
retCache
->
mask
=
(
sizeOfHash
-
1
);
retCache
->
mask
=
(
sizeOfHash
-
1
);
/* Store the hashing function so that codes can be computed. */
retCache
->
hashFunc
=
aHashFunc
;
...
...
@@ -144,8 +141,8 @@ hash_new (u_int sizeOfHash, HashFunc aHashFunc, CompareFunc aCompareFunc) {
void
hash_delete
(
Cache_t
theCache
)
{
hash_delete
(
Cache_t
theCache
)
{
CacheNode_t
aNode
;
...
...
@@ -160,37 +157,37 @@ hash_delete (Cache_t theCache) {
void
hash_add
(
Cache_t
*
theCache
,
void
*
aKey
,
void
*
aValue
)
{
hash_add
(
Cache_t
*
theCache
,
void
*
aKey
,
void
*
aValue
)
{
u_int
indx
=
(
*
(
*
theCache
)
->
hashFunc
)(
*
theCache
,
aKey
);
CacheNode_t
aCacheNode
=
(
CacheNode_t
)
calloc
(
1
,
sizeof
(
CacheNode
));
u_int
indx
=
(
*
(
*
theCache
)
->
hashFunc
)(
*
theCache
,
aKey
);
CacheNode_t
aCacheNode
=
calloc
(
1
,
sizeof
(
CacheNode
));
assert
(
aCacheNode
);
assert
(
aCacheNode
);
/* Initialize the new node. */
aCacheNode
->
theKey
=
aKey
;
aCacheNode
->
theValue
=
aValue
;
aCacheNode
->
nextNode
=
(
*
(
*
theCache
)
->
theNodeTable
)[
indx
];
aCacheNode
->
nextNode
=
(
*
(
*
theCache
)
->
theNodeTable
)
[
indx
];
/* Debugging.
Check the list for another key. */
#ifdef DEBUG
{
CacheNode_t
checkHashNode
=
(
*
(
*
theCache
)
->
theNodeTable
)[
indx
];
{
CacheNode_t
checkHashNode
=
(
*
(
*
theCache
)
->
theNodeTable
)
[
indx
];
while
(
checkHashNode
)
{
assert
(
checkHashNode
->
theKey
!=
aKey
);
assert
(
checkHashNode
->
theKey
!=
aKey
);
checkHashNode
=
checkHashNode
->
nextNode
;
}
}
#endif
/* Install the node as the first element on the list. */
(
*
(
*
theCache
)
->
theNodeTable
)[
indx
]
=
aCacheNode
;
(
*
(
*
theCache
)
->
theNodeTable
)
[
indx
]
=
aCacheNode
;
/* Bump the number of entries in the cache. */
++
(
*
theCache
)
->
entriesInHash
;
++
(
*
theCache
)
->
entriesInHash
;
/* Check the hash table's fullness. We're going
to expand if it is above the fullness level. */
...
...
@@ -224,18 +221,18 @@ hash_add (Cache_t* theCache, void* aKey, void* aValue) {
void
hash_remove
(
Cache_t
theCache
,
void
*
aKey
)
{
hash_remove
(
Cache_t
theCache
,
void
*
aKey
)
{
u_int
indx
=
(
*
theCache
->
hashFunc
)(
theCache
,
aKey
);
CacheNode_t
aCacheNode
=
(
*
theCache
->
theNodeTable
)
[
indx
];
CacheNode_t
aCacheNode
=
(
*
theCache
->
theNodeTable
)
[
indx
];
/* We assume there is an entry in the table. Error if it is not. */
assert
(
aCacheNode
);
assert
(
aCacheNode
);
/* Special case. First element is the key/value pair to be removed. */
if
((
*
theCache
->
compareFunc
)(
aCacheNode
->
theKey
,
aKey
))
{
(
*
theCache
->
theNodeTable
)
[
indx
]
=
aCacheNode
->
nextNode
;
(
*
theCache
->
theNodeTable
)
[
indx
]
=
aCacheNode
->
nextNode
;
free
(
aCacheNode
);
}
else
{
...
...
@@ -251,7 +248,7 @@ hash_remove (Cache_t theCache, void* aKey) {
}
else
prevHashNode
=
aCacheNode
,
aCacheNode
=
aCacheNode
->
nextNode
;
}
while
(
!
removed
&&
aCacheNode
);
assert
(
removed
);
assert
(
removed
);
}
/* Decrement the number of entries in the hash table. */
...
...
@@ -260,8 +257,8 @@ hash_remove (Cache_t theCache, void* aKey) {
CacheNode_t
hash_next
(
Cache_t
theCache
,
CacheNode_t
aCacheNode
)
{
hash_next
(
Cache_t
theCache
,
CacheNode_t
aCacheNode
)
{
CacheNode_t
theCacheNode
=
aCacheNode
;
...
...
@@ -286,8 +283,8 @@ hash_next (Cache_t theCache, CacheNode_t aCacheNode) {
/* Scan the remainder of the buckets looking for an entry
at the head of the list. Return the first item found. */
while
(
theCache
->
lastBucket
<
theCache
->
sizeOfHash
)
if
((
*
theCache
->
theNodeTable
)
[
theCache
->
lastBucket
])
return
(
*
theCache
->
theNodeTable
)
[
theCache
->
lastBucket
];
if
((
*
theCache
->
theNodeTable
)
[
theCache
->
lastBucket
])
return
(
*
theCache
->
theNodeTable
)
[
theCache
->
lastBucket
];
else
++
theCache
->
lastBucket
;
...
...
@@ -302,12 +299,12 @@ hash_next (Cache_t theCache, CacheNode_t aCacheNode) {
* Given key, return its value. Return NULL if the
* key/value pair isn't in the hash.
*/
void
*
hash_value_for_key
(
Cache_t
theCache
,
void
*
aKey
)
{
CacheNode_t
aCacheNode
=
(
*
theCache
->
theNodeTable
)
[(
*
theCache
->
hashFunc
)(
theCache
,
aKey
)];
void
*
retVal
=
NULL
;
void
*
hash_value_for_key
(
Cache_t
theCache
,
void
*
aKey
)
{
CacheNode_t
aCacheNode
=
(
*
theCache
->
theNodeTable
)
[(
*
theCache
->
hashFunc
)(
theCache
,
aKey
)];
void
*
retVal
=
NULL
;
if
(
aCacheNode
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment