0
|
1 |
'From Smalltalk/X, Version:2.4.7 on 12-Jan-1993 at 21:32:36'!
|
|
2 |
|
|
3 |
Dictionary subclass:#CacheDictionary
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Collections-Unordered'
|
|
8 |
!
|
|
9 |
|
|
10 |
CacheDictionary comment:'
|
|
11 |
|
|
12 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
13 |
All Rights Reserved
|
|
14 |
|
|
15 |
a CacheDictionary is a Dictionary which will not grow - i.e. keep
|
|
16 |
only a limited number of elements.
|
|
17 |
|
|
18 |
%W% %E%
|
|
19 |
|
|
20 |
written jan 93 by claus
|
|
21 |
'!
|
|
22 |
|
|
23 |
!CacheDictionary methodsFor:'private'!
|
|
24 |
|
|
25 |
findKeyOrNil:key
|
|
26 |
"Look for the key in the receiver. If it is found, return
|
|
27 |
the index of the association containing the key, otherwise
|
|
28 |
return the index of the first unused slot. If no empty slot
|
|
29 |
is available, make one empty"
|
|
30 |
|
|
31 |
|index "{ Class:SmallInteger }"
|
|
32 |
length "{ Class:SmallInteger }"
|
|
33 |
startIndex
|
|
34 |
probe|
|
|
35 |
|
|
36 |
length := keyArray basicSize.
|
|
37 |
startIndex := key hash \\ length + 1.
|
|
38 |
|
|
39 |
index := startIndex.
|
|
40 |
[true] whileTrue:[
|
|
41 |
probe := keyArray basicAt:index.
|
|
42 |
(probe == nil or: [probe = key]) ifTrue:[^ index].
|
|
43 |
|
|
44 |
index := index + 1.
|
|
45 |
index > length ifTrue:[
|
|
46 |
index := 1.
|
|
47 |
].
|
|
48 |
index == startIndex ifTrue:[
|
|
49 |
valueArray basicAt:startIndex put:nil.
|
|
50 |
tally := tally - 1.
|
|
51 |
^ startIndex
|
|
52 |
].
|
|
53 |
|
|
54 |
]
|
|
55 |
! !
|