2
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
84
|
3 |
All Rights Reserved
|
2
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
0
|
12 |
|
|
13 |
Dictionary subclass:#CacheDictionary
|
238
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Unordered'
|
0
|
18 |
!
|
|
19 |
|
31
|
20 |
!CacheDictionary class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
84
|
25 |
All Rights Reserved
|
0
|
26 |
|
31
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
0
|
35 |
|
31
|
36 |
documentation
|
|
37 |
"
|
|
38 |
a CacheDictionary is a Dictionary which will not grow - i.e. keep
|
|
39 |
only a limited number of elements.
|
|
40 |
It can be used as a cache, for keeping recently used objects alive.
|
254
|
41 |
|
|
42 |
[author:]
|
|
43 |
Claus Gittinger
|
31
|
44 |
"
|
|
45 |
! !
|
0
|
46 |
|
|
47 |
!CacheDictionary methodsFor:'private'!
|
|
48 |
|
13
|
49 |
emptyCheck
|
489
|
50 |
"redefined - never shrink"
|
13
|
51 |
|
|
52 |
^ self
|
489
|
53 |
|
|
54 |
"Modified: 30.1.1997 / 15:17:12 / cg"
|
13
|
55 |
!
|
|
56 |
|
0
|
57 |
findKeyOrNil:key
|
|
58 |
"Look for the key in the receiver. If it is found, return
|
|
59 |
the index of the association containing the key, otherwise
|
|
60 |
return the index of the first unused slot. If no empty slot
|
489
|
61 |
is available, make one empty (but never grow)."
|
0
|
62 |
|
|
63 |
|index "{ Class:SmallInteger }"
|
|
64 |
length "{ Class:SmallInteger }"
|
13
|
65 |
startIndex freeIndex
|
0
|
66 |
probe|
|
|
67 |
|
|
68 |
length := keyArray basicSize.
|
459
|
69 |
startIndex := key hash * 2 \\ length + 1.
|
0
|
70 |
|
|
71 |
index := startIndex.
|
|
72 |
[true] whileTrue:[
|
238
|
73 |
probe := keyArray basicAt:index.
|
489
|
74 |
probe = key ifTrue:[^ index].
|
|
75 |
probe isNil ifTrue:[
|
|
76 |
freeIndex isNil ifTrue:[^ index].
|
|
77 |
keyArray basicAt:freeIndex put:nil.
|
|
78 |
valueArray basicAt:freeIndex put:nil.
|
|
79 |
^ freeIndex
|
|
80 |
].
|
0
|
81 |
|
238
|
82 |
(freeIndex isNil and:[probe == DeletedEntry]) ifTrue:[
|
|
83 |
freeIndex := index
|
|
84 |
].
|
13
|
85 |
|
238
|
86 |
index := index + 1.
|
|
87 |
index > length ifTrue:[
|
|
88 |
index := 1.
|
|
89 |
].
|
|
90 |
index == startIndex ifTrue:[
|
489
|
91 |
"/ mhmh - actually, a kind of round-robin would be better
|
238
|
92 |
freeIndex isNil ifTrue:[
|
|
93 |
freeIndex := startIndex
|
|
94 |
].
|
13
|
95 |
|
238
|
96 |
keyArray basicAt:freeIndex put:nil.
|
|
97 |
valueArray basicAt:freeIndex put:nil.
|
|
98 |
tally := tally - 1.
|
|
99 |
^ freeIndex
|
|
100 |
].
|
0
|
101 |
|
|
102 |
]
|
238
|
103 |
|
489
|
104 |
"Modified: 30.1.1997 / 15:16:25 / cg"
|
|
105 |
!
|
|
106 |
|
|
107 |
fullCheck
|
|
108 |
"redefined - never grow"
|
|
109 |
|
|
110 |
^ self
|
|
111 |
|
|
112 |
"Modified: 30.1.1997 / 15:17:18 / cg"
|
0
|
113 |
! !
|
125
|
114 |
|
134
|
115 |
!CacheDictionary class methodsFor:'documentation'!
|
|
116 |
|
|
117 |
version
|
489
|
118 |
^ '$Header: /cvs/stx/stx/libbasic2/CacheDictionary.st,v 1.16 1997-01-30 14:38:03 cg Exp $'
|
134
|
119 |
! !
|