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