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. */
...
@@ -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. */
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 $
$Header: /home/fsf/rms/c-runtime/dispatch/RCS/hash.c,v 0.1
5 1992/09/02 02:04:32 rms
Exp rms $
$Author:
dglattin
$
$Author:
rms
$
$Date: 1992/0
8/31 21:09:15
$
$Date: 1992/0
9/02 02:04:32
$
$Log: hash.c,v $
$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
* Revision 0.14 1992/08/31 21:09:15 dglattin
* minor documentation changes.
* minor documentation changes.
*
*
...
@@ -99,99 +102,99 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
...
@@ -99,99 +102,99 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
These equations are percentages. */
These equations are percentages. */
#define FULLNESS(cache) \
#define FULLNESS(cache) \
((((cache)->size
OfHash * 75) / 100) <= (cache)->entriesInHash
)
((((cache)->size
* 75) / 100) <= (cache)->used
)
#define EXPANSION(cache) \
#define EXPANSION(cache) \
((cache)->size
OfHash
* 2)
((cache)->size * 2)
Cache_t
cache_ptr
hash_new
(
u_int
size
OfHash
,
HashFunc
aHashFunc
,
CompareFunc
aCompareF
unc
)
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. */
/* Pass me a value greater than 0 and a power of 2. */
assert
(
size
OfHash
);
assert
(
size
);
assert
(
!
(
size
OfHash
&
(
sizeOfHash
-
1
)));
assert
(
!
(
size
&
(
size
-
1
)));
/* Allocate the cache structure. calloc insures
/* Allocate the cache structure. calloc insures
its initialization for default values. */
its initialization for default values. */
retCache
=
(
Cache_t
)
calloc
(
1
,
sizeof
(
C
ache
));
cache
=
(
cache_ptr
)
calloc
(
1
,
sizeof
(
struct
c
ache
));
assert
(
retC
ache
);
assert
(
c
ache
);
/* Allocate the array of buckets for the cache.
/* Allocate the array of buckets for the cache.
calloc initializes all of the pointers to NULL. */
calloc initializes all of the pointers to NULL. */
retCache
->
theNodeT
able
cache
->
node_t
able
=
(
CacheNode_t
*
)
calloc
(
sizeOfHash
,
sizeof
(
CacheNode_t
));
=
(
node_ptr
*
)
calloc
(
size
,
sizeof
(
node_ptr
));
assert
(
retCache
->
theNodeT
able
);
assert
(
cache
->
node_t
able
);
retCache
->
sizeOfHash
=
sizeOfHash
;
cache
->
size
=
size
;
/* This should work for all processor architectures? */
/* 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. */
/* 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
/* Store the function that compares hash keys to
determine if they are equal. */
determine if they are equal. */
retCache
->
compareFunc
=
aCompareF
unc
;
cache
->
compare_func
=
compare_f
unc
;
return
retC
ache
;
return
c
ache
;
}
}
void
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. */
/* Purge all key/value pairs from the table. */
while
(
aNode
=
hash_next
(
theC
ache
,
NULL
))
while
(
node
=
hash_next
(
c
ache
,
NULL
))
hash_remove
(
theCache
,
aNode
->
theK
ey
);
hash_remove
(
cache
,
node
->
k
ey
);
/* Release the array of nodes and the cache itself. */
/* Release the array of nodes and the cache itself. */
free
(
theCache
->
theNodeT
able
);
free
(
cache
->
node_t
able
);
free
(
theC
ache
);
free
(
c
ache
);
}
}
void
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
);
u_int
indx
=
(
*
(
*
cachep
)
->
hash_func
)(
*
cachep
,
k
ey
);
CacheNode_t
aCacheNode
=
(
CacheNode_t
)
calloc
(
1
,
sizeof
(
CacheN
ode
));
node_ptr
node
=
(
node_ptr
)
calloc
(
1
,
sizeof
(
struct
cache_n
ode
));
assert
(
aCacheN
ode
);
assert
(
n
ode
);
/* Initialize the new node. */
/* Initialize the new node. */
aCacheNode
->
theKey
=
aK
ey
;
node
->
key
=
k
ey
;
aCacheNode
->
theValue
=
aV
alue
;
node
->
value
=
v
alue
;
aCacheNode
->
nextNode
=
(
*
(
*
theCache
)
->
theNodeTable
)
[
indx
];
node
->
next
=
(
*
(
*
cachep
)
->
node_table
)
[
indx
];
/* Debugging.
/* Debugging.
Check the list for another key. */
Check the list for another key. */
#ifdef DEBUG
#ifdef DEBUG
{
CacheNode_t
checkHashNode
=
(
*
(
*
theCache
)
->
theNodeTable
)
[
indx
];
{
node_ptr
node1
=
(
*
(
*
cachep
)
->
node_table
)
[
indx
];
while
(
checkHashNode
)
{
while
(
node1
)
{
assert
(
checkHashNode
->
theKey
!=
aK
ey
);
assert
(
node1
->
key
!=
k
ey
);
checkHashNode
=
checkHashNode
->
nextNode
;
node1
=
node1
->
next
;
}
}
}
}
#endif
#endif
/* Install the node as the first element on the list. */
/* 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. */
/* Bump the number of entries in the cache. */
++
(
*
theCache
)
->
entriesInHash
;
++
(
*
cachep
)
->
used
;
/* Check the hash table's fullness. We're going
/* Check the hash table's fullness. We're going
to expand if it is above the fullness level. */
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
/* The hash table has reached its fullness level. Time to
expand it.
expand it.
...
@@ -199,94 +202,92 @@ hash_add (Cache_t *theCache, void *aKey, void *aValue)
...
@@ -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
I'm using a slow method here but is built on other
primitive functions thereby increasing its
primitive functions thereby increasing its
correctness. */
correctness. */
CacheNode_t
aNode
=
NULL
;
node_ptr
node1
=
NULL
;
Cache_t
newCache
=
hash_new
(
EXPANSION
(
*
theCache
),
cache_ptr
new
=
hash_new
(
EXPANSION
(
*
cachep
),
(
*
theCache
)
->
hashF
unc
,
(
*
cachep
)
->
hash_f
unc
,
(
*
theCache
)
->
compareF
unc
);
(
*
cachep
)
->
compare_f
unc
);
DEBUG_PRINTF
(
stderr
,
"Expanding cache %#x from %d to %d
\n
"
,
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. */
/* Copy the nodes from the first hash table to the new one. */
while
(
aNode
=
hash_next
(
*
theCache
,
aNode
))
while
(
node1
=
hash_next
(
*
cachep
,
node1
))
hash_add
(
&
new
Cache
,
aNode
->
theKey
,
aNode
->
theV
alue
);
hash_add
(
&
new
,
node1
->
key
,
node1
->
v
alue
);
/* Trash the old cache. */
/* Trash the old cache. */
hash_delete
(
*
theCache
);
hash_delete
(
*
cachep
);
/* Return a pointer to the new hash table. */
/* Return a pointer to the new hash table. */
*
theCache
=
newCache
;
*
cachep
=
new
;
}
}
}
}
void
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
);
u_int
indx
=
(
*
cache
->
hash_func
)(
cache
,
k
ey
);
CacheNode_t
aCacheNode
=
(
*
theCache
->
theNodeTable
)
[
indx
];
node_ptr
node
=
(
*
cache
->
node_table
)
[
indx
];
/* We assume there is an entry in the table. Error if it is not. */
/* 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. */
/* Special case. First element is the key/value pair to be removed. */
if
((
*
theCache
->
compareFunc
)(
aCacheNode
->
theKey
,
aK
ey
))
{
if
((
*
cache
->
compare_func
)(
node
->
key
,
k
ey
))
{
(
*
theCache
->
theNodeTable
)
[
indx
]
=
aCacheNode
->
nextNode
;
(
*
cache
->
node_table
)[
indx
]
=
node
->
next
;
free
(
aCacheN
ode
);
free
(
n
ode
);
}
else
{
}
else
{
/* Otherwise, find the hash entry. */
/* Otherwise, find the hash entry. */
CacheNode_t
prevHashNode
=
aCacheN
ode
;
node_ptr
prev
=
n
ode
;
BOOL
removed
=
NO
;
BOOL
removed
=
NO
;
do
{
do
{
if
((
*
theCache
->
compareFunc
)(
aCacheNode
->
theKey
,
aK
ey
))
{
if
((
*
cache
->
compare_func
)(
node
->
key
,
k
ey
))
{
prev
HashNode
->
nextNode
=
aCacheNode
->
nextNode
,
removed
=
YES
;
prev
->
next
=
node
->
next
,
removed
=
YES
;
free
(
aCacheN
ode
);
free
(
n
ode
);
}
else
}
else
prev
HashNode
=
aCacheNode
,
aCacheNode
=
aCacheNode
->
nextNode
;
prev
=
node
,
node
=
node
->
next
;
}
while
(
!
removed
&&
aCacheN
ode
);
}
while
(
!
removed
&&
n
ode
);
assert
(
removed
);
assert
(
removed
);
}
}
/* Decrement the number of entries in the hash table. */
/* Decrement the number of entries in the hash table. */
--
theCache
->
entriesInHash
;
--
cache
->
used
;
}
}
CacheNode_t
node_ptr
hash_next
(
Cache_t
theCache
,
CacheNode_t
aCacheN
ode
)
hash_next
(
cache_ptr
cache
,
node_ptr
n
ode
)
{
{
CacheNode_t
theCacheNode
=
aCacheNode
;
/* If the scan is being started then reset the last node
/* If the scan is being started then reset the last node
visitied pointer and bucket index. */
visitied pointer and bucket index. */
if
(
!
theCacheN
ode
)
if
(
!
n
ode
)
theCache
->
lastB
ucket
=
0
;
cache
->
last_b
ucket
=
0
;
/* If there is a node visited last then check for another
/* If there is a node visited last then check for another
entry in the same bucket; Otherwise step to the next bucket. */
entry in the same bucket; Otherwise step to the next bucket. */
if
(
theCacheNode
)
if
(
node
)
{
if
(
theCacheNode
->
nextNode
)
if
(
node
->
next
)
/* There is a node which follows the last node
/* There is a node which follows the last node
returned. Step to that node and retun it. */
returned. Step to that node and retun it. */
return
theCacheNode
->
nextNode
;
return
node
->
next
;
else
else
++
theCache
->
lastBucket
;
++
cache
->
last_bucket
;
}
/* If the list isn't exhausted then search the buckets for
/* If the list isn't exhausted then search the buckets for
other nodes. */
other nodes. */
if
(
theCache
->
lastBucket
<
theCache
->
sizeOfHash
)
{
if
(
cache
->
last_bucket
<
cache
->
size
)
{
/* Scan the remainder of the buckets looking for an entry
/* Scan the remainder of the buckets looking for an entry
at the head of the list. Return the first item found. */
at the head of the list. Return the first item found. */
while
(
theCache
->
lastBucket
<
theCache
->
sizeOfHash
)
while
(
cache
->
last_bucket
<
cache
->
size
)
if
((
*
theCache
->
theNodeTable
)
[
theCache
->
lastB
ucket
])
if
((
*
cache
->
node_table
)[
cache
->
last_b
ucket
])
return
(
*
theCache
->
theNodeTable
)
[
theCache
->
lastB
ucket
];
return
(
*
cache
->
node_table
)[
cache
->
last_b
ucket
];
else
else
++
theCache
->
lastB
ucket
;
++
cache
->
last_b
ucket
;
/* No further nodes were found in the hash table. */
/* No further nodes were found in the hash table. */
return
NULL
;
return
NULL
;
...
@@ -300,20 +301,20 @@ hash_next (Cache_t theCache, CacheNode_t aCacheNode)
...
@@ -300,20 +301,20 @@ hash_next (Cache_t theCache, CacheNode_t aCacheNode)
* key/value pair isn't in the hash.
* key/value pair isn't in the hash.
*/
*/
void
*
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
node_ptr
n
ode
=
(
*
theCache
->
theNodeTable
)
[(
*
theCache
->
hashFunc
)(
theCache
,
aK
ey
)];
=
(
*
cache
->
node_table
)[(
*
cache
->
hash_func
)(
cache
,
k
ey
)];
void
*
retV
al
=
NULL
;
void
*
retv
al
=
NULL
;
if
(
aCacheN
ode
)
if
(
n
ode
)
do
{
do
{
if
((
*
theCache
->
compareFunc
)(
aCacheNode
->
theKey
,
aK
ey
))
if
((
*
cache
->
compare_func
)(
node
->
key
,
k
ey
))
ret
Val
=
aCacheNode
->
theV
alue
;
ret
val
=
node
->
v
alue
;
else
else
aCacheNode
=
aCacheNode
->
nextNode
;
node
=
node
->
next
;
}
while
(
!
ret
Val
&&
aCacheN
ode
);
}
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