author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 17 Jun 2015 06:22:00 +0100 | |
branch | jv |
changeset 18487 | 8735bd9eee2f |
parent 18120 | e3a375d5f6a8 |
child 18630 | a74d669db937 |
permissions | -rw-r--r-- |
94 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
187 | 3 |
All Rights Reserved |
94 | 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 |
" |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
13 |
|
94 | 14 |
IdentitySet subclass:#WeakIdentitySet |
1054 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
4350 | 18 |
category:'Collections-Weak' |
94 | 19 |
! |
20 |
||
21 |
!WeakIdentitySet class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
187 | 26 |
All Rights Reserved |
94 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
1263 | 39 |
WeakIdentitySets behave like IdentitySets, as long as the contained |
40 |
objects are still referenced by some other (non-weak) object. |
|
41 |
However, once the last non-weak reference ceases to exist, |
|
42 |
the object will be automatically removed from the Weakcollection |
|
43 |
(with some delay: it will be removed after the next garbage collect). |
|
44 |
||
45 |
This class was added to support dependencies which do not |
|
46 |
prevent objects from dying. (i.e. which do not fill up your memory |
|
47 |
if you forget to #release it). |
|
48 |
||
2307 | 49 |
[Warning:] |
50 |
If you use this, be very careful since the collections size changes |
|
51 |
'magically' - for example, testing for being nonEmpty and then |
|
52 |
removing the first element may fail, since the element may vanish inbetween. |
|
53 |
In general, never trust the value as returned by the size/isEmpty messages. |
|
54 |
WeakIdentitySet is not meant as a 'public' class. |
|
2260 | 55 |
|
1290 | 56 |
[author:] |
57 |
Claus Gittinger |
|
58 |
||
1263 | 59 |
[See also:] |
60 |
WeakArray WeakIdentityDictionary |
|
94 | 61 |
" |
62 |
! ! |
|
63 |
||
111 | 64 |
!WeakIdentitySet class methodsFor:'instance creation'! |
65 |
||
66 |
new |
|
1263 | 67 |
"return a new empty WeakIdentitySet" |
111 | 68 |
|
69 |
^ self new:1 |
|
1263 | 70 |
|
71 |
"Modified: 23.4.1996 / 13:56:08 / cg" |
|
111 | 72 |
! ! |
73 |
||
609 | 74 |
!WeakIdentitySet class methodsFor:'queries'! |
75 |
||
76 |
goodSizeFrom:arg |
|
77 |
"return a good array size for the given argument. |
|
78 |
Since WeakIdentitySets are mostly used for dependency management, we typically |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
79 |
have only a small number of elements in the set. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
80 |
Therefore use exact size for small sets |
9317 | 81 |
(instead of rounding up to the next prime 11)." |
609 | 82 |
|
83 |
arg <= 10 ifTrue:[ |
|
9317 | 84 |
arg < 1 ifTrue:[^ 1]. |
85 |
^ arg. |
|
609 | 86 |
]. |
87 |
^ super goodSizeFrom:arg |
|
88 |
! ! |
|
89 |
||
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
90 |
!WeakIdentitySet methodsFor:'accessing'! |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
91 |
|
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
92 |
firstIfEmpty:exceptionValue |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
93 |
"return the first element of the collection or the |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
94 |
value of the exceptionBlock, if empty. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
95 |
Redefine, since the inherited method does not work if |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
96 |
elements change silently to nil" |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
97 |
|
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
98 |
|index "{ Class: SmallInteger }" |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
99 |
element| |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
100 |
|
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
101 |
index := 1. |
16458 | 102 |
"/ allow for the size to change during enumeration |
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
103 |
[index <= keyArray size] whileTrue:[ |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
104 |
element := keyArray basicAt:index. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
105 |
element notNil ifTrue:[ |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
106 |
element ~~ 0 ifTrue:[ |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
107 |
element ~~ DeletedEntry ifTrue:[ |
14316 | 108 |
element == NilEntry ifTrue:[ |
109 |
element := nil. |
|
110 |
]. |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
111 |
^ element |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
112 |
] |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
113 |
] |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
114 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
115 |
index := index + 1 |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
116 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
117 |
|
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
118 |
^ exceptionValue value. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
119 |
! ! |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
120 |
|
359 | 121 |
!WeakIdentitySet methodsFor:'adding & removing'! |
122 |
||
123 |
add:newElement |
|
14894 | 124 |
"add the argument, newElement to the receiver. |
125 |
Returns the argument, newElement (sigh). |
|
126 |
||
127 |
Redefined to avoid synchronization problems, in case of interrupts |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
128 |
(otherwise, there could be some other operation on the receiver |
2304 | 129 |
done by another process, which garbles my contents)" |
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
130 |
|
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
131 |
|ret| |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
132 |
|
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
133 |
(OperatingSystem blockInterrupts) ifTrue:[ |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
134 |
"/ already blocked |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
135 |
^ super add:newElement. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
136 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
137 |
|
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
138 |
[ |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
139 |
ret := super add:newElement. |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
140 |
] ensure:[ |
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
141 |
OperatingSystem unblockInterrupts |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
142 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
143 |
^ ret |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
144 |
|
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
145 |
"Modified: 29.1.1997 / 15:06:57 / cg" |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
146 |
! |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
147 |
|
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
148 |
remove:anObject ifAbsent:exceptionBlock |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
149 |
"redefined to avoid synchronization problems, in case of interrupts |
359 | 150 |
(otherwise, there could be some other operation on the receiver |
151 |
done by another process, which garbles my contents)" |
|
152 |
||
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
153 |
|ret| |
359 | 154 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
155 |
(OperatingSystem blockInterrupts) ifTrue:[ |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
156 |
"/ already blocked |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
157 |
^ super remove:anObject ifAbsent:exceptionBlock. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
158 |
]. |
359 | 159 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
160 |
[ |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
161 |
ret := super remove:anObject ifAbsent:exceptionBlock |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
162 |
] ensure:[ |
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
163 |
OperatingSystem unblockInterrupts |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
164 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
165 |
^ ret |
359 | 166 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
167 |
"Modified: 29.1.1997 / 15:07:19 / cg" |
359 | 168 |
! ! |
169 |
||
609 | 170 |
!WeakIdentitySet methodsFor:'element disposal'! |
94 | 171 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
172 |
update:something with:aParameter from:changedObject |
609 | 173 |
"an element died - must rehash" |
174 |
||
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
175 |
|wasBlocked| |
111 | 176 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
177 |
something == #ElementExpired ifTrue:[ |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
178 |
" |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
179 |
must block interrupts here - finalization |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
180 |
may be done at low prio in the background |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
181 |
finalizer, we do not want to be interrupted |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
182 |
while rehashing |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
183 |
" |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
184 |
wasBlocked := OperatingSystem blockInterrupts. |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
185 |
keyArray forAllDeadIndicesDo:[:idx | tally := tally - 1] replacingCorpsesWith:DeletedEntry. |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
186 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
187 |
]. |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
188 |
|
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
189 |
"Created: 7.1.1997 / 17:00:33 / stefan" |
94 | 190 |
! ! |
191 |
||
216 | 192 |
!WeakIdentitySet methodsFor:'enumerating'! |
193 |
||
194 |
do:aBlock |
|
195 |
"perform the block for all members in the collection. |
|
196 |
This method has been rewritten to be more robust about |
|
197 |
changed contents while enumerating elements (which might |
|
198 |
happen during change&update processing, if dependents |
|
16604 | 199 |
are added or removed within the update)." |
216 | 200 |
|
201 |
|index "{ Class: SmallInteger }" |
|
202 |
element| |
|
203 |
||
204 |
index := 1. |
|
16458 | 205 |
"/ allow for the size to change during enumeration |
216 | 206 |
[index <= keyArray size] whileTrue:[ |
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
207 |
element := keyArray basicAt:index. |
16458 | 208 |
element notNil ifTrue:[ |
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
209 |
element ~~ 0 ifTrue:[ |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
210 |
element ~~ DeletedEntry ifTrue:[ |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
211 |
aBlock value:element |
16458 | 212 |
] |
2102
7a0e81ed345b
dont clear entries while enumerating
Claus Gittinger <cg@exept.de>
parents:
2091
diff
changeset
|
213 |
] |
7a0e81ed345b
dont clear entries while enumerating
Claus Gittinger <cg@exept.de>
parents:
2091
diff
changeset
|
214 |
]. |
7a0e81ed345b
dont clear entries while enumerating
Claus Gittinger <cg@exept.de>
parents:
2091
diff
changeset
|
215 |
index := index + 1 |
216 | 216 |
] |
217 |
! ! |
|
218 |
||
609 | 219 |
!WeakIdentitySet methodsFor:'private'! |
94 | 220 |
|
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
221 |
findKeyOrNil:key |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
222 |
"Look for the key in the receiver. |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
223 |
If it is found, return return the index, otherwise |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
224 |
the index of the first unused slot. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
225 |
Grow the receiver, if key was not found, and no unused slots were present. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
226 |
|
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
227 |
Warning: an empty slot MUST be filled by the sender - it is only to be sent |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
228 |
by at:put: / add: - like methods." |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
229 |
|
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
230 |
|index "{ Class:SmallInteger }" |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
231 |
length "{ Class:SmallInteger }" |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
232 |
startIndex probe |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
233 |
delIndex "{ Class:SmallInteger }"| |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
234 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
235 |
(OperatingSystem blockInterrupts) ifFalse:[ |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
236 |
"/ |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
237 |
"/ may never be entered with interrupts enabled |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
238 |
"/ |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
239 |
OperatingSystem unblockInterrupts. |
8492 | 240 |
self error:'unblocked call of findKeyOrNil'. |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
241 |
]. |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
242 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
243 |
delIndex := 0. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
244 |
|
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
245 |
length := keyArray basicSize. |
6953
6b3a197638f0
invoke hash/idHash only in one place (initialIndexFor..)
Claus Gittinger <cg@exept.de>
parents:
6421
diff
changeset
|
246 |
startIndex := index := self initialIndexForKey:key. |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
247 |
|
16238 | 248 |
[ |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
249 |
probe := keyArray basicAt:index. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
250 |
key == probe ifTrue:[^ index]. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
251 |
probe isNil ifTrue:[ |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
252 |
delIndex == 0 ifTrue:[^ index]. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
253 |
keyArray basicAt:delIndex put:nil. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
254 |
^ delIndex |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
255 |
]. |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
256 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
257 |
probe == 0 ifTrue:[ |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
258 |
probe := DeletedEntry. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
259 |
keyArray basicAt:index put:probe. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
260 |
tally := tally - 1. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
261 |
]. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
262 |
delIndex == 0 ifTrue:[ |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
263 |
probe == DeletedEntry ifTrue:[ |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
264 |
delIndex := index |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
265 |
] |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
266 |
]. |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
267 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
268 |
index == length ifTrue:[ |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
269 |
index := 1 |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
270 |
] ifFalse:[ |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
271 |
index := index + 1 |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
272 |
]. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
273 |
index == startIndex ifTrue:[ |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
274 |
delIndex ~~ 0 ifTrue:[ |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
275 |
keyArray basicAt:delIndex put:nil. |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
276 |
^ delIndex |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
277 |
]. |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
278 |
^ self grow findKeyOrNil:key |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
279 |
]. |
16238 | 280 |
] loop. |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
281 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
282 |
"Modified: 30.1.1997 / 15:04:38 / cg" |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
283 |
! |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2307
diff
changeset
|
284 |
|
9241 | 285 |
isWeakCollection |
286 |
"return true, if the receiver has weak references to its elements." |
|
287 |
||
288 |
^ true |
|
289 |
! |
|
290 |
||
609 | 291 |
keyContainerOfSize:n |
292 |
"return a container for keys and values of size n. |
|
293 |
use WeakArrays here." |
|
359 | 294 |
|
609 | 295 |
|w| |
296 |
||
297 |
w := WeakArray new:n. |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
298 |
w addDependent:self. |
609 | 299 |
^ w |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
300 |
|
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2026
diff
changeset
|
301 |
"Modified: 7.1.1997 / 17:01:28 / stefan" |
94 | 302 |
! ! |
609 | 303 |
|
636 | 304 |
!WeakIdentitySet class methodsFor:'documentation'! |
305 |
||
306 |
version |
|
16604 | 307 |
^ '$Header: /cvs/stx/stx/libbasic/WeakIdentitySet.st,v 1.42 2014-06-23 09:00:21 cg Exp $' |
636 | 308 |
! ! |
14894 | 309 |