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
80b0e34e
Commit
80b0e34e
authored
Sep 20, 1992
by
Richard Stallman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix indentation. Carry out renamings from hash.h.
Rename args and locals also. From-SVN: r2193
parent
d0bd180d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
89 deletions
+90
-89
gcc/objc/hash.c
+90
-89
No files found.
gcc/objc/hash.c
View file @
80b0e34e
...
...
@@ -23,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: /home/fsf/rms/c-runtime/dispatch/RCS/hash.c,v 0.1
4 1992/08/31 21:09:15 dglattin
Exp rms $
$Author:
dglattin
$
$Date: 1992/0
8/31 21:09:15
$
$Header: /home/fsf/rms/c-runtime/dispatch/RCS/hash.c,v 0.1
5 1992/09/02 02:04:32 rms
Exp rms $
$Author:
rms
$
$Date: 1992/0
9/02 02:04:32
$
$Log: hash.c,v $
* Revision 0.15 1992/09/02 02:04:32 rms
* Changed some decls.
*
* Revision 0.14 1992/08/31 21:09:15 dglattin
* minor documentation changes.
*
...
...
@@ -99,99 +102,99 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
These equations are percentages. */
#define FULLNESS(cache) \
((((cache)->size
OfHash * 75) / 100) <= (cache)->entriesInHash
)
((((cache)->size
* 75) / 100) <= (cache)->used
)
#define EXPANSION(cache) \
((cache)->size
OfHash
* 2)
((cache)->size * 2)
Cache_t
hash_new
(
u_int
size
OfHash
,
HashFunc
aHashFunc
,
CompareFunc
aCompareF
unc
)
cache_ptr
hash_new
(
u_int
size
,
hash_func_type
hash_func
,
compare_func_type
compare_f
unc
)
{
Cache_t
retC
ache
;
cache_ptr
c
ache
;
/* Pass me a value greater than 0 and a power of 2. */
assert
(
size
OfHash
);
assert
(
!
(
size
OfHash
&
(
sizeOfHash
-
1
)));
assert
(
size
);
assert
(
!
(
size
&
(
size
-
1
)));
/* Allocate the cache structure. calloc insures
its initialization for default values. */
retCache
=
(
Cache_t
)
calloc
(
1
,
sizeof
(
C
ache
));
assert
(
retC
ache
);
cache
=
(
cache_ptr
)
calloc
(
1
,
sizeof
(
struct
c
ache
));
assert
(
c
ache
);
/* Allocate the array of buckets for the cache.
calloc initializes all of the pointers to NULL. */
retCache
->
theNodeT
able
=
(
CacheNode_t
*
)
calloc
(
sizeOfHash
,
sizeof
(
CacheNode_t
));
assert
(
retCache
->
theNodeT
able
);
cache
->
node_t
able
=
(
node_ptr
*
)
calloc
(
size
,
sizeof
(
node_ptr
));
assert
(
cache
->
node_t
able
);
retCache
->
sizeOfHash
=
sizeOfHash
;
cache
->
size
=
size
;
/* This should work for all processor architectures? */
retCache
->
mask
=
(
sizeOfHash
-
1
);
cache
->
mask
=
(
size
-
1
);
/* Store the hashing function so that codes can be computed. */
retCache
->
hashFunc
=
aHashF
unc
;
cache
->
hash_func
=
hash_f
unc
;
/* Store the function that compares hash keys to
determine if they are equal. */
retCache
->
compareFunc
=
aCompareF
unc
;
cache
->
compare_func
=
compare_f
unc
;
return
retC
ache
;
return
c
ache
;
}
void
hash_delete
(
Cache_t
theC
ache
)
hash_delete
(
cache_ptr
c
ache
)
{
CacheNode_t
aN
ode
;
node_ptr
n
ode
;
/* Purge all key/value pairs from the table. */
while
(
aNode
=
hash_next
(
theC
ache
,
NULL
))
hash_remove
(
theCache
,
aNode
->
theK
ey
);
while
(
node
=
hash_next
(
c
ache
,
NULL
))
hash_remove
(
cache
,
node
->
k
ey
);
/* Release the array of nodes and the cache itself. */
free
(
theCache
->
theNodeT
able
);
free
(
theC
ache
);
free
(
cache
->
node_t
able
);
free
(
c
ache
);
}
void
hash_add
(
Cache_t
*
theCache
,
void
*
aKey
,
void
*
aV
alue
)
hash_add
(
cache_ptr
*
cachep
,
void
*
key
,
void
*
v
alue
)
{
u_int
indx
=
(
*
(
*
theCache
)
->
hashFunc
)(
*
theCache
,
aK
ey
);
CacheNode_t
aCacheNode
=
(
CacheNode_t
)
calloc
(
1
,
sizeof
(
CacheN
ode
));
u_int
indx
=
(
*
(
*
cachep
)
->
hash_func
)(
*
cachep
,
k
ey
);
node_ptr
node
=
(
node_ptr
)
calloc
(
1
,
sizeof
(
struct
cache_n
ode
));
assert
(
aCacheN
ode
);
assert
(
n
ode
);
/* Initialize the new node. */
aCacheNode
->
theKey
=
aK
ey
;
aCacheNode
->
theValue
=
aV
alue
;
aCacheNode
->
nextNode
=
(
*
(
*
theCache
)
->
theNodeTable
)
[
indx
];
node
->
key
=
k
ey
;
node
->
value
=
v
alue
;
node
->
next
=
(
*
(
*
cachep
)
->
node_table
)
[
indx
];
/* Debugging.
Check the list for another key. */
#ifdef DEBUG
{
CacheNode_t
checkHashNode
=
(
*
(
*
theCache
)
->
theNodeTable
)
[
indx
];
{
node_ptr
node1
=
(
*
(
*
cachep
)
->
node_table
)
[
indx
];
while
(
checkHashNode
)
{
while
(
node1
)
{
assert
(
checkHashNode
->
theKey
!=
aK
ey
);
checkHashNode
=
checkHashNode
->
nextNode
;
assert
(
node1
->
key
!=
k
ey
);
node1
=
node1
->
next
;
}
}
#endif
/* Install the node as the first element on the list. */
(
*
(
*
theCache
)
->
theNodeTable
)
[
indx
]
=
aCacheN
ode
;
(
*
(
*
cachep
)
->
node_table
)[
indx
]
=
n
ode
;
/* Bump the number of entries in the cache. */
++
(
*
theCache
)
->
entriesInHash
;
++
(
*
cachep
)
->
used
;
/* Check the hash table's fullness. We're going
to expand if it is above the fullness level. */
if
(
FULLNESS
(
*
theCache
))
{
if
(
FULLNESS
(
*
cachep
))
{
/* The hash table has reached its fullness level. Time to
expand it.
...
...
@@ -199,94 +202,92 @@ hash_add (Cache_t *theCache, void *aKey, void *aValue)
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
(
EXPANSION
(
*
theCache
),
(
*
theCache
)
->
hashF
unc
,
(
*
theCache
)
->
compareF
unc
);
node_ptr
node1
=
NULL
;
cache_ptr
new
=
hash_new
(
EXPANSION
(
*
cachep
),
(
*
cachep
)
->
hash_f
unc
,
(
*
cachep
)
->
compare_f
unc
);
DEBUG_PRINTF
(
stderr
,
"Expanding cache %#x from %d to %d
\n
"
,
*
theCache
,
(
*
theCache
)
->
sizeOfHash
,
newCache
->
sizeOfHash
);
*
cachep
,
(
*
cachep
)
->
size
,
new
->
size
);
/* Copy the nodes from the first hash table to the new one. */
while
(
aNode
=
hash_next
(
*
theCache
,
aNode
))
hash_add
(
&
new
Cache
,
aNode
->
theKey
,
aNode
->
theV
alue
);
while
(
node1
=
hash_next
(
*
cachep
,
node1
))
hash_add
(
&
new
,
node1
->
key
,
node1
->
v
alue
);
/* Trash the old cache. */
hash_delete
(
*
theCache
);
hash_delete
(
*
cachep
);
/* Return a pointer to the new hash table. */
*
theCache
=
newCache
;
*
cachep
=
new
;
}
}
void
hash_remove
(
Cache_t
theCache
,
void
*
aK
ey
)
hash_remove
(
cache_ptr
cache
,
void
*
k
ey
)
{
u_int
indx
=
(
*
theCache
->
hashFunc
)(
theCache
,
aK
ey
);
CacheNode_t
aCacheNode
=
(
*
theCache
->
theNodeTable
)
[
indx
];
u_int
indx
=
(
*
cache
->
hash_func
)(
cache
,
k
ey
);
node_ptr
node
=
(
*
cache
->
node_table
)
[
indx
];
/* We assume there is an entry in the table. Error if it is not. */
assert
(
aCacheN
ode
);
assert
(
n
ode
);
/* Special case. First element is the key/value pair to be removed. */
if
((
*
theCache
->
compareFunc
)(
aCacheNode
->
theKey
,
aK
ey
))
{
(
*
theCache
->
theNodeTable
)
[
indx
]
=
aCacheNode
->
nextNode
;
free
(
aCacheN
ode
);
if
((
*
cache
->
compare_func
)(
node
->
key
,
k
ey
))
{
(
*
cache
->
node_table
)[
indx
]
=
node
->
next
;
free
(
n
ode
);
}
else
{
/* Otherwise, find the hash entry. */
CacheNode_t
prevHashNode
=
aCacheN
ode
;
node_ptr
prev
=
n
ode
;
BOOL
removed
=
NO
;
do
{
if
((
*
theCache
->
compareFunc
)(
aCacheNode
->
theKey
,
aK
ey
))
{
prev
HashNode
->
nextNode
=
aCacheNode
->
nextNode
,
removed
=
YES
;
free
(
aCacheN
ode
);
if
((
*
cache
->
compare_func
)(
node
->
key
,
k
ey
))
{
prev
->
next
=
node
->
next
,
removed
=
YES
;
free
(
n
ode
);
}
else
prev
HashNode
=
aCacheNode
,
aCacheNode
=
aCacheNode
->
nextNode
;
}
while
(
!
removed
&&
aCacheN
ode
);
prev
=
node
,
node
=
node
->
next
;
}
while
(
!
removed
&&
n
ode
);
assert
(
removed
);
}
/* Decrement the number of entries in the hash table. */
--
theCache
->
entriesInHash
;
--
cache
->
used
;
}
CacheNode_t
hash_next
(
Cache_t
theCache
,
CacheNode_t
aCacheN
ode
)
node_ptr
hash_next
(
cache_ptr
cache
,
node_ptr
n
ode
)
{
CacheNode_t
theCacheNode
=
aCacheNode
;
/* If the scan is being started then reset the last node
visitied pointer and bucket index. */
if
(
!
theCacheN
ode
)
theCache
->
lastB
ucket
=
0
;
if
(
!
n
ode
)
cache
->
last_b
ucket
=
0
;
/* If there is a node visited last then check for another
entry in the same bucket; Otherwise step to the next bucket. */
if
(
theCacheNode
)
if
(
theCacheNode
->
nextNode
)
if
(
node
)
{
if
(
node
->
next
)
/* There is a node which follows the last node
returned. Step to that node and retun it. */
return
theCacheNode
->
nextNode
;
return
node
->
next
;
else
++
theCache
->
lastBucket
;
++
cache
->
last_bucket
;
}
/* If the list isn't exhausted then search the buckets for
other nodes. */
if
(
theCache
->
lastBucket
<
theCache
->
sizeOfHash
)
{
if
(
cache
->
last_bucket
<
cache
->
size
)
{
/* 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
->
lastB
ucket
])
return
(
*
theCache
->
theNodeTable
)
[
theCache
->
lastB
ucket
];
while
(
cache
->
last_bucket
<
cache
->
size
)
if
((
*
cache
->
node_table
)[
cache
->
last_b
ucket
])
return
(
*
cache
->
node_table
)[
cache
->
last_b
ucket
];
else
++
theCache
->
lastB
ucket
;
++
cache
->
last_b
ucket
;
/* No further nodes were found in the hash table. */
return
NULL
;
...
...
@@ -300,20 +301,20 @@ hash_next (Cache_t theCache, CacheNode_t aCacheNode)
* key/value pair isn't in the hash.
*/
void
*
hash_value_for_key
(
Cache_t
theCache
,
void
*
aK
ey
)
hash_value_for_key
(
cache_ptr
cache
,
void
*
k
ey
)
{
CacheNode_t
aCacheN
ode
=
(
*
theCache
->
theNodeTable
)
[(
*
theCache
->
hashFunc
)(
theCache
,
aK
ey
)];
void
*
retV
al
=
NULL
;
node_ptr
n
ode
=
(
*
cache
->
node_table
)[(
*
cache
->
hash_func
)(
cache
,
k
ey
)];
void
*
retv
al
=
NULL
;
if
(
aCacheN
ode
)
if
(
n
ode
)
do
{
if
((
*
theCache
->
compareFunc
)(
aCacheNode
->
theKey
,
aK
ey
))
ret
Val
=
aCacheNode
->
theV
alue
;
if
((
*
cache
->
compare_func
)(
node
->
key
,
k
ey
))
ret
val
=
node
->
v
alue
;
else
aCacheNode
=
aCacheNode
->
nextNode
;
}
while
(
!
ret
Val
&&
aCacheN
ode
);
node
=
node
->
next
;
}
while
(
!
ret
val
&&
n
ode
);
return
ret
V
al
;
return
ret
v
al
;
}
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