author | Claus Gittinger <cg@exept.de> |
Sun, 10 Feb 2019 14:43:52 +0100 | |
changeset 23694 | e4a55e9a2735 |
parent 23330 | 0bec0f8e3df9 |
child 23845 | ad43d2e69458 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 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 |
" |
|
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5335
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5335
diff
changeset
|
13 |
|
17263
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
14 |
"{ NameSpace: Smalltalk }" |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
15 |
|
1 | 16 |
Collection subclass:#Set |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
17 |
instanceVariableNames:'tally keyArray' |
14314 | 18 |
classVariableNames:'DeletedEntry NilEntry' |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
19 |
poolDictionaries:'' |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
20 |
category:'Collections-Unordered' |
1 | 21 |
! |
22 |
||
2272 | 23 |
Object subclass:#EmptySlot |
2259 | 24 |
instanceVariableNames:'' |
4017
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
25 |
classVariableNames:'TheOneAndOnlyInstance' |
2259 | 26 |
poolDictionaries:'' |
27 |
privateIn:Set |
|
28 |
! |
|
29 |
||
14314 | 30 |
Object subclass:#NilKey |
31 |
instanceVariableNames:'' |
|
32 |
classVariableNames:'TheOneAndOnlyInstance' |
|
33 |
poolDictionaries:'' |
|
34 |
privateIn:Set |
|
35 |
! |
|
36 |
||
2259 | 37 |
!Set class methodsFor:'documentation'! |
88 | 38 |
|
39 |
copyright |
|
40 |
" |
|
41 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
159 | 42 |
All Rights Reserved |
1 | 43 |
|
88 | 44 |
This software is furnished under a license and may be used |
45 |
only in accordance with the terms of that license and with the |
|
46 |
inclusion of the above copyright notice. This software may not |
|
47 |
be provided or otherwise made available to, or used by, any |
|
48 |
other person. No title to or ownership of the software is |
|
49 |
hereby transferred. |
|
50 |
" |
|
51 |
! |
|
1 | 52 |
|
88 | 53 |
documentation |
54 |
" |
|
55 |
a Set is a collection where each element occurs at most once. |
|
14300 | 56 |
The inclusion test is done using equality (=) for comparison; |
95 | 57 |
see IdentitySet for sets using identity compare. |
6191 | 58 |
Keep in mind, that a regular Set therefore treats 3.0 and 3 as equal |
59 |
and therefore: |
|
14300 | 60 |
(Set with:3.0) includes:3 |
6191 | 61 |
will return true (since 3.0 and 3 are equal). |
62 |
In contrast, an IdentitySet will return false, because 3.0 and 3 are not |
|
63 |
identical. |
|
64 |
||
95 | 65 |
Sets use hashing for fast access, this access is considerably faster, |
66 |
if a good hash-number is returned by the elements. |
|
362 | 67 |
|
68 |
Notice that the default hash (Object>>hash) is not perfect; due to |
|
69 |
the implementation of hash-keys in ST/X, increased hash collisions |
|
70 |
are to be expected for large sets (say: > 20000 element). |
|
71 |
If your objects are heavyly used in sets or dictionaries, and you need |
|
72 |
big collections, your instances may provide a better hash values. |
|
95 | 73 |
|
345 | 74 |
Performance hints: |
657 | 75 |
If only symbols or smallIntegers are used as keys, |
362 | 76 |
use an instance of IdentitySet for slightly better performance, |
77 |
since both hashing and comparison is faster. |
|
345 | 78 |
|
79 |
If you have a rough idea how big the set is going to grow, |
|
80 |
create it using #new: instead of #new. Even if the size given is a |
|
81 |
poor guess (say half of the real size), there is some 20-30% performance |
|
14300 | 82 |
win to expect, since many resizing operations of the set are avoided |
83 |
(resizing is expensive, as the set does a rehash). |
|
345 | 84 |
|
95 | 85 |
Examples: |
86 |
||
14300 | 87 |
|s| |
88 |
s := Set new. |
|
89 |
s add:'hello'. |
|
90 |
s add:'world'. |
|
91 |
s add:#foo. |
|
92 |
s add:1.2345678. |
|
93 |
s add:'hello'. |
|
95 | 94 |
|
14300 | 95 |
s printCR. |
96 |
's size -> ' print. s size printCR. |
|
97 |
'(s includes:''hello'') -> ' print. (s includes:'hello') printCR. |
|
98 |
'(s includes:#foo) -> ' print. (s includes:#foo) printCR. |
|
99 |
'(s includes:''foo'') -> ' print. (s includes:'foo') printCR. |
|
100 |
'(s includes:#bar) -> ' print. (s includes:#bar) printCR. |
|
1290 | 101 |
|
102 |
[author:] |
|
14300 | 103 |
Claus Gittinger |
88 | 104 |
" |
105 |
! ! |
|
1 | 106 |
|
2259 | 107 |
!Set class methodsFor:'initialization'! |
41 | 108 |
|
109 |
initialize |
|
110 |
"initialize the Set class" |
|
111 |
||
112 |
DeletedEntry isNil ifTrue:[ |
|
14314 | 113 |
DeletedEntry := EmptySlot new. |
114 |
NilEntry := NilKey new. |
|
41 | 115 |
]. |
116 |
||
14314 | 117 |
" |
118 |
Set initialize |
|
119 |
" |
|
2259 | 120 |
|
121 |
"Modified: 24.1.1997 / 21:09:00 / cg" |
|
41 | 122 |
! ! |
123 |
||
2259 | 124 |
!Set class methodsFor:'instance creation'! |
1 | 125 |
|
6083 | 126 |
decodeFromLiteralArray:anArray |
127 |
"create & return a new instance from information encoded in anArray." |
|
128 |
||
8831
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
129 |
|set |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
130 |
sz "{ Class: SmallInteger }"| |
6083 | 131 |
|
8831
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
132 |
sz := anArray size. |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
133 |
set := self new:sz-1. |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
134 |
2 to:sz do:[:idx| set add:(anArray at:idx) decodeAsLiteralArray]. |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
135 |
^ set |
6083 | 136 |
|
137 |
" |
|
138 |
(Set with:1234 |
|
8831
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
139 |
with:(1 @ 2) |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
140 |
with:'hello' |
6083 | 141 |
) literalArrayEncoding decodeAsLiteralArray |
142 |
" |
|
143 |
! |
|
144 |
||
1 | 145 |
new |
146 |
"return a new empty Set" |
|
147 |
||
23330 | 148 |
^ self new:5 |
149 |
||
150 |
"Modified: / 11-09-2018 / 17:58:42 / Stefan Vogel" |
|
1 | 151 |
! |
152 |
||
153 |
new:anInteger |
|
154 |
"return a new empty Set with space for anInteger elements" |
|
155 |
||
159 | 156 |
" |
157 |
make it somewhat bigger; hashing works better if fill grade is |
|
158 |
below 10% (make it 75% here ..) |
|
159 |
" |
|
23330 | 160 |
^ self basicNew initializeForCapacity:(anInteger * 4 // 3)+1 |
161 |
||
162 |
"Modified: / 11-09-2018 / 17:58:51 / Stefan Vogel" |
|
22307 | 163 |
! |
164 |
||
165 |
newWithCapacity:size |
|
166 |
"return a new empty Collection with capacity for n elements." |
|
167 |
||
168 |
^ self new:size |
|
169 |
||
170 |
"Created: / 10-10-2017 / 17:58:47 / stefan" |
|
159 | 171 |
! ! |
172 |
||
2259 | 173 |
!Set class methodsFor:'queries'! |
252 | 174 |
|
175 |
goodSizeFrom:arg |
|
176 |
"return a good array size for the given argument. |
|
177 |
Returns the next prime after arg, since prime sizes are good for hashing." |
|
178 |
||
302 | 179 |
|n| |
180 |
||
2461
2d65e1845502
minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
181 |
"/ arg <= 11 ifTrue:[^ 11]. |
2d65e1845502
minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
182 |
"/ n := arg * 3 // 2. |
252 | 183 |
|
2461
2d65e1845502
minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
184 |
arg <= 7 ifTrue:[^ 7]. |
2d65e1845502
minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
185 |
n := arg. |
302 | 186 |
|
252 | 187 |
" |
188 |
mhmh - this returns good numbers for collections with up-to about |
|
189 |
500k elements; if you have bigger ones, add some more primes here ... |
|
190 |
" |
|
302 | 191 |
n <= 524288 ifTrue:[ |
9318 | 192 |
"2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288" |
193 |
^ #(7 7 11 17 37 67 131 257 521 1031 2053 4099 8209 16411 32771 65537 131101 262147 524309) at:(n highBit) |
|
252 | 194 |
]. |
2461
2d65e1845502
minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
195 |
|
9318 | 196 |
^ n nextPrime |
252 | 197 |
! ! |
198 |
||
3048 | 199 |
!Set class methodsFor:'utilities'! |
200 |
||
201 |
rehashAllSubInstances |
|
202 |
"rehash all sets & dictionaries. |
|
203 |
Useful utility if hash/identityHash method was changed |
|
204 |
of some object which is known to be kept in a set" |
|
205 |
||
206 |
self allSubInstances do:[:s | s rehash] |
|
207 |
||
208 |
" |
|
209 |
Set rehashAllSubInstances |
|
210 |
" |
|
211 |
||
212 |
"Created: / 24.10.1997 / 23:13:44 / cg" |
|
213 |
! ! |
|
214 |
||
23330 | 215 |
|
7268 | 216 |
!Set methodsFor:'Compatibility-ST80'! |
6991
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
217 |
|
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
218 |
initialIndexFor:hashKey boundedBy:length |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
219 |
"for ST-80 compatibility only; it is (currently) not used in this |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
220 |
implementation of sets. Therefore, in ST/X it does not make sense |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
221 |
to redefine it. (which may be a bad design decision, but slightly |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
222 |
improves performance, by avoiding an extra message send ...)" |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
223 |
|
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
224 |
|index "{ Class:SmallInteger }"| |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
225 |
|
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
226 |
index := hashKey bitAnd:16r3FFFFFFF. |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
227 |
index < 16r1FFFFFFF ifTrue:[ |
6994 | 228 |
index := index * 2 |
6991
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
229 |
]. |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
230 |
index := index \\ length + 1. |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
231 |
^ index. |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
232 |
|
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
233 |
"Modified: 1.3.1997 / 01:01:13 / cg" |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
234 |
! ! |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
235 |
|
7311
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
236 |
!Set methodsFor:'Compatibility-Squeak'! |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
237 |
|
11052 | 238 |
copyWithout:elementToSkip |
239 |
"return a new collection consisting of a copy of the receiver, with |
|
240 |
ALL elements equal to elementToSkip are left out. |
|
241 |
No error is reported, if elementToSkip is not in the collection." |
|
242 |
||
243 |
^ self select:[:each | each ~= elementToSkip] |
|
7311
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
244 |
|
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
245 |
" |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
246 |
#(1 2 3 4 5 6 7) asSet copyWithout:5 |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
247 |
" |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
248 |
! |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
249 |
|
14019 | 250 |
copyWithoutAll:elementsToSkip |
251 |
"return a new collection consisting of a copy of the receiver, with |
|
252 |
ALL elements equal to elementToSkip are left out. |
|
253 |
No error is reported, if elementsToSkip is not in the collection." |
|
254 |
||
255 |
elementsToSkip size * self size > 10000 ifTrue:[ |
|
256 |
"speed up everything" |
|
257 |
^ self \ (elementsToSkip asSet). |
|
258 |
]. |
|
259 |
^ self \ elementsToSkip |
|
7311
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
260 |
|
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
261 |
" |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
262 |
#(1 2 3 4 5 6 7) asSet copyWithoutAll:#(3 5 7 9) |
14019 | 263 |
#(a b c d e f) asIdentitySet copyWithoutAll:#(d e f) |
264 |
#('a' 'b' 'c' 'd' 'e' 'f') asIdentitySet copyWithoutAll:#('d' 'e' 'f') |
|
265 |
#('a' 'b' 'c' 'd' 'e' 'f') asSet copyWithoutAll:#('d' 'e' 'f') |
|
7311
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
266 |
" |
12342 | 267 |
! |
268 |
||
269 |
like:anObject |
|
270 |
"Answer an object in the receiver that is equal to anObject, |
|
271 |
nil if no such object is found. |
|
272 |
Relies heavily on hash properties (i.e. that two object's hashes are equal |
|
273 |
if the two object compare equal)" |
|
274 |
||
275 |
^ self elementAt:anObject ifAbsent:[ nil ] |
|
276 |
||
277 |
" |
|
278 |
(Set withAll:#(10.0 20.0 30.0 40.0)) like:20 |
|
279 |
" |
|
7311
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
280 |
! ! |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
281 |
|
609 | 282 |
!Set methodsFor:'accessing'! |
283 |
||
12734 | 284 |
addFirst:anObject |
285 |
"add the argument, anObject to the receiver. |
|
286 |
If the receiver is ordered, the new element will be added at the beginning. |
|
287 |
An error is raised here - it does not make sense for unordered collections" |
|
288 |
||
289 |
^ self shouldNotImplement |
|
290 |
! |
|
291 |
||
609 | 292 |
at:index |
293 |
"report an error: at: is not allowed for Sets" |
|
294 |
||
295 |
^ self errorNotKeyed |
|
296 |
! |
|
297 |
||
298 |
at:index put:anObject |
|
299 |
"report an error: at:put: is not allowed for Sets" |
|
300 |
||
301 |
^ self errorNotKeyed |
|
2469
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
302 |
! |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
303 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
304 |
elementAt:anObject |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
305 |
"return the element, if contained in the set. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
306 |
If there is none, report an error. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
307 |
This may seem confusing at first - however, it is useful with |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
308 |
non-identitysets, to find an existing element, for a |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
309 |
given equal (but not identical) object. |
12342 | 310 |
This is the same functionality as provided by the goodies/KeyedSet goody." |
2469
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
311 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
312 |
^ self elementAt:anObject ifAbsent:[^ self errorNotFound]. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
313 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
314 |
"Modified: 20.3.1997 / 20:35:24 / cg" |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
315 |
! |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
316 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
317 |
elementAt:anObject ifAbsent:exceptionBlock |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
318 |
"return the element, if contained in the set. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
319 |
If there is none, return the result from evaluating exceptionBlock. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
320 |
This may seem confusing at first - however, it is useful with |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
321 |
non-identitysets, to find an existing element, for a |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
322 |
given equal (but not identical) object. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
323 |
This is the same functionality as provided by the goodies/KeyedSet |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
324 |
goody." |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
325 |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
326 |
|index "{ Class: SmallInteger }" ret| |
2469
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
327 |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
328 |
index := self find:(anObject ? NilEntry)ifAbsent:0. |
2469
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
329 |
index == 0 ifTrue:[ |
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
330 |
^ exceptionBlock value |
2469
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
331 |
]. |
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
332 |
ret := keyArray basicAt:index. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
333 |
ret == NilEntry ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
334 |
ret := nil. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
335 |
]. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
336 |
^ ret. |
2469
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
337 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
338 |
"Created: 20.3.1997 / 20:34:07 / cg" |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
339 |
"Modified: 20.3.1997 / 20:35:49 / cg" |
12734 | 340 |
! |
341 |
||
342 |
removeLast |
|
343 |
"remove the last element from the receiver. |
|
344 |
Return the removed element. |
|
345 |
An error is raised here - it does not make sense for unordered collections" |
|
346 |
||
347 |
^ self shouldNotImplement |
|
348 |
! |
|
349 |
||
350 |
reverseDo:aBlock |
|
351 |
"evaluate the argument, aBlock for each element in reverse order. |
|
352 |
An error is raised here - it does not make sense for unordered collections" |
|
353 |
||
354 |
^ self shouldNotImplement |
|
609 | 355 |
! ! |
356 |
||
357 |
!Set methodsFor:'adding & removing'! |
|
358 |
||
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
359 |
add:keyArg |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
360 |
"add the argument, anObject to the receiver. |
14895 | 361 |
Return the added element. |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
362 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
363 |
WARNING: do not add elements while iterating over the receiver. |
10868 | 364 |
Iterate over a copy to do this." |
609 | 365 |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
366 |
|key index "{ Class: SmallInteger }"| |
609 | 367 |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
368 |
keyArg isNil ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
369 |
key := NilEntry. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
370 |
] ifFalse:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
371 |
key := keyArg. |
5335
fae7e0698241
added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents:
5298
diff
changeset
|
372 |
]. |
609 | 373 |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
374 |
index := self findKeyOrNil:key. |
5335
fae7e0698241
added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents:
5298
diff
changeset
|
375 |
(keyArray basicAt:index) isNil ifTrue:[ |
10868 | 376 |
"/ not already there |
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
377 |
keyArray basicAt:index put:key. |
10868 | 378 |
tally := tally + 1. |
5335
fae7e0698241
added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents:
5298
diff
changeset
|
379 |
|
17263
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
380 |
self possiblyGrow. |
609 | 381 |
]. |
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
382 |
^ keyArg |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
383 |
|
2328
0fd1d715e5a9
oops - the last one was not good
Claus Gittinger <cg@exept.de>
parents:
2323
diff
changeset
|
384 |
"Modified: 30.1.1997 / 14:58:08 / cg" |
609 | 385 |
! |
386 |
||
23189 | 387 |
addOrReplace:anObject |
388 |
"add the argument, anObject to the receiver. |
|
389 |
If it is already included, replace it by anObject. |
|
390 |
Return nil, if anObject was not present in the receiver, |
|
391 |
otherwise the element that has been replaced. |
|
392 |
||
393 |
WARNING: do not add elements while iterating over the receiver. |
|
394 |
Iterate over a copy to do this." |
|
395 |
||
396 |
|key index "{ Class: SmallInteger }" existingKey| |
|
397 |
||
398 |
anObject isNil ifTrue:[ |
|
399 |
key := NilEntry. |
|
400 |
] ifFalse:[ |
|
401 |
key := anObject. |
|
402 |
]. |
|
403 |
||
404 |
index := self findKeyOrNil:key. |
|
405 |
existingKey := keyArray basicAt:index. |
|
406 |
keyArray basicAt:index put:key. |
|
407 |
existingKey isNil ifTrue:[ |
|
408 |
"/ not already there |
|
409 |
tally := tally + 1. |
|
410 |
self possiblyGrow. |
|
411 |
]. |
|
412 |
^ existingKey |
|
413 |
||
414 |
" |
|
415 |
Note that 1 is replaced by 1.0: |
|
416 |
||
417 |
self new |
|
418 |
addOrReplace:1; |
|
419 |
addOrReplace:2; |
|
420 |
addOrReplace:nil; |
|
421 |
addOrReplace:1.0; |
|
422 |
yourself |
|
423 |
" |
|
424 |
||
425 |
"Created: / 03-07-2018 / 19:13:58 / Stefan Vogel" |
|
426 |
"Modified (comment): / 03-07-2018 / 23:38:13 / Stefan Vogel" |
|
427 |
! |
|
428 |
||
17410 | 429 |
clearContents |
22571 | 430 |
"remove all elements from the receiver, but do not resize the underlying keyArray. |
21348 | 431 |
Returns the receiver. |
432 |
Similar to removeAll, but might behave better, |
|
433 |
if the receiver is to be filled again afterwards." |
|
17410 | 434 |
|
435 |
keyArray atAllPut:nil. |
|
17413 | 436 |
tally := 0. |
21348 | 437 |
|
438 |
"Modified (comment): / 06-02-2017 / 12:55:05 / cg" |
|
17410 | 439 |
! |
440 |
||
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
441 |
remove:oldObjectArg ifAbsent:exceptionBlock |
19080 | 442 |
"remove the first occurrence of oldObject from the collection and return it. |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
443 |
If it was not in the collection return the value of exceptionBlock. |
6191 | 444 |
Notice, that the returned object could be non-identical to the argument |
445 |
(although it will always be equal). |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
446 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
447 |
WARNING: do not remove elements while iterating over the receiver. |
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
448 |
See #saveRemove: to do this." |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
449 |
|
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
450 |
|oldObject index next removedObject| |
609 | 451 |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
452 |
oldObjectArg isNil ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
453 |
oldObject := NilEntry. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
454 |
] ifFalse:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
455 |
oldObject := oldObjectArg. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
456 |
]. |
3265
18d96c910653
handle attempt to remove nil.
Claus Gittinger <cg@exept.de>
parents:
3261
diff
changeset
|
457 |
|
609 | 458 |
index := self find:oldObject ifAbsent:0. |
459 |
index == 0 ifTrue:[^ exceptionBlock value]. |
|
460 |
||
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
461 |
removedObject := keyArray basicAt:index. |
609 | 462 |
keyArray basicAt:index put:nil. |
463 |
tally := tally - 1. |
|
464 |
tally == 0 ifTrue:[ |
|
22951 | 465 |
self possiblyShrinkToZero |
609 | 466 |
] ifFalse:[ |
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
467 |
index == keyArray basicSize ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
468 |
next := 1 |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
469 |
] ifFalse:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
470 |
next := index + 1. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
471 |
]. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
472 |
(keyArray basicAt:next) notNil ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
473 |
keyArray basicAt:index put:DeletedEntry. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
474 |
]. |
17263
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
475 |
self possiblyShrink |
609 | 476 |
]. |
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
477 |
removedObject == NilEntry ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
478 |
removedObject := nil. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
479 |
]. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
480 |
^ removedObject |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
481 |
|
6191 | 482 |
"Modified: / 16.11.2001 / 10:14:24 / cg" |
609 | 483 |
! |
484 |
||
485 |
removeAll |
|
21350 | 486 |
"remove all elements from the receiver and resize (shrink) the underlying container. |
487 |
Returns the receiver. |
|
488 |
Similar to clearContents, which but might behave better, |
|
489 |
if the receiver is to be filled again afterwards." |
|
609 | 490 |
|
18331 | 491 |
self initializeForCapacity:7. |
1164 | 492 |
|
21350 | 493 |
"Modified: / 12-04-1996 / 13:35:06 / cg" |
494 |
"Modified (comment): / 06-02-2017 / 12:56:14 / cg" |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
495 |
! |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
496 |
|
15806 | 497 |
removeIdentical:oldObjectArg ifAbsent:exceptionBlock |
498 |
"remove oldObject from the collection and return it. |
|
499 |
If it was not in the collection return the value of exceptionBlock. |
|
500 |
Uses identity compare (==) to search for an occurrence. |
|
501 |
||
502 |
WARNING: do not remove elements while iterating over the receiver. |
|
503 |
See #saveRemove: to do this." |
|
504 |
||
505 |
|oldObject index next| |
|
506 |
||
507 |
oldObjectArg isNil ifTrue:[ |
|
508 |
oldObject := NilEntry. |
|
509 |
] ifFalse:[ |
|
510 |
oldObject := oldObjectArg. |
|
511 |
]. |
|
512 |
||
513 |
"first a quick check. |
|
514 |
There is a high possibility that objects, which are |
|
515 |
equal are also identical" |
|
516 |
index := self find:oldObject ifAbsent:0. |
|
517 |
index ~~ 0 ifTrue:[ |
|
518 |
oldObject ~~ (keyArray basicAt:index) ifTrue:[ |
|
519 |
index := 0. |
|
520 |
] |
|
521 |
]. |
|
522 |
index == 0 ifTrue:[ |
|
523 |
"have to go the long and hard path..." |
|
524 |
index := self findIdentical:oldObject ifAbsent:0. |
|
525 |
index == 0 ifTrue:[^ exceptionBlock value]. |
|
526 |
]. |
|
527 |
||
528 |
keyArray basicAt:index put:nil. |
|
529 |
tally := tally - 1. |
|
530 |
tally == 0 ifTrue:[ |
|
22951 | 531 |
self possiblyShrinkToZero |
15806 | 532 |
] ifFalse:[ |
533 |
index == keyArray basicSize ifTrue:[ |
|
534 |
next := 1 |
|
535 |
] ifFalse:[ |
|
536 |
next := index + 1. |
|
537 |
]. |
|
538 |
(keyArray basicAt:next) notNil ifTrue:[ |
|
539 |
keyArray basicAt:index put:DeletedEntry. |
|
540 |
]. |
|
17263
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
541 |
self possiblyShrink |
15806 | 542 |
]. |
543 |
^ oldObjectArg |
|
544 |
! |
|
545 |
||
23207 | 546 |
replaceAll:oldObject with:newObject |
547 |
"replace all oldObjects by newObject in the receiver." |
|
548 |
||
549 |
self |
|
550 |
remove:oldObject ifAbsent:[]; |
|
551 |
addOrReplace:newObject. |
|
552 |
||
553 |
"Created: / 13-07-2018 / 12:04:31 / Stefan Vogel" |
|
554 |
! |
|
555 |
||
16515 | 556 |
safeRemove:oldObject |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
557 |
"remove the element, oldObject from the collection. |
6191 | 558 |
Return the element |
559 |
(could be non-identical to oldObject, since I hash on equality, not on identity). |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
560 |
If it was not in the collection return nil. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
561 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
562 |
In contrast to #remove:, this does not resize the underlying collection |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
563 |
and therefore does NOT rehash & change the elements order. |
14319 | 564 |
Therefor this can be used while enumerating the receiver, |
565 |
which is not possible if #remove: is used. |
|
566 |
||
567 |
WARNING: since no resizing is done, the physical amount of memory used |
|
568 |
by the container remains the same, although the logical size shrinks. |
|
569 |
You may want to manually resize the receiver using #emptyCheck. |
|
570 |
(after the loop)" |
|
571 |
||
16515 | 572 |
^ self safeRemove:oldObject ifAbsent:[]. |
14319 | 573 |
|
574 |
"Created: / 16.11.2001 / 10:23:48 / cg" |
|
575 |
"Modified: / 16.11.2001 / 10:24:03 / cg" |
|
576 |
! |
|
577 |
||
16515 | 578 |
safeRemove:oldObjectArg ifAbsent:exceptionValueProvider |
14319 | 579 |
"remove the element, oldObject from the collection. |
580 |
Return the element |
|
581 |
(could be non-identical to oldObject, since I hash on equality, not on identity). |
|
582 |
If it was not in the collection return the value of exceptionValueProvider. |
|
583 |
||
584 |
In contrast to #remove:, this does not resize the underlying collection |
|
585 |
and therefore does NOT rehash & change the elements order. |
|
12963 | 586 |
Therefore this can be used while enumerating the receiver, |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
587 |
which is not possible if #remove: is used. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
588 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
589 |
WARNING: since no resizing is done, the physical amount of memory used |
12963 | 590 |
by the container remains the same, although the logical size shrinks. |
591 |
You may want to manually resize the receiver using #emptyCheck. |
|
592 |
(after the loop)" |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
593 |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
594 |
|oldObject |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
595 |
index "{ Class:SmallInteger }" |
6191 | 596 |
next "{ Class:SmallInteger }" |
597 |
removedObject| |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
598 |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
599 |
oldObjectArg isNil ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
600 |
oldObject := NilEntry. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
601 |
] ifFalse:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
602 |
oldObject := oldObjectArg. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
603 |
]. |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
604 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
605 |
index := self find:oldObject ifAbsent:0. |
14319 | 606 |
index == 0 ifTrue:[^ exceptionValueProvider value]. |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
607 |
|
6191 | 608 |
removedObject := keyArray basicAt:index. |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
609 |
keyArray basicAt:index put:nil. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
610 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
611 |
tally := tally - 1. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
612 |
tally ~~ 0 ifTrue:[ |
12963 | 613 |
index == keyArray basicSize ifTrue:[ |
614 |
next := 1 |
|
615 |
] ifFalse:[ |
|
616 |
next := index + 1. |
|
617 |
]. |
|
618 |
(keyArray basicAt:next) notNil ifTrue:[ |
|
619 |
keyArray basicAt:index put:DeletedEntry |
|
620 |
]. |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
621 |
]. |
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
622 |
removedObject == NilEntry ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
623 |
removedObject := nil. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
624 |
]. |
6191 | 625 |
^ removedObject |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
626 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
627 |
"does NOT work: |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
628 |
|
12963 | 629 |
|s| |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
630 |
|
12963 | 631 |
s := Set new. |
632 |
s add:1. |
|
633 |
s add:2. |
|
634 |
s add:3. |
|
635 |
s add:4. |
|
636 |
s add:5. |
|
637 |
s add:6. |
|
638 |
s add:7. |
|
639 |
s add:8. |
|
640 |
s add:9. |
|
641 |
s do:[:v | |
|
642 |
v odd ifTrue:[ |
|
643 |
s remove:v |
|
644 |
] |
|
645 |
]. |
|
646 |
s inspect |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
647 |
" |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
648 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
649 |
"DOES work: |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
650 |
|
12963 | 651 |
|s| |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
652 |
|
12963 | 653 |
s := Set new. |
654 |
s add:1. |
|
655 |
s add:2. |
|
656 |
s add:3. |
|
657 |
s add:4. |
|
658 |
s add:5. |
|
659 |
s add:6. |
|
660 |
s add:7. |
|
661 |
s add:8. |
|
662 |
s add:9. |
|
663 |
s do:[:v | |
|
664 |
v odd ifTrue:[ |
|
16515 | 665 |
s safeRemove:v |
12963 | 666 |
] |
667 |
]. |
|
668 |
s inspect |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
669 |
" |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
670 |
|
6191 | 671 |
"Created: / 1.3.1996 / 21:14:26 / cg" |
672 |
"Modified: / 16.11.2001 / 10:22:59 / cg" |
|
10588 | 673 |
! |
674 |
||
16515 | 675 |
saveRemove:oldObject |
676 |
<resource: #obsolete> |
|
677 |
"bad spelling - kept for backward compatibility (2014-06-04)" |
|
678 |
||
679 |
^ self safeRemove:oldObject. |
|
680 |
! |
|
681 |
||
682 |
saveRemove:oldObjectArg ifAbsent:exceptionValueProvider |
|
683 |
<resource: #obsolete> |
|
684 |
"bad spelling - kept for backward compatibility (2014-06-04)" |
|
685 |
||
686 |
^ self safeRemove:oldObjectArg ifAbsent:exceptionValueProvider. |
|
687 |
! |
|
688 |
||
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
689 |
testAndAdd:keyArg |
21652 | 690 |
"Test, if the element is present in the receiver. |
10588 | 691 |
Answer true, if the element did already exist in the collection, |
692 |
false otherwise. |
|
21652 | 693 |
If the element does not exist, add it to the collection. |
10588 | 694 |
|
695 |
WARNING: do not add elements while iterating over the receiver. |
|
696 |
Iterate over a copy to do this." |
|
697 |
||
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
698 |
|key index "{ Class: SmallInteger }"| |
10588 | 699 |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
700 |
keyArg isNil ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
701 |
key := NilEntry. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
702 |
] ifFalse:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
703 |
key := keyArg. |
10588 | 704 |
]. |
705 |
||
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
706 |
index := self findKeyOrNil:key. |
21457 | 707 |
(keyArray basicAt:index) notNil ifTrue:[ |
708 |
^ true. |
|
709 |
]. |
|
10588 | 710 |
|
21457 | 711 |
"/ not already there |
712 |
keyArray basicAt:index put:key. |
|
713 |
tally := tally + 1. |
|
10588 | 714 |
|
21457 | 715 |
self possiblyGrow. |
716 |
^ false. |
|
717 |
||
718 |
"Modified: / 30-01-1997 / 14:58:08 / cg" |
|
719 |
"Modified: / 16-02-2017 / 13:47:10 / stefan" |
|
21652 | 720 |
"Modified (comment): / 16-03-2017 / 16:46:04 / stefan" |
609 | 721 |
! ! |
722 |
||
11052 | 723 |
|
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
724 |
!Set methodsFor:'comparing'! |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
725 |
|
21457 | 726 |
= anObject |
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
727 |
"return true, if the argument is a Set containing the same elements |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
728 |
as I do" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
729 |
|
21457 | 730 |
anObject species ~~ self species ifTrue:[^ false]. |
731 |
anObject size ~~ self size ifTrue:[^ false]. |
|
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
732 |
"/ same number of elements; since I am a Set, all of |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
733 |
"/ of my elements must be in the other collection ... |
21457 | 734 |
self do:[:eachElement | (anObject includes:eachElement) ifFalse:[^ false]]. |
14134 | 735 |
^ true. |
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
736 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
737 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
738 |
#(1 2 3 4 5) asSet = #(2 3 4 5 1) asSet |
18221 | 739 |
#(nil 1 2 3 4 5) asSet = #(2 3 4 5 1) asSet |
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
740 |
#(1 2 3 4 5) asSet = #(2 3 4 5 1.0) asSet |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
741 |
#(1 2 3 4 5) asSet = #(2 3 4 5 'one') asSet |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
742 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
743 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
744 |
|d1 d2| |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
745 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
746 |
d1 := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
747 |
d2 := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
748 |
d1 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
749 |
d1 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
750 |
d1 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
751 |
d1 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
752 |
d1 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
753 |
d1 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
754 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
755 |
d2 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
756 |
d2 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
757 |
d2 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
758 |
d2 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
759 |
d2 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
760 |
d2 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
761 |
d1 = d2 |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
762 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
763 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
764 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
765 |
|d1 d2| |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
766 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
767 |
d1 := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
768 |
d2 := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
769 |
d1 at:1 put:'uno'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
770 |
d1 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
771 |
d1 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
772 |
d1 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
773 |
d1 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
774 |
d1 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
775 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
776 |
d2 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
777 |
d2 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
778 |
d2 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
779 |
d2 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
780 |
d2 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
781 |
d2 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
782 |
d1 = d2 |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
783 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
784 |
|
10090
af5b9428e8ae
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
9933
diff
changeset
|
785 |
"Modified: / 13-10-2006 / 12:58:43 / cg" |
21457 | 786 |
"Modified (comment): / 16-02-2017 / 14:09:32 / stefan" |
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
787 |
! |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
788 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
789 |
hash |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
790 |
"return a hash key for the receiver" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
791 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
792 |
"this hash is stupid - but for larger collections, the hashing |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
793 |
time can become much bigger than the time lost in added probing. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
794 |
Time will show ... |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
795 |
Notice & warning: |
14134 | 796 |
if the #= method is ever changed to compare non-dictionaries equal, |
22444 | 797 |
the code below must be changed to assert that the same hash-value is |
14134 | 798 |
still returned. |
22444 | 799 |
(which may be hard to accomplish) |
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
800 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
801 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
802 |
|mySize| |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
803 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
804 |
mySize := self size. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
805 |
mySize == 0 ifTrue:[^ 0]. |
14134 | 806 |
^ (self anElement hash times:mySize) bitAnd:16r3FFFFFFF |
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
807 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
808 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
809 |
|d| |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
810 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
811 |
d := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
812 |
d at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
813 |
d at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
814 |
d at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
815 |
d at:'two' put:2. |
22444 | 816 |
d hash |
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
817 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
818 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
819 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
820 |
|d| |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
821 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
822 |
d := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
823 |
d at:1 put:'uno'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
824 |
d at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
825 |
d at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
826 |
d at:'two' put:2. |
22444 | 827 |
d hash |
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
828 |
" |
22444 | 829 |
|
830 |
"Modified (comment): / 17-01-2018 / 15:18:56 / mawalch" |
|
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
831 |
! ! |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
832 |
|
15000 | 833 |
!Set methodsFor:'converting'! |
834 |
||
835 |
asNewSet |
|
836 |
"make sure to return a unique new set" |
|
837 |
||
838 |
"could be an instance of a subclass..." |
|
839 |
self class == Set ifTrue:[ |
|
840 |
^ self copy |
|
841 |
]. |
|
21457 | 842 |
^ self asSet |
15000 | 843 |
|
844 |
" |
|
845 |
|s| |
|
846 |
s := #(1 2 3 4) asSet. |
|
847 |
self assert:(s ~~ s asNewSet). |
|
848 |
self assert:(s = s asNewSet). |
|
849 |
" |
|
21457 | 850 |
|
851 |
"Modified: / 16-02-2017 / 14:10:43 / stefan" |
|
15036 | 852 |
! |
853 |
||
854 |
asSet |
|
855 |
"return the receiver as a Set" |
|
856 |
||
857 |
"could be an instance of a subclass..." |
|
858 |
self class == Set ifTrue:[ |
|
859 |
^ self |
|
860 |
]. |
|
861 |
^ super asSet |
|
15000 | 862 |
! ! |
863 |
||
159 | 864 |
!Set methodsFor:'copying'! |
865 |
||
866 |
postCopy |
|
867 |
"have to copy the keyArray too" |
|
868 |
||
21384 | 869 |
<modifier: #super> "must be called if redefined" |
870 |
||
159 | 871 |
keyArray := keyArray shallowCopy |
21384 | 872 |
|
873 |
"Modified: / 08-02-2017 / 00:16:45 / cg" |
|
1 | 874 |
! ! |
875 |
||
609 | 876 |
!Set methodsFor:'enumerating'! |
1 | 877 |
|
609 | 878 |
do:aBlock |
1056 | 879 |
"perform the block for all members in the collection. |
880 |
||
881 |
WARNING: do not add/remove elements while iterating over the receiver. |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
882 |
Iterate over a copy to do this." |
13 | 883 |
|
609 | 884 |
|sz "{ Class: SmallInteger }" |
885 |
element| |
|
13 | 886 |
|
609 | 887 |
sz := keyArray size. |
888 |
1 to:sz do:[:index | |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
889 |
element := keyArray at:index. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
890 |
(element notNil and:[element ~~ DeletedEntry]) ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
891 |
element == NilEntry ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
892 |
element := nil. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
893 |
]. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
894 |
aBlock value:element |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
895 |
] |
609 | 896 |
] |
1056 | 897 |
|
898 |
"Modified: 1.3.1996 / 21:41:13 / cg" |
|
609 | 899 |
! ! |
61 | 900 |
|
969 | 901 |
|
23330 | 902 |
|
7169 | 903 |
!Set methodsFor:'obsolete set operations'! |
904 |
||
905 |
+ aCollection |
|
8606 | 906 |
"Kept for backward compatibility. |
907 |
Use #union: instead, to isolate arithmethic and set operations" |
|
7169 | 908 |
|
909 |
<resource: #obsolete> |
|
17202 | 910 |
|
7169 | 911 |
^ self union:aCollection. |
912 |
! |
|
913 |
||
914 |
- aCollection |
|
8606 | 915 |
"Kept for backward compatibility. |
916 |
Use #\ instead, to isolate arithmethic and set operations" |
|
7169 | 917 |
|
918 |
<resource: #obsolete> |
|
919 |
||
920 |
^ self \ aCollection |
|
921 |
! ! |
|
922 |
||
609 | 923 |
!Set methodsFor:'private'! |
2 | 924 |
|
1 | 925 |
find:key ifAbsent:aBlock |
926 |
"Look for the key in the receiver. If it is found, return |
|
927 |
the index of the slot containing the key, otherwise |
|
928 |
return the value of evaluating aBlock." |
|
929 |
||
61 | 930 |
|index "{ Class:SmallInteger }" |
931 |
length "{ Class:SmallInteger }" |
|
932 |
startIndex probe| |
|
1 | 933 |
|
13 | 934 |
length := keyArray basicSize. |
1126
497de696dff0
OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
935 |
|
497de696dff0
OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
936 |
"/ |
497de696dff0
OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
937 |
"/ length < 10 ifTrue:[ |
362 | 938 |
"/ "assuming, that for small collections the overhead of hashing |
939 |
"/ is larger ... maybe that proves wrong |
|
940 |
"/ (if overhead of comparing is higher)" |
|
941 |
"/ ^ keyArray indexOf:key ifAbsent:aBlock |
|
1126
497de696dff0
OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
942 |
"/ ]. |
13 | 943 |
|
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
944 |
startIndex := index := self initialIndexForKey:key. |
1 | 945 |
|
16241 | 946 |
[ |
19542 | 947 |
probe := keyArray basicAt:index. |
948 |
probe isNil ifTrue:[^ aBlock value]. |
|
949 |
(probe ~~ DeletedEntry and:[key = probe]) ifTrue:[^ index]. |
|
1 | 950 |
|
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
951 |
index == length ifTrue:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
952 |
index := 1 |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
953 |
] ifFalse:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
954 |
index := index + 1 |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
955 |
]. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
956 |
index == startIndex ifTrue:[^ aBlock value]. |
16241 | 957 |
] loop. |
13279 | 958 |
|
959 |
"Modified: / 03-02-2011 / 13:53:18 / sr" |
|
1 | 960 |
! |
961 |
||
15806 | 962 |
findIdentical:key ifAbsent:aBlock |
963 |
"Look for the key in the receiver. If it is found, return |
|
964 |
the index of the slot containing the key, otherwise |
|
965 |
return the value of evaluating aBlock." |
|
966 |
||
967 |
^ keyArray identityIndexOf:key ifAbsent:aBlock |
|
968 |
! |
|
969 |
||
13 | 970 |
findKeyOrNil:key |
1126
497de696dff0
OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
971 |
"Look for the key in the receiver. |
3082 | 972 |
If it is found, return the index of the first unused slot. |
19542 | 973 |
Grow the receiver, if key was not found, and no unused slots were present |
974 |
||
975 |
Warning: an empty slot MUST be filled by the sender - it is only to be sent |
|
976 |
by at:put: / add: - like methods." |
|
1 | 977 |
|
61 | 978 |
|index "{ Class:SmallInteger }" |
979 |
length "{ Class:SmallInteger }" |
|
1126
497de696dff0
OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
980 |
startIndex probe |
19542 | 981 |
delIndex "{ Class:SmallInteger }"| |
982 |
||
983 |
delIndex := 0. |
|
1 | 984 |
|
13 | 985 |
length := keyArray basicSize. |
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
986 |
startIndex := index := self initialIndexForKey:key. |
1 | 987 |
|
16241 | 988 |
[ |
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
989 |
probe := keyArray basicAt:index. |
19542 | 990 |
probe isNil ifTrue:[ |
991 |
delIndex == 0 ifTrue:[^ index]. |
|
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
992 |
keyArray basicAt:delIndex put:nil. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
993 |
^ delIndex |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
994 |
]. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
995 |
probe == DeletedEntry ifTrue:[ |
19542 | 996 |
delIndex == 0 ifTrue:[ |
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
997 |
delIndex := index |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
998 |
] |
19542 | 999 |
] ifFalse:[ |
1000 |
key = probe ifTrue:[^ index] |
|
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1001 |
]. |
1 | 1002 |
|
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1003 |
index == length ifTrue:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1004 |
index := 1 |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1005 |
] ifFalse:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1006 |
index := index + 1 |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1007 |
]. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1008 |
index == startIndex ifTrue:[ |
19542 | 1009 |
delIndex ~~ 0 ifTrue:[ |
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1010 |
keyArray basicAt:delIndex put:nil. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1011 |
^ delIndex |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1012 |
]. |
20038 | 1013 |
self grow. |
1014 |
length := keyArray basicSize. |
|
1015 |
startIndex := index := self initialIndexForKey:key. |
|
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
1016 |
]. |
16241 | 1017 |
] loop. |
1450
18c2a1da8be2
first look for nil-entry in findKeyOrNil: - saves a compare in the good case, when adding new elements
Claus Gittinger <cg@exept.de>
parents:
1319
diff
changeset
|
1018 |
|
13311 | 1019 |
"Modified: / 27-02-2011 / 15:30:42 / cg" |
1 | 1020 |
! |
1021 |
||
20236 | 1022 |
findKeyOrNilOrDeletedEntry:key |
1023 |
"Look for the key in the receiver. |
|
1024 |
If it is found, return the index of the first unused slot. |
|
1025 |
Grow the receiver, if key was not found, and no unused slots were present. |
|
1026 |
The answer is the index into the keyArray where the (keyArray at:index) |
|
1027 |
may contain: |
|
1028 |
nil - an empty slot |
|
1029 |
DeletedEntry - an empty slot, but preceeded and followed by non-empty |
|
1030 |
slots with keys hashing to the same value (hash collisions) |
|
1031 |
key - key is laready present in the slot." |
|
1032 |
||
1033 |
|index "{ Class:SmallInteger }" |
|
1034 |
length "{ Class:SmallInteger }" |
|
1035 |
startIndex probe |
|
1036 |
delIndex "{ Class:SmallInteger }"| |
|
1037 |
||
1038 |
delIndex := 0. |
|
1039 |
||
1040 |
length := keyArray basicSize. |
|
1041 |
startIndex := index := self initialIndexForKey:key. |
|
1042 |
||
1043 |
[ |
|
1044 |
probe := keyArray basicAt:index. |
|
1045 |
probe isNil ifTrue:[ |
|
1046 |
delIndex == 0 ifTrue:[^ index]. |
|
1047 |
^ delIndex |
|
1048 |
]. |
|
1049 |
probe == DeletedEntry ifTrue:[ |
|
1050 |
delIndex == 0 ifTrue:[ |
|
1051 |
delIndex := index |
|
1052 |
] |
|
1053 |
] ifFalse:[ |
|
1054 |
key = probe ifTrue:[^ index] |
|
1055 |
]. |
|
1056 |
||
1057 |
index == length ifTrue:[ |
|
1058 |
index := 1 |
|
1059 |
] ifFalse:[ |
|
1060 |
index := index + 1 |
|
1061 |
]. |
|
1062 |
index == startIndex ifTrue:[ |
|
1063 |
delIndex ~~ 0 ifTrue:[ |
|
1064 |
^ delIndex |
|
1065 |
]. |
|
1066 |
self grow. |
|
1067 |
length := keyArray basicSize. |
|
1068 |
startIndex := index := self initialIndexForKey:key. |
|
1069 |
]. |
|
1070 |
] loop. |
|
1071 |
||
1072 |
"Modified: / 27-02-2011 / 15:30:42 / cg" |
|
1073 |
! |
|
1074 |
||
1 | 1075 |
findNil:key |
2475 | 1076 |
"Look for the next slot usable for key. |
1077 |
WARNING: |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
1078 |
This method assumes that key is not already in the receiver |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
1079 |
AND that keyArray does not have previously removed entries |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
1080 |
AND that there is an empty slot. |
2475 | 1081 |
To be used ONLY while growing/rehashing to enter elements into a fresh |
1082 |
collection - if any of the above conditions is not met, the method |
|
1083 |
loops forever." |
|
1 | 1084 |
|
2475 | 1085 |
|index "{ Class:SmallInteger }" |
61 | 1086 |
length "{ Class:SmallInteger }"| |
1 | 1087 |
|
13 | 1088 |
length := keyArray basicSize. |
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
1089 |
index := self initialIndexForKey:key. |
1 | 1090 |
|
5772 | 1091 |
"/ index := keyArray identityIndexOf:nil startingAt:index. |
1092 |
"/ index == 0 ifTrue:[ |
|
1093 |
"/ index := keyArray identityIndexOf:nil startingAt:1 endingAt:index. |
|
1094 |
"/ ]. |
|
1095 |
"/ that code is completely inlined by stc ... |
|
1096 |
[(keyArray basicAt:index) notNil] whileTrue:[ |
|
14315
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
1097 |
index == length ifTrue:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
1098 |
index := 1 |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
1099 |
] ifFalse:[ |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
1100 |
index := index + 1 |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
1101 |
]. |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
1102 |
"notice: no check for no nil found - we must find one since |
f75e7698ccfe
Support for nil as element in a set
Stefan Vogel <sv@exept.de>
parents:
14314
diff
changeset
|
1103 |
this is only called after growing" |
1 | 1104 |
]. |
1105 |
^ index |
|
1055 | 1106 |
|
2475 | 1107 |
"Modified: 21.3.1997 / 10:32:58 / cg" |
1 | 1108 |
! |
1109 |
||
2459
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1110 |
hashFor:aKey |
6991
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
1111 |
"return the arguments hash value. |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
1112 |
Redefined in subclasses, which use a different comparison (i.e. identity compare)" |
2459
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1113 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1114 |
^ aKey hash |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1115 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1116 |
"Created: 19.3.1997 / 15:03:03 / cg" |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1117 |
! |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1118 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1119 |
initialIndexForKey:aKey |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1120 |
"return an initial index given a key." |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1121 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1122 |
|index "{ Class:SmallInteger }" |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1123 |
length "{ Class:SmallInteger }"| |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1124 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1125 |
length := keyArray basicSize. |
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
1126 |
index := (self hashFor:aKey) bitAnd:16r3FFFFFFF. |
14656 | 1127 |
|
1128 |
"multiply by a large prime to spread the keys over the whole range. |
|
1129 |
This causes maxChainLength to reduce from about 2000 to 6 for an |
|
1130 |
IdentitySet of 9000 Smalltalk classes" |
|
1131 |
index := index times:31415821. |
|
2459
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1132 |
index := index \\ length + 1. |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1133 |
^ index. |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1134 |
|
14656 | 1135 |
" |
1136 |
Smalltalk allClasses maxChainLength |
|
1137 |
" |
|
1138 |
||
2459
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1139 |
"Modified: 1.3.1997 / 01:01:13 / cg" |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1140 |
"Created: 19.3.1997 / 15:02:41 / cg" |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1141 |
! |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1142 |
|
18331 | 1143 |
initializeForCapacity:minSize |
1144 |
"initialize the contents array (for at least minSize slots) |
|
1145 |
and set tally to zero. |
|
1146 |
The size is increased to the next prime for better hashing behavior." |
|
1147 |
||
1148 |
|n| |
|
1149 |
||
1150 |
n := self class goodSizeFrom:minSize. |
|
1151 |
n == keyArray size ifTrue:[ |
|
1152 |
keyArray atAllPut:nil. |
|
1153 |
] ifFalse:[ |
|
1154 |
keyArray := self keyContainerOfSize:n. |
|
1155 |
]. |
|
1156 |
tally := 0 |
|
1157 |
||
1158 |
"Modified: / 4.8.1998 / 22:07:25 / cg" |
|
1159 |
! |
|
1160 |
||
3261
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
1161 |
keyArray |
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
1162 |
^ keyArray |
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
1163 |
|
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
1164 |
"Created: / 2.2.1998 / 14:50:55 / cg" |
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
1165 |
! |
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
1166 |
|
609 | 1167 |
keyContainerOfSize:n |
1168 |
"return a container for keys of size n. |
|
1169 |
Extracted to make life of weak subclasses easier ..." |
|
1170 |
||
1171 |
^ Array basicNew:n |
|
1172 |
! |
|
1173 |
||
1 | 1174 |
rehash |
61 | 1175 |
"rehash is done by re-adding all elements to a new empty set. |
1176 |
Rehash is needed after a binaryRead, for example." |
|
1 | 1177 |
|
3082 | 1178 |
|element oldKeyArray newKeyArray newIdx |
95 | 1179 |
n "{ Class:SmallInteger }"| |
1 | 1180 |
|
95 | 1181 |
oldKeyArray := keyArray. |
1182 |
n := oldKeyArray size. |
|
1183 |
keyArray := newKeyArray := self keyContainerOfSize:n. |
|
1184 |
||
2 | 1185 |
1 to:n do:[:index | |
6994 | 1186 |
element := oldKeyArray at:index. |
1187 |
(element notNil and:[element ~~ DeletedEntry]) ifTrue:[ |
|
1188 |
"cannot be already there" |
|
1189 |
newIdx := self findNil:element. |
|
1190 |
newKeyArray basicAt:newIdx put:element |
|
1191 |
]. |
|
1 | 1192 |
] |
3082 | 1193 |
|
1194 |
"Modified: / 30.10.1997 / 16:04:46 / cg" |
|
1 | 1195 |
! ! |
1196 |
||
7260 | 1197 |
!Set methodsFor:'private-grow & shrink'! |
3082 | 1198 |
|
1199 |
grow |
|
1200 |
"change the number of element slots of the collection to a useful |
|
1201 |
new size" |
|
1202 |
||
1203 |
self grow:(keyArray basicSize * 2) |
|
1204 |
! |
|
1205 |
||
1206 |
grow:newSize |
|
1207 |
"change the number of element slots of the collection - to do this, |
|
1208 |
we have to rehash (which is done by re-adding all elements to a new |
|
1209 |
empty set)." |
|
1210 |
||
1211 |
|elem oldKeyArray newKeyArray deletedEntry |
|
1212 |
containerSize oldSize "{ Class:SmallInteger }"| |
|
1213 |
||
1214 |
oldKeyArray := keyArray. |
|
1215 |
oldSize := oldKeyArray size. |
|
1216 |
containerSize := (self class goodSizeFrom:newSize). |
|
1217 |
containerSize == oldSize ifTrue:[^ self]. |
|
1218 |
||
1219 |
keyArray := newKeyArray := self keyContainerOfSize:containerSize. |
|
1220 |
||
1221 |
deletedEntry := DeletedEntry. |
|
1222 |
1 to:oldSize do:[:srcIndex | |
|
1223 |
elem := oldKeyArray basicAt:srcIndex. |
|
1224 |
(elem notNil and:[elem ~~ deletedEntry]) ifTrue:[ |
|
1225 |
"cannot be already there" |
|
1226 |
newKeyArray basicAt:(self findNil:elem) put:elem |
|
1227 |
]. |
|
1228 |
]. |
|
17263
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1229 |
! |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1230 |
|
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1231 |
possiblyGrow |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1232 |
"check if collection is full (after an add); grow if so. |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1233 |
Definition of 'full' is currently: 'filled more than 75% (i.e. 3/4th)'" |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1234 |
|
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1235 |
|sz "{Class: SmallInteger}" | |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1236 |
|
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1237 |
" |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1238 |
grow if filled more than 75% |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1239 |
" |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1240 |
sz := keyArray basicSize. |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1241 |
tally > (sz * 3 // 4) ifTrue:[ |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1242 |
self grow |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1243 |
] |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1244 |
! |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1245 |
|
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1246 |
possiblyShrink |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1247 |
"check if the receiver has become too empty (after a remove) |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1248 |
and shrink if it makes sense. |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1249 |
Definition of 'too empty' is: 'filled less than 12.5% (i.e. 1/8th)'" |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1250 |
|
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1251 |
|sz "{Class: SmallInteger}" |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1252 |
newSize "{Class: SmallInteger}" | |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1253 |
|
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1254 |
sz := keyArray basicSize. |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1255 |
sz > 56 ifTrue:[ |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1256 |
" |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1257 |
shrink if too empty |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1258 |
" |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1259 |
tally < (sz // 8) ifTrue:[ |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1260 |
newSize := sz // 4. |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1261 |
self grow:newSize |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1262 |
] |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1263 |
] |
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1264 |
|
65d015f98f43
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
17202
diff
changeset
|
1265 |
"Modified: 19.3.1997 / 16:02:55 / cg" |
22951 | 1266 |
! |
1267 |
||
1268 |
possiblyShrinkToZero |
|
1269 |
"the tally went down to zero. |
|
1270 |
throw away any big container and start anew" |
|
1271 |
||
1272 |
keyArray := self keyContainerOfSize:(self class goodSizeFrom:0). |
|
3082 | 1273 |
! ! |
1274 |
||
5557 | 1275 |
!Set methodsFor:'queries'! |
1276 |
||
23694 | 1277 |
capacity |
1278 |
"return the number of elements, that the receiver is prepared to take w.o. resizing. |
|
1279 |
Notice, that Sets do automatically resize as required, |
|
1280 |
so knowing the capacity is of no real use." |
|
1281 |
||
1282 |
^ keyArray size |
|
1283 |
||
1284 |
"Modified (comment): / 17-03-2017 / 11:50:16 / stefan" |
|
1285 |
! |
|
1286 |
||
8499 | 1287 |
collisionCount |
1288 |
"return the number of key collisions in the set. |
|
1289 |
There is a collision if two keys hash to the same value." |
|
1290 |
||
1291 |
|count| |
|
1292 |
||
1293 |
count := 0. |
|
1294 |
||
1295 |
keyArray do:[:eachKey| |
|
1296 |
(eachKey notNil and:[eachKey ~~ DeletedEntry]) ifTrue:[ |
|
1297 |
count := count + (self collisionsFor:eachKey). |
|
1298 |
] |
|
1299 |
]. |
|
1300 |
||
1301 |
^ count |
|
14654 | 1302 |
|
1303 |
" |
|
1304 |
self allSubInstances |
|
1305 |
collect:[:each| each collisionCount -> each] |
|
1306 |
thenSelect:[:each| each key > 0] |
|
1307 |
" |
|
8499 | 1308 |
! |
1309 |
||
1310 |
collisionsFor:key |
|
1311 |
"Return the number of searches - 1 required for key" |
|
1312 |
||
1313 |
|index "{ Class:SmallInteger }" |
|
14654 | 1314 |
length "{ Class:SmallInteger }" startIndex probe count| |
8499 | 1315 |
|
1316 |
length := keyArray basicSize. |
|
14654 | 1317 |
startIndex := index := self initialIndexForKey:key. |
8499 | 1318 |
|
1319 |
count := 0. |
|
16241 | 1320 |
[ |
14654 | 1321 |
probe := keyArray basicAt:index. |
8499 | 1322 |
(probe notNil and:[key = probe]) ifTrue:[^ count]. |
19542 | 1323 |
probe isNil ifTrue:[self error:'non existing key']. |
8499 | 1324 |
|
1325 |
index == length ifTrue:[ |
|
1326 |
index := 1. |
|
1327 |
] ifFalse:[ |
|
1328 |
index := index + 1. |
|
1329 |
]. |
|
1330 |
count := count + 1. |
|
1331 |
index == startIndex ifTrue:[self error:'non existing key']. |
|
16241 | 1332 |
] loop. |
8499 | 1333 |
! |
1334 |
||
23694 | 1335 |
includes:anObject |
1336 |
"return true if the argument anObject is in the receiver" |
|
1337 |
||
1338 |
tally == 0 ifTrue:[^ false]. "/ quick reject if empty |
|
1339 |
^ (self find:(anObject ? NilEntry) ifAbsent:0) ~~ 0 |
|
1340 |
! |
|
1341 |
||
1342 |
isEmpty |
|
1343 |
"return true if the receiver is empty" |
|
1344 |
||
1345 |
^ tally == 0 |
|
1346 |
! |
|
1347 |
||
1348 |
isEmptyOrNil |
|
1349 |
"return true if the receiver is empty" |
|
1350 |
||
1351 |
^ tally == 0 |
|
1352 |
||
1353 |
"Created: / 23-02-2017 / 15:51:50 / stefan" |
|
1354 |
! |
|
1355 |
||
8499 | 1356 |
maxChainLength |
1357 |
"return the number of the maximum chain length in the set. |
|
1358 |
This is the worst case overhead when accessing a key." |
|
1359 |
||
1360 |
|chainLength key| |
|
1361 |
||
1362 |
chainLength := 0. |
|
1363 |
||
1364 |
keyArray do:[:eachKey| |t| |
|
1365 |
(eachKey notNil and:[eachKey ~~ DeletedEntry]) ifTrue:[ |
|
1366 |
t := self collisionsFor:eachKey. |
|
1367 |
chainLength < t ifTrue:[chainLength := t. key := eachKey]. |
|
1368 |
] |
|
1369 |
]. |
|
1370 |
||
1371 |
^ (key -> chainLength) |
|
1372 |
! |
|
1373 |
||
23694 | 1374 |
notEmpty |
1375 |
"return true if the receiver is not empty" |
|
1376 |
||
1377 |
^ tally ~~ 0 |
|
1378 |
||
1379 |
"Created: 12.2.1997 / 12:39:02 / cg" |
|
1380 |
! |
|
1381 |
||
1382 |
notEmptyOrNil |
|
1383 |
"return true if the receiver is not empty" |
|
1384 |
||
1385 |
^ tally ~~ 0 |
|
1386 |
||
1387 |
"Created: / 23-02-2017 / 15:51:58 / stefan" |
|
1388 |
! |
|
1389 |
||
1390 |
occurrencesOf:anObject |
|
1391 |
"return the number of occurrences of anObject in the receiver. |
|
1392 |
As I am a Set, this can only return 0 or 1." |
|
1393 |
||
1394 |
tally == 0 ifTrue:[^ 0]. |
|
1395 |
(self find:(anObject ? NilEntry) ifAbsent:0) == 0 ifTrue:[^ 0]. |
|
1396 |
^ 1 |
|
1397 |
||
1398 |
"Modified: / 16.11.2001 / 10:30:14 / cg" |
|
1399 |
! |
|
1400 |
||
5557 | 1401 |
size |
1402 |
"return the number of set elements" |
|
1403 |
||
1404 |
^ tally |
|
1405 |
! ! |
|
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5335
diff
changeset
|
1406 |
|
23189 | 1407 |
|
16810 | 1408 |
!Set methodsFor:'searching'! |
1409 |
||
1410 |
findFirst:aBlock ifNone:exceptionValue |
|
1411 |
"find the index of the first element, for which evaluation of the argument, aBlock returns true; |
|
1412 |
return its index or the value from exceptionValue if none detected. |
|
1413 |
This is much like #detect:ifNone:, however, here an INDEX is returned, |
|
1414 |
while #detect:ifNone: returns the element. |
|
1415 |
||
1416 |
Sets do not have indices." |
|
1417 |
||
1418 |
^ self shouldNotImplement |
|
21457 | 1419 |
! |
1420 |
||
1421 |
findLast:aBlock ifNone:exceptionValue |
|
1422 |
"Sets do not have indices." |
|
1423 |
||
1424 |
^ self shouldNotImplement |
|
1425 |
||
1426 |
"Created: / 16-02-2017 / 13:54:53 / stefan" |
|
16810 | 1427 |
! ! |
1428 |
||
1 | 1429 |
!Set methodsFor:'testing'! |
1430 |
||
609 | 1431 |
isFixedSize |
1432 |
"return true if the receiver cannot grow - this will vanish once |
|
1433 |
Arrays and Strings learn how to grow ..." |
|
1434 |
||
1435 |
^ false |
|
1436 |
! |
|
1437 |
||
18466 | 1438 |
isOrdered |
1439 |
"return true, if the receiver's elements are ordered. |
|
1440 |
Redefined to return false here, because the order of keys (and values in dictionaries) |
|
1441 |
may change due to rehashing, when elements are added/removed" |
|
1442 |
||
1443 |
^ false |
|
1 | 1444 |
! ! |
1445 |
||
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1446 |
!Set methodsFor:'visiting'! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1447 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1448 |
acceptVisitor:aVisitor with:aParameter |
16717 | 1449 |
"dispatch for visitor pattern; send #visitSet:with: to aVisitor." |
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1450 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1451 |
^ aVisitor visitSet:self with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1452 |
! ! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1453 |
|
4017
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1454 |
!Set::EmptySlot class methodsFor:'instance creation'! |
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1455 |
|
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1456 |
basicNew |
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1457 |
TheOneAndOnlyInstance isNil ifTrue:[ |
6994 | 1458 |
TheOneAndOnlyInstance := super basicNew |
4017
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1459 |
]. |
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1460 |
^ TheOneAndOnlyInstance |
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1461 |
|
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1462 |
! ! |
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1463 |
|
14314 | 1464 |
!Set::NilKey class methodsFor:'instance creation'! |
1465 |
||
1466 |
basicNew |
|
1467 |
TheOneAndOnlyInstance isNil ifTrue:[ |
|
1468 |
TheOneAndOnlyInstance := super basicNew |
|
1469 |
]. |
|
1470 |
^ TheOneAndOnlyInstance |
|
1471 |
||
1472 |
||
1473 |
! ! |
|
1474 |
||
2259 | 1475 |
!Set class methodsFor:'documentation'! |
635 | 1476 |
|
1477 |
version |
|
19080 | 1478 |
^ '$Header$' |
12342 | 1479 |
! |
1480 |
||
1481 |
version_CVS |
|
19080 | 1482 |
^ '$Header$' |
635 | 1483 |
! ! |
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
1484 |
|
14654 | 1485 |
|
609 | 1486 |
Set initialize! |