author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 15 Jun 2009 20:55:05 +0100 | |
branch | jv |
changeset 17711 | 39faaaf888b4 |
parent 11472 | d30ca682c65f |
child 17734 | 406b1590afe8 |
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 |
|
1 | 14 |
Collection subclass:#Set |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
15 |
instanceVariableNames:'tally keyArray' |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
16 |
classVariableNames:'DeletedEntry' |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
17 |
poolDictionaries:'' |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
18 |
category:'Collections-Unordered' |
1 | 19 |
! |
20 |
||
2272 | 21 |
Object subclass:#EmptySlot |
2259 | 22 |
instanceVariableNames:'' |
4017
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
23 |
classVariableNames:'TheOneAndOnlyInstance' |
2259 | 24 |
poolDictionaries:'' |
25 |
privateIn:Set |
|
26 |
! |
|
27 |
||
28 |
!Set class methodsFor:'documentation'! |
|
88 | 29 |
|
30 |
copyright |
|
31 |
" |
|
32 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
159 | 33 |
All Rights Reserved |
1 | 34 |
|
88 | 35 |
This software is furnished under a license and may be used |
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
1 | 43 |
|
88 | 44 |
documentation |
45 |
" |
|
46 |
a Set is a collection where each element occurs at most once. |
|
95 | 47 |
The inclusion test is done using = for comparison; |
48 |
see IdentitySet for sets using identity compare. |
|
6191 | 49 |
Keep in mind, that a regular Set therefore treats 3.0 and 3 as equal |
50 |
and therefore: |
|
6994 | 51 |
(Set with:3.0) includes:3 |
6191 | 52 |
will return true (since 3.0 and 3 are equal). |
53 |
In contrast, an IdentitySet will return false, because 3.0 and 3 are not |
|
54 |
identical. |
|
55 |
||
95 | 56 |
Sets use hashing for fast access, this access is considerably faster, |
57 |
if a good hash-number is returned by the elements. |
|
362 | 58 |
|
59 |
Notice that the default hash (Object>>hash) is not perfect; due to |
|
60 |
the implementation of hash-keys in ST/X, increased hash collisions |
|
61 |
are to be expected for large sets (say: > 20000 element). |
|
62 |
If your objects are heavyly used in sets or dictionaries, and you need |
|
63 |
big collections, your instances may provide a better hash values. |
|
95 | 64 |
|
345 | 65 |
Performance hints: |
657 | 66 |
If only symbols or smallIntegers are used as keys, |
362 | 67 |
use an instance of IdentitySet for slightly better performance, |
68 |
since both hashing and comparison is faster. |
|
345 | 69 |
|
70 |
If you have a rough idea how big the set is going to grow, |
|
71 |
create it using #new: instead of #new. Even if the size given is a |
|
72 |
poor guess (say half of the real size), there is some 20-30% performance |
|
73 |
win to expect, since many resizing operations of the set are avoided. |
|
74 |
||
95 | 75 |
Examples: |
76 |
||
6994 | 77 |
|s| |
78 |
s := Set new. |
|
79 |
s add:'hello'. |
|
80 |
s add:'world'. |
|
81 |
s add:#foo. |
|
82 |
s add:1.2345678. |
|
83 |
s add:'hello'. |
|
95 | 84 |
|
6994 | 85 |
s printCR. |
86 |
's size -> ' print. s size printCR. |
|
87 |
'(s includes:''hello'') -> ' print. (s includes:'hello') printCR. |
|
88 |
'(s includes:#foo) -> ' print. (s includes:#foo) printCR. |
|
89 |
'(s includes:''foo'') -> ' print. (s includes:'foo') printCR. |
|
90 |
'(s includes:#bar) -> ' print. (s includes:#bar) printCR. |
|
1290 | 91 |
|
92 |
[author:] |
|
6994 | 93 |
Claus Gittinger |
88 | 94 |
" |
95 |
! ! |
|
1 | 96 |
|
2259 | 97 |
!Set class methodsFor:'initialization'! |
41 | 98 |
|
99 |
initialize |
|
100 |
"initialize the Set class" |
|
101 |
||
102 |
DeletedEntry isNil ifTrue:[ |
|
6994 | 103 |
DeletedEntry := EmptySlot new |
41 | 104 |
]. |
105 |
||
106 |
"Set initialize" |
|
2259 | 107 |
|
108 |
"Modified: 24.1.1997 / 21:09:00 / cg" |
|
41 | 109 |
! ! |
110 |
||
2259 | 111 |
!Set class methodsFor:'instance creation'! |
1 | 112 |
|
6083 | 113 |
decodeFromLiteralArray:anArray |
114 |
"create & return a new instance from information encoded in anArray." |
|
115 |
||
8831
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
116 |
|set |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
117 |
sz "{ Class: SmallInteger }"| |
6083 | 118 |
|
8831
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
119 |
sz := anArray size. |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
120 |
set := self new:sz-1. |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
121 |
2 to:sz do:[:idx| set add:(anArray at:idx) decodeAsLiteralArray]. |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
122 |
^ set |
6083 | 123 |
|
124 |
" |
|
125 |
(Set with:1234 |
|
8831
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
126 |
with:(1 @ 2) |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8606
diff
changeset
|
127 |
with:'hello' |
6083 | 128 |
) literalArrayEncoding decodeAsLiteralArray |
129 |
" |
|
130 |
! |
|
131 |
||
1 | 132 |
new |
133 |
"return a new empty Set" |
|
134 |
||
135 |
^ self new:7 |
|
136 |
! |
|
137 |
||
138 |
new:anInteger |
|
139 |
"return a new empty Set with space for anInteger elements" |
|
140 |
||
159 | 141 |
" |
142 |
make it somewhat bigger; hashing works better if fill grade is |
|
143 |
below 10% (make it 75% here ..) |
|
144 |
" |
|
145 |
^ self basicNew setTally:(anInteger * 4 // 3) |
|
146 |
! ! |
|
147 |
||
2259 | 148 |
!Set class methodsFor:'queries'! |
252 | 149 |
|
150 |
goodSizeFrom:arg |
|
151 |
"return a good array size for the given argument. |
|
152 |
Returns the next prime after arg, since prime sizes are good for hashing." |
|
153 |
||
302 | 154 |
|n| |
155 |
||
2461
2d65e1845502
minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
156 |
"/ arg <= 11 ifTrue:[^ 11]. |
2d65e1845502
minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
157 |
"/ n := arg * 3 // 2. |
252 | 158 |
|
2461
2d65e1845502
minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
159 |
arg <= 7 ifTrue:[^ 7]. |
2d65e1845502
minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
160 |
n := arg. |
302 | 161 |
|
252 | 162 |
" |
163 |
mhmh - this returns good numbers for collections with up-to about |
|
164 |
500k elements; if you have bigger ones, add some more primes here ... |
|
165 |
" |
|
302 | 166 |
n <= 524288 ifTrue:[ |
9318 | 167 |
"2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288" |
168 |
^ #(7 7 11 17 37 67 131 257 521 1031 2053 4099 8209 16411 32771 65537 131101 262147 524309) at:(n highBit) |
|
252 | 169 |
]. |
2461
2d65e1845502
minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
170 |
|
9318 | 171 |
^ n nextPrime |
252 | 172 |
! ! |
173 |
||
3048 | 174 |
!Set class methodsFor:'utilities'! |
175 |
||
176 |
rehashAllSubInstances |
|
177 |
"rehash all sets & dictionaries. |
|
178 |
Useful utility if hash/identityHash method was changed |
|
179 |
of some object which is known to be kept in a set" |
|
180 |
||
181 |
self allSubInstances do:[:s | s rehash] |
|
182 |
||
183 |
" |
|
184 |
Set rehashAllSubInstances |
|
185 |
" |
|
186 |
||
187 |
"Created: / 24.10.1997 / 23:13:44 / cg" |
|
188 |
! ! |
|
189 |
||
7268 | 190 |
!Set methodsFor:'Compatibility-ST80'! |
6991
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
191 |
|
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
192 |
initialIndexFor:hashKey boundedBy:length |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
193 |
"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
|
194 |
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
|
195 |
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
|
196 |
improves performance, by avoiding an extra message send ...)" |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
197 |
|
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
198 |
|index "{ Class:SmallInteger }"| |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
199 |
|
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
200 |
index := hashKey bitAnd:16r3FFFFFFF. |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
201 |
index < 16r1FFFFFFF ifTrue:[ |
6994 | 202 |
index := index * 2 |
6991
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
203 |
]. |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
204 |
index := index \\ length + 1. |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
205 |
^ index. |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
206 |
|
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
207 |
"Modified: 1.3.1997 / 01:01:13 / cg" |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
208 |
! ! |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
209 |
|
7311
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
210 |
!Set methodsFor:'Compatibility-Squeak'! |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
211 |
|
11052 | 212 |
copyWithout:elementToSkip |
213 |
"return a new collection consisting of a copy of the receiver, with |
|
214 |
ALL elements equal to elementToSkip are left out. |
|
215 |
No error is reported, if elementToSkip is not in the collection." |
|
216 |
||
217 |
^ self select:[:each | each ~= elementToSkip] |
|
7311
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
218 |
|
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
219 |
" |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
220 |
#(1 2 3 4 5 6 7) asSet copyWithout:5 |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
221 |
" |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
222 |
! |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
223 |
|
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
224 |
copyWithoutAll:aCollection |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
225 |
^ self select:[:each | (aCollection includes:each)] |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
226 |
|
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
227 |
" |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
228 |
#(1 2 3 4 5 6 7) asSet copyWithoutAll:#(3 5 7 9) |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
229 |
" |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
230 |
! ! |
6878116b0a27
+copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents:
7268
diff
changeset
|
231 |
|
609 | 232 |
!Set methodsFor:'accessing'! |
233 |
||
234 |
at:index |
|
235 |
"report an error: at: is not allowed for Sets" |
|
236 |
||
237 |
^ self errorNotKeyed |
|
238 |
! |
|
239 |
||
240 |
at:index put:anObject |
|
241 |
"report an error: at:put: is not allowed for Sets" |
|
242 |
||
243 |
^ self errorNotKeyed |
|
2469
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
244 |
! |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
245 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
246 |
elementAt:anObject |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
247 |
"return the element, if contained in the set. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
248 |
If there is none, report an error. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
249 |
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
|
250 |
non-identitysets, to find an existing element, for a |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
251 |
given equal (but not identical) object. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
252 |
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
|
253 |
goody." |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
254 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
255 |
^ self elementAt:anObject ifAbsent:[^ self errorNotFound]. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
256 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
257 |
"Modified: 20.3.1997 / 20:35:24 / cg" |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
258 |
! |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
259 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
260 |
elementAt:anObject ifAbsent:exceptionBlock |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
261 |
"return the element, if contained in the set. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
262 |
If there is none, return the result from evaluating exceptionBlock. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
263 |
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
|
264 |
non-identitysets, to find an existing element, for a |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
265 |
given equal (but not identical) object. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
266 |
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
|
267 |
goody." |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
268 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
269 |
|index "{ Class: SmallInteger }" | |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
270 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
271 |
index := self find:anObject ifAbsent:0. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
272 |
index == 0 ifTrue:[ |
6994 | 273 |
^ exceptionBlock value |
2469
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
274 |
]. |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
275 |
^ keyArray basicAt:index |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
276 |
|
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
277 |
"Created: 20.3.1997 / 20:34:07 / cg" |
ecca86d50852
added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2461
diff
changeset
|
278 |
"Modified: 20.3.1997 / 20:35:49 / cg" |
609 | 279 |
! ! |
280 |
||
281 |
!Set methodsFor:'adding & removing'! |
|
282 |
||
283 |
add:anObject |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
284 |
"add the argument, anObject to the receiver. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
285 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
286 |
WARNING: do not add elements while iterating over the receiver. |
10868 | 287 |
Iterate over a copy to do this." |
609 | 288 |
|
2328
0fd1d715e5a9
oops - the last one was not good
Claus Gittinger <cg@exept.de>
parents:
2323
diff
changeset
|
289 |
|index "{ Class: SmallInteger }"| |
609 | 290 |
|
10868 | 291 |
anObject isNil ifTrue:[ |
292 |
^ self invalidElementError. |
|
5335
fae7e0698241
added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents:
5298
diff
changeset
|
293 |
]. |
609 | 294 |
|
5335
fae7e0698241
added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents:
5298
diff
changeset
|
295 |
index := self findKeyOrNil:anObject. |
fae7e0698241
added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents:
5298
diff
changeset
|
296 |
(keyArray basicAt:index) isNil ifTrue:[ |
10868 | 297 |
"/ not already there |
298 |
keyArray basicAt:index put:anObject. |
|
299 |
tally := tally + 1. |
|
5335
fae7e0698241
added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents:
5298
diff
changeset
|
300 |
|
10868 | 301 |
self fullCheck. |
609 | 302 |
]. |
303 |
^ anObject |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
304 |
|
2328
0fd1d715e5a9
oops - the last one was not good
Claus Gittinger <cg@exept.de>
parents:
2323
diff
changeset
|
305 |
"Modified: 30.1.1997 / 14:58:08 / cg" |
609 | 306 |
! |
307 |
||
308 |
remove:oldObject ifAbsent:exceptionBlock |
|
309 |
"remove oldObject from the collection and return it. |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
310 |
If it was not in the collection return the value of exceptionBlock. |
6191 | 311 |
Notice, that the returned object could be non-identical to the argument |
312 |
(although it will always be equal). |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
313 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
314 |
WARNING: do not remove elements while iterating over the receiver. |
6994 | 315 |
See #saveRemove: to do this." |
609 | 316 |
|
6191 | 317 |
|index next objectRemoved| |
609 | 318 |
|
3265
18d96c910653
handle attempt to remove nil.
Claus Gittinger <cg@exept.de>
parents:
3261
diff
changeset
|
319 |
oldObject isNil ifTrue:[^ exceptionBlock value]. |
18d96c910653
handle attempt to remove nil.
Claus Gittinger <cg@exept.de>
parents:
3261
diff
changeset
|
320 |
|
609 | 321 |
index := self find:oldObject ifAbsent:0. |
322 |
index == 0 ifTrue:[^ exceptionBlock value]. |
|
323 |
||
6191 | 324 |
objectRemoved := keyArray basicAt:index. |
609 | 325 |
keyArray basicAt:index put:nil. |
326 |
tally := tally - 1. |
|
327 |
tally == 0 ifTrue:[ |
|
6994 | 328 |
keyArray := self keyContainerOfSize:(self class goodSizeFrom:0). |
609 | 329 |
] ifFalse:[ |
6994 | 330 |
index == keyArray basicSize ifTrue:[ |
331 |
next := 1 |
|
332 |
] ifFalse:[ |
|
333 |
next := index + 1. |
|
334 |
]. |
|
335 |
(keyArray basicAt:next) notNil ifTrue:[ |
|
336 |
keyArray basicAt:index put:DeletedEntry. |
|
337 |
]. |
|
338 |
self emptyCheck |
|
609 | 339 |
]. |
6191 | 340 |
^ objectRemoved |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
341 |
|
6191 | 342 |
"Modified: / 16.11.2001 / 10:14:24 / cg" |
609 | 343 |
! |
344 |
||
345 |
removeAll |
|
1164 | 346 |
"remove all elements from the receiver. Returns the receiver." |
609 | 347 |
|
348 |
self setTally:7. |
|
1164 | 349 |
|
350 |
"Modified: 12.4.1996 / 13:35:06 / cg" |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
351 |
! |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
352 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
353 |
saveRemove:oldObject |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
354 |
"remove the element, oldObject from the collection. |
6191 | 355 |
Return the element |
356 |
(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
|
357 |
If it was not in the collection return nil. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
358 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
359 |
In contrast to #remove:, this does not resize the underlying collection |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
360 |
and therefore does NOT rehash & change the elements order. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
361 |
Therefor this can be used while enumerating the receiver, |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
362 |
which is not possible if #remove: is used. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
363 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
364 |
WARNING: since no resizing is done, the physical amount of memory used |
6994 | 365 |
by the container remains the same, although the logical size shrinks. |
366 |
You may want to manually resize the receiver using #emptyCheck. |
|
367 |
(after the loop)" |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
368 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
369 |
|index "{ Class:SmallInteger }" |
6191 | 370 |
next "{ Class:SmallInteger }" |
371 |
removedObject| |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
372 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
373 |
oldObject isNil ifTrue:[^ nil]. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
374 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
375 |
index := self find:oldObject ifAbsent:0. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
376 |
index == 0 ifTrue:[^ nil]. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
377 |
|
6191 | 378 |
removedObject := keyArray basicAt:index. |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
379 |
keyArray basicAt:index put:nil. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
380 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
381 |
tally := tally - 1. |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
382 |
tally ~~ 0 ifTrue:[ |
6994 | 383 |
index == keyArray basicSize ifTrue:[ |
384 |
next := 1 |
|
385 |
] ifFalse:[ |
|
386 |
next := index + 1. |
|
387 |
]. |
|
388 |
(keyArray basicAt:next) notNil ifTrue:[ |
|
389 |
keyArray basicAt:index put:DeletedEntry |
|
390 |
]. |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
391 |
]. |
6191 | 392 |
^ removedObject |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
393 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
394 |
"does NOT work: |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
395 |
|
6994 | 396 |
|s| |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
397 |
|
6994 | 398 |
s := Set new. |
399 |
s add:1. |
|
400 |
s add:2. |
|
401 |
s add:3. |
|
402 |
s add:4. |
|
403 |
s add:5. |
|
404 |
s add:6. |
|
405 |
s add:7. |
|
406 |
s add:8. |
|
407 |
s add:9. |
|
408 |
s do:[:v | |
|
409 |
v odd ifTrue:[ |
|
410 |
s remove:v |
|
411 |
] |
|
412 |
]. |
|
413 |
s inspect |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
414 |
" |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
415 |
|
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
416 |
"DOES work: |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
417 |
|
6994 | 418 |
|s| |
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
419 |
|
6994 | 420 |
s := Set new. |
421 |
s add:1. |
|
422 |
s add:2. |
|
423 |
s add:3. |
|
424 |
s add:4. |
|
425 |
s add:5. |
|
426 |
s add:6. |
|
427 |
s add:7. |
|
428 |
s add:8. |
|
429 |
s add:9. |
|
430 |
s do:[:v | |
|
431 |
v odd ifTrue:[ |
|
432 |
s saveRemove:v |
|
433 |
] |
|
434 |
]. |
|
435 |
s inspect |
|
1052
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
436 |
" |
7d43187f7e11
added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
437 |
|
6191 | 438 |
"Created: / 1.3.1996 / 21:14:26 / cg" |
439 |
"Modified: / 16.11.2001 / 10:22:59 / cg" |
|
10588 | 440 |
! |
441 |
||
442 |
testAndAdd:anObject |
|
443 |
"add the argument, anObject to the receiver. |
|
444 |
Answer true, if the element did already exist in the collection, |
|
445 |
false otherwise. |
|
446 |
||
447 |
WARNING: do not add elements while iterating over the receiver. |
|
448 |
Iterate over a copy to do this." |
|
449 |
||
450 |
|index "{ Class: SmallInteger }"| |
|
451 |
||
452 |
anObject isNil ifTrue:[ |
|
453 |
^ self invalidElementError. |
|
454 |
]. |
|
455 |
||
456 |
index := self findKeyOrNil:anObject. |
|
457 |
(keyArray basicAt:index) isNil ifTrue:[ |
|
458 |
"/ not already there |
|
459 |
keyArray basicAt:index put:anObject. |
|
460 |
tally := tally + 1. |
|
461 |
||
462 |
self fullCheck. |
|
463 |
^ false. |
|
464 |
]. |
|
465 |
^ true. |
|
466 |
||
467 |
"Modified: 30.1.1997 / 14:58:08 / cg" |
|
609 | 468 |
! ! |
469 |
||
11052 | 470 |
|
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
471 |
!Set methodsFor:'comparing'! |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
472 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
473 |
= aCollection |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
474 |
"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
|
475 |
as I do" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
476 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
477 |
aCollection species == self species ifFalse:[^ false]. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
478 |
aCollection size == self size ifFalse:[^ false]. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
479 |
"/ same number of elements; since I am a Set, all of |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
480 |
"/ of my elements must be in the other collection ... |
10090
af5b9428e8ae
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
9933
diff
changeset
|
481 |
^ self conform:[:element | (aCollection includes:element)] |
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
482 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
483 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
484 |
#(1 2 3 4 5) asSet = #(2 3 4 5 1) asSet |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
485 |
#(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
|
486 |
#(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
|
487 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
488 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
489 |
|d1 d2| |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
490 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
491 |
d1 := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
492 |
d2 := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
493 |
d1 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
494 |
d1 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
495 |
d1 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
496 |
d1 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
497 |
d1 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
498 |
d1 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
499 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
500 |
d2 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
501 |
d2 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
502 |
d2 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
503 |
d2 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
504 |
d2 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
505 |
d2 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
506 |
d1 = d2 |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
507 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
508 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
509 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
510 |
|d1 d2| |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
511 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
512 |
d1 := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
513 |
d2 := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
514 |
d1 at:1 put:'uno'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
515 |
d1 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
516 |
d1 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
517 |
d1 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
518 |
d1 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
519 |
d1 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
520 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
521 |
d2 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
522 |
d2 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
523 |
d2 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
524 |
d2 at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
525 |
d2 at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
526 |
d2 at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
527 |
d1 = d2 |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
528 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
529 |
|
10090
af5b9428e8ae
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
9933
diff
changeset
|
530 |
"Modified: / 13-10-2006 / 12:58:43 / cg" |
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
531 |
! |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
532 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
533 |
hash |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
534 |
"return a hash key for the receiver" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
535 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
536 |
"this hash is stupid - but for larger collections, the hashing |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
537 |
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
|
538 |
Time will show ... |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
539 |
Notice & warning: |
6994 | 540 |
if the #= method is ever changed to compare non-dictionaries equal, |
541 |
the code below must be changed to assert that the same hash-value is |
|
542 |
still returned. |
|
543 |
(which may be hard to acomplish) |
|
5280
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
544 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
545 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
546 |
|mySize| |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
547 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
548 |
mySize := self size. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
549 |
mySize == 0 ifTrue:[^ 0]. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
550 |
^ ((self first) hash times:mySize) bitAnd:16r3FFFFFFF |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
551 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
552 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
553 |
|d| |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
554 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
555 |
d := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
556 |
d at:1 put:'one'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
557 |
d at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
558 |
d at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
559 |
d at:'two' put:2. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
560 |
d hash |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
561 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
562 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
563 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
564 |
|d| |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
565 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
566 |
d := Dictionary new. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
567 |
d at:1 put:'uno'. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
568 |
d at:'one' put:1. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
569 |
d at:2 put:#two. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
570 |
d at:'two' put:2. |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
571 |
d hash |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
572 |
" |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
573 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
574 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
575 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
576 |
|
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
577 |
! ! |
ad806c9b992e
added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
578 |
|
159 | 579 |
!Set methodsFor:'copying'! |
580 |
||
581 |
postCopy |
|
582 |
"have to copy the keyArray too" |
|
583 |
||
584 |
keyArray := keyArray shallowCopy |
|
1 | 585 |
! ! |
586 |
||
609 | 587 |
!Set methodsFor:'enumerating'! |
1 | 588 |
|
609 | 589 |
do:aBlock |
1056 | 590 |
"perform the block for all members in the collection. |
591 |
||
592 |
WARNING: do not add/remove elements while iterating over the receiver. |
|
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
|
593 |
Iterate over a copy to do this." |
13 | 594 |
|
609 | 595 |
|sz "{ Class: SmallInteger }" |
596 |
element| |
|
13 | 597 |
|
609 | 598 |
sz := keyArray size. |
599 |
1 to:sz do:[:index | |
|
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
|
600 |
element := keyArray at:index. |
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
|
601 |
(element notNil and:[element ~~ DeletedEntry]) ifTrue:[ |
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
|
602 |
aBlock value:element |
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
|
603 |
] |
609 | 604 |
] |
1056 | 605 |
|
606 |
"Modified: 1.3.1996 / 21:41:13 / cg" |
|
609 | 607 |
! ! |
61 | 608 |
|
969 | 609 |
|
7169 | 610 |
!Set methodsFor:'obsolete set operations'! |
611 |
||
612 |
+ aCollection |
|
8606 | 613 |
"Kept for backward compatibility. |
614 |
Use #union: instead, to isolate arithmethic and set operations" |
|
7169 | 615 |
|
616 |
<resource: #obsolete> |
|
617 |
||
618 |
^ self union:aCollection. |
|
619 |
! |
|
620 |
||
621 |
- aCollection |
|
8606 | 622 |
"Kept for backward compatibility. |
623 |
Use #\ instead, to isolate arithmethic and set operations" |
|
7169 | 624 |
|
625 |
<resource: #obsolete> |
|
626 |
||
627 |
^ self \ aCollection |
|
628 |
! ! |
|
629 |
||
609 | 630 |
!Set methodsFor:'private'! |
2 | 631 |
|
1 | 632 |
find:key ifAbsent:aBlock |
633 |
"Look for the key in the receiver. If it is found, return |
|
634 |
the index of the slot containing the key, otherwise |
|
635 |
return the value of evaluating aBlock." |
|
636 |
||
61 | 637 |
|index "{ Class:SmallInteger }" |
638 |
length "{ Class:SmallInteger }" |
|
639 |
startIndex probe| |
|
1 | 640 |
|
13 | 641 |
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
|
642 |
|
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
|
643 |
"/ |
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
|
644 |
"/ length < 10 ifTrue:[ |
362 | 645 |
"/ "assuming, that for small collections the overhead of hashing |
646 |
"/ is larger ... maybe that proves wrong |
|
647 |
"/ (if overhead of comparing is higher)" |
|
648 |
"/ ^ 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
|
649 |
"/ ]. |
13 | 650 |
|
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
651 |
startIndex := index := self initialIndexForKey:key. |
1 | 652 |
|
653 |
[true] whileTrue:[ |
|
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
654 |
probe := (keyArray basicAt:index). |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
655 |
(probe notNil and:[key = probe]) ifTrue:[^ index]. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
656 |
(self slotIsEmpty:probe) ifTrue:[^ aBlock value]. |
1 | 657 |
|
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
658 |
index == length ifTrue:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
659 |
index := 1 |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
660 |
] ifFalse:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
661 |
index := index + 1 |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
662 |
]. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
663 |
index == startIndex ifTrue:[^ aBlock value]. |
1 | 664 |
] |
665 |
! |
|
666 |
||
13 | 667 |
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
|
668 |
"Look for the key in the receiver. |
3082 | 669 |
If it is found, return the index of the first unused slot. |
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
|
670 |
Grow the receiver, if key was not found, and no unused slots were present" |
1 | 671 |
|
61 | 672 |
|index "{ Class:SmallInteger }" |
673 |
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
|
674 |
startIndex probe |
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
675 |
delIndex| |
1 | 676 |
|
13 | 677 |
length := keyArray basicSize. |
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
678 |
startIndex := index := self initialIndexForKey:key. |
1 | 679 |
|
680 |
[true] whileTrue:[ |
|
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
681 |
probe := keyArray basicAt:index. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
682 |
(probe notNil and:[key = probe]) ifTrue:[^ index]. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
683 |
(self slotIsEmpty:probe) ifTrue:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
684 |
delIndex isNil ifTrue:[^ index]. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
685 |
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
|
686 |
^ delIndex |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
687 |
]. |
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
|
688 |
|
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
689 |
probe == DeletedEntry ifTrue:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
690 |
delIndex isNil ifTrue:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
691 |
delIndex := index |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
692 |
] |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
693 |
]. |
1 | 694 |
|
7654
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
695 |
index == length ifTrue:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
696 |
index := 1 |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
697 |
] ifFalse:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
698 |
index := index + 1 |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
699 |
]. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
700 |
index == startIndex ifTrue:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
701 |
delIndex notNil ifTrue:[ |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
702 |
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
|
703 |
^ delIndex |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
704 |
]. |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
705 |
^ self grow findKeyOrNil:key |
41441d702cfc
avoid need for elements to know how to compare against nil.
Claus Gittinger <cg@exept.de>
parents:
7598
diff
changeset
|
706 |
]. |
1 | 707 |
] |
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
|
708 |
|
3082 | 709 |
"Modified: / 30.10.1997 / 16:01:57 / cg" |
1 | 710 |
! |
711 |
||
712 |
findNil:key |
|
2475 | 713 |
"Look for the next slot usable for key. |
714 |
WARNING: |
|
6994 | 715 |
This method assumes that key is not already in the receiver |
716 |
AND that keyArray does not have previously removed entries |
|
717 |
AND that there is an empty slot. |
|
2475 | 718 |
To be used ONLY while growing/rehashing to enter elements into a fresh |
719 |
collection - if any of the above conditions is not met, the method |
|
720 |
loops forever." |
|
1 | 721 |
|
2475 | 722 |
|index "{ Class:SmallInteger }" |
61 | 723 |
length "{ Class:SmallInteger }"| |
1 | 724 |
|
13 | 725 |
length := keyArray basicSize. |
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
726 |
index := self initialIndexForKey:key. |
1 | 727 |
|
5772 | 728 |
"/ index := keyArray identityIndexOf:nil startingAt:index. |
729 |
"/ index == 0 ifTrue:[ |
|
730 |
"/ index := keyArray identityIndexOf:nil startingAt:1 endingAt:index. |
|
731 |
"/ ]. |
|
732 |
"/ that code is completely inlined by stc ... |
|
733 |
[(keyArray basicAt:index) notNil] whileTrue:[ |
|
6994 | 734 |
index == length ifTrue:[ |
735 |
index := 1 |
|
736 |
] ifFalse:[ |
|
737 |
index := index + 1 |
|
738 |
]. |
|
739 |
"notice: no check for no nil found - we must find one since |
|
740 |
this is only called after growing" |
|
1 | 741 |
]. |
742 |
^ index |
|
1055 | 743 |
|
2475 | 744 |
"Modified: 21.3.1997 / 10:32:58 / cg" |
1 | 745 |
! |
746 |
||
2459
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
747 |
hashFor:aKey |
6991
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
748 |
"return the arguments hash value. |
e95313d7c780
comment and category change only
Claus Gittinger <cg@exept.de>
parents:
6917
diff
changeset
|
749 |
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
|
750 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
751 |
^ aKey hash |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
752 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
753 |
"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
|
754 |
! |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
755 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
756 |
initialIndexForKey:aKey |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
757 |
"return an initial index given a key." |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
758 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
759 |
|index "{ Class:SmallInteger }" |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
760 |
length "{ Class:SmallInteger }"| |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
761 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
762 |
length := keyArray basicSize. |
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
763 |
index := (self hashFor:aKey) bitAnd:16r3FFFFFFF. |
2459
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
764 |
index < 16r1FFFFFFF ifTrue:[ |
6994 | 765 |
index := index * 2 |
2459
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
766 |
]. |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
767 |
index := index \\ length + 1. |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
768 |
^ index. |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
769 |
|
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
770 |
"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
|
771 |
"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
|
772 |
! |
0a38e8602aac
findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
773 |
|
5845
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
774 |
invalidElementError |
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
775 |
"this is send when a nil is used with a Set. |
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
776 |
For now this is just an info-Message. Will become an error sometimes." |
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
777 |
|
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
778 |
"/ self elementBoundError. |
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
779 |
|
9086 | 780 |
InfoPrinting ifTrue:[ |
781 |
'Set [warning]: nil is not a valid element - will be an error in later versions' errorPrintCR. |
|
11472 | 782 |
Context showWhereWeCameFrom. |
6540
cf1a6a1a8645
better invalidElementError message
Claus Gittinger <cg@exept.de>
parents:
6519
diff
changeset
|
783 |
]. |
5845
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
784 |
! |
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
785 |
|
3261
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
786 |
keyArray |
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
787 |
^ keyArray |
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
788 |
|
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
789 |
"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
|
790 |
! |
7e4e57c041df
added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents:
3082
diff
changeset
|
791 |
|
609 | 792 |
keyContainerOfSize:n |
793 |
"return a container for keys of size n. |
|
794 |
Extracted to make life of weak subclasses easier ..." |
|
795 |
||
796 |
^ Array basicNew:n |
|
797 |
! |
|
798 |
||
1 | 799 |
rehash |
61 | 800 |
"rehash is done by re-adding all elements to a new empty set. |
801 |
Rehash is needed after a binaryRead, for example." |
|
1 | 802 |
|
3082 | 803 |
|element oldKeyArray newKeyArray newIdx |
95 | 804 |
n "{ Class:SmallInteger }"| |
1 | 805 |
|
95 | 806 |
oldKeyArray := keyArray. |
807 |
n := oldKeyArray size. |
|
808 |
keyArray := newKeyArray := self keyContainerOfSize:n. |
|
809 |
||
2 | 810 |
1 to:n do:[:index | |
6994 | 811 |
element := oldKeyArray at:index. |
812 |
(element notNil and:[element ~~ DeletedEntry]) ifTrue:[ |
|
813 |
"cannot be already there" |
|
814 |
newIdx := self findNil:element. |
|
815 |
newKeyArray basicAt:newIdx put:element |
|
816 |
]. |
|
1 | 817 |
] |
3082 | 818 |
|
819 |
"Modified: / 30.10.1997 / 16:04:46 / cg" |
|
1 | 820 |
! |
821 |
||
822 |
rehashFrom:startIndex |
|
61 | 823 |
"rehash elements starting at index - after a remove. |
824 |
Notice: due to the new implementation of remove, |
|
159 | 825 |
this is no longer needed" |
1 | 826 |
|
3 | 827 |
|element i "{ Class:SmallInteger }" |
828 |
length |
|
1 | 829 |
index "{ Class:SmallInteger }" | |
830 |
||
13 | 831 |
length := keyArray basicSize. |
1 | 832 |
index := startIndex. |
13 | 833 |
element := keyArray basicAt:index. |
1 | 834 |
[element notNil] whileTrue:[ |
159 | 835 |
i := self findNil:element. |
836 |
i == index ifTrue:[ |
|
837 |
^ self |
|
838 |
]. |
|
839 |
keyArray basicAt:i put:element. |
|
840 |
keyArray basicAt:index put:nil. |
|
1 | 841 |
|
159 | 842 |
index == length ifTrue:[ |
843 |
index := 1 |
|
844 |
] ifFalse:[ |
|
845 |
index := index + 1. |
|
846 |
]. |
|
847 |
element := keyArray basicAt:index. |
|
1 | 848 |
] |
849 |
! |
|
850 |
||
609 | 851 |
setTally:count |
852 |
"initialize the contents array (for at least count slots) |
|
853 |
and set tally to zero. |
|
854 |
The size is increased to the next prime for better hashing behavior." |
|
1 | 855 |
|
3726
cf3eafa152a4
try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents:
3265
diff
changeset
|
856 |
|n| |
cf3eafa152a4
try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents:
3265
diff
changeset
|
857 |
|
cf3eafa152a4
try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents:
3265
diff
changeset
|
858 |
n := self class goodSizeFrom:count. |
cf3eafa152a4
try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents:
3265
diff
changeset
|
859 |
n == keyArray size ifTrue:[ |
6994 | 860 |
keyArray atAllPut:nil. |
3726
cf3eafa152a4
try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents:
3265
diff
changeset
|
861 |
] ifFalse:[ |
6994 | 862 |
keyArray := self keyContainerOfSize:n. |
3726
cf3eafa152a4
try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents:
3265
diff
changeset
|
863 |
]. |
609 | 864 |
tally := 0 |
3726
cf3eafa152a4
try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents:
3265
diff
changeset
|
865 |
|
cf3eafa152a4
try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents:
3265
diff
changeset
|
866 |
"Modified: / 4.8.1998 / 22:07:25 / cg" |
6233 | 867 |
! |
868 |
||
869 |
slotIsEmpty:aSlotValue |
|
870 |
"only redefined in weak subclasses, since they treat a 0-value |
|
871 |
as being empty" |
|
872 |
||
873 |
^ aSlotValue isNil |
|
1 | 874 |
! ! |
875 |
||
7260 | 876 |
!Set methodsFor:'private-grow & shrink'! |
3082 | 877 |
|
878 |
emptyCheck |
|
879 |
"check if the receiver has become too empty (after a remove) |
|
880 |
and shrink if it makes sense. |
|
881 |
Definition of 'too empty' is 'filled less than 12.5% (i.e. 1/8th)'" |
|
882 |
||
883 |
|sz "{Class: SmallInteger}" |
|
884 |
newSize "{Class: SmallInteger}" | |
|
885 |
||
886 |
sz := keyArray basicSize. |
|
887 |
sz > 56 ifTrue:[ |
|
6994 | 888 |
" |
889 |
shrink if too empty |
|
890 |
" |
|
891 |
tally < (sz // 8) ifTrue:[ |
|
892 |
newSize := sz // 4. |
|
893 |
self grow:newSize |
|
894 |
] |
|
3082 | 895 |
] |
896 |
||
897 |
"Modified: 19.3.1997 / 16:02:55 / cg" |
|
898 |
! |
|
899 |
||
900 |
fullCheck |
|
901 |
"check if collection is full (after an add); grow if so. |
|
902 |
Definition of 'full' is currently: 'filled more than 75% (i.e. 3/4th)'" |
|
903 |
||
904 |
|sz "{Class: SmallInteger}" | |
|
905 |
||
906 |
" |
|
907 |
grow if filled more than 75% |
|
908 |
" |
|
909 |
sz := keyArray basicSize. |
|
910 |
tally > (sz * 3 // 4) ifTrue:[ |
|
911 |
self grow |
|
912 |
] |
|
913 |
! |
|
914 |
||
915 |
grow |
|
916 |
"change the number of element slots of the collection to a useful |
|
917 |
new size" |
|
918 |
||
919 |
self grow:(keyArray basicSize * 2) |
|
920 |
! |
|
921 |
||
922 |
grow:newSize |
|
923 |
"change the number of element slots of the collection - to do this, |
|
924 |
we have to rehash (which is done by re-adding all elements to a new |
|
925 |
empty set)." |
|
926 |
||
927 |
|elem oldKeyArray newKeyArray deletedEntry |
|
928 |
containerSize oldSize "{ Class:SmallInteger }"| |
|
929 |
||
930 |
oldKeyArray := keyArray. |
|
931 |
oldSize := oldKeyArray size. |
|
932 |
containerSize := (self class goodSizeFrom:newSize). |
|
933 |
containerSize == oldSize ifTrue:[^ self]. |
|
934 |
||
935 |
keyArray := newKeyArray := self keyContainerOfSize:containerSize. |
|
936 |
||
937 |
deletedEntry := DeletedEntry. |
|
938 |
1 to:oldSize do:[:srcIndex | |
|
939 |
elem := oldKeyArray basicAt:srcIndex. |
|
940 |
(elem notNil and:[elem ~~ deletedEntry]) ifTrue:[ |
|
941 |
"cannot be already there" |
|
942 |
newKeyArray basicAt:(self findNil:elem) put:elem |
|
943 |
]. |
|
944 |
]. |
|
945 |
! ! |
|
946 |
||
5557 | 947 |
!Set methodsFor:'queries'! |
948 |
||
8499 | 949 |
collisionCount |
950 |
"return the number of key collisions in the set. |
|
951 |
There is a collision if two keys hash to the same value." |
|
952 |
||
953 |
|count| |
|
954 |
||
955 |
count := 0. |
|
956 |
||
957 |
keyArray do:[:eachKey| |
|
958 |
(eachKey notNil and:[eachKey ~~ DeletedEntry]) ifTrue:[ |
|
959 |
count := count + (self collisionsFor:eachKey). |
|
960 |
] |
|
961 |
]. |
|
962 |
||
963 |
^ count |
|
964 |
! |
|
965 |
||
966 |
collisionsFor:key |
|
967 |
"Return the number of searches - 1 required for key" |
|
968 |
||
969 |
|index "{ Class:SmallInteger }" |
|
970 |
length "{ Class:SmallInteger }" |
|
971 |
hash "{ Class:SmallInteger }" |
|
972 |
step "{ Class:SmallInteger }" |
|
973 |
startIndex probe count| |
|
974 |
||
975 |
length := keyArray basicSize. |
|
976 |
hash := (self hashFor:key) bitAnd:16r3FFFFFFF. |
|
977 |
hash < 16r1FFFFFFF ifTrue:[ |
|
978 |
hash := hash * 2 |
|
979 |
]. |
|
980 |
startIndex := index := hash \\ length + 1. |
|
981 |
step:= hash // length + 1. |
|
982 |
||
983 |
count := 0. |
|
984 |
[true] whileTrue:[ |
|
985 |
probe := (keyArray basicAt:index). |
|
986 |
(probe notNil and:[key = probe]) ifTrue:[^ count]. |
|
987 |
(self slotIsEmpty:probe) ifTrue:[self error:'non existing key']. |
|
988 |
||
989 |
index == length ifTrue:[ |
|
990 |
index := 1. |
|
991 |
] ifFalse:[ |
|
992 |
index := index + 1. |
|
993 |
]. |
|
994 |
count := count + 1. |
|
995 |
index == startIndex ifTrue:[self error:'non existing key']. |
|
996 |
] |
|
997 |
! |
|
998 |
||
999 |
maxChainLength |
|
1000 |
"return the number of the maximum chain length in the set. |
|
1001 |
This is the worst case overhead when accessing a key." |
|
1002 |
||
1003 |
|chainLength key| |
|
1004 |
||
1005 |
chainLength := 0. |
|
1006 |
||
1007 |
keyArray do:[:eachKey| |t| |
|
1008 |
(eachKey notNil and:[eachKey ~~ DeletedEntry]) ifTrue:[ |
|
1009 |
t := self collisionsFor:eachKey. |
|
1010 |
chainLength < t ifTrue:[chainLength := t. key := eachKey]. |
|
1011 |
] |
|
1012 |
]. |
|
1013 |
||
1014 |
^ (key -> chainLength) |
|
1015 |
! |
|
1016 |
||
5557 | 1017 |
size |
1018 |
"return the number of set elements" |
|
1019 |
||
1020 |
^ tally |
|
1021 |
! ! |
|
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5335
diff
changeset
|
1022 |
|
1 | 1023 |
!Set methodsFor:'testing'! |
1024 |
||
362 | 1025 |
capacity |
1026 |
"return the number of elements, that the receiver is |
|
1027 |
prepared to take. |
|
1028 |
Not used by the system; added for ST-80 compatibility." |
|
1029 |
||
1030 |
^ keyArray size |
|
1031 |
! |
|
1032 |
||
1 | 1033 |
includes:anObject |
1034 |
"return true if the argument anObject is in the receiver" |
|
1035 |
||
5568
826390eef742
includes:nil - allowed, but send out a warning
Claus Gittinger <cg@exept.de>
parents:
5557
diff
changeset
|
1036 |
anObject isNil ifTrue:[ |
6994 | 1037 |
"even if adding nil to a set is forbidden, asking for it should be ok!!" |
1038 |
"self invalidElementError." |
|
1039 |
^ false |
|
5568
826390eef742
includes:nil - allowed, but send out a warning
Claus Gittinger <cg@exept.de>
parents:
5557
diff
changeset
|
1040 |
]. |
362 | 1041 |
^ (self find:anObject ifAbsent:0) ~~ 0 |
1 | 1042 |
! |
1043 |
||
1044 |
isEmpty |
|
1045 |
"return true if the receiver is empty" |
|
1046 |
||
1047 |
^ tally == 0 |
|
1048 |
! |
|
1049 |
||
609 | 1050 |
isFixedSize |
1051 |
"return true if the receiver cannot grow - this will vanish once |
|
1052 |
Arrays and Strings learn how to grow ..." |
|
1053 |
||
1054 |
^ false |
|
1055 |
! |
|
1056 |
||
2383 | 1057 |
notEmpty |
1058 |
"return true if the receiver is not empty" |
|
1059 |
||
1060 |
^ tally ~~ 0 |
|
1061 |
||
1062 |
"Created: 12.2.1997 / 12:39:02 / cg" |
|
1063 |
! |
|
1064 |
||
1 | 1065 |
occurrencesOf:anObject |
5048 | 1066 |
"return the number of occurrences of anObject in the receiver. |
6191 | 1067 |
As I am a Set, this can only return 0 or 1." |
1 | 1068 |
|
5845
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
1069 |
anObject isNil ifTrue:[ |
6994 | 1070 |
"even if adding nil to a set is forbidden, asking for it should be ok!!" |
1071 |
"self invalidElementError." |
|
1072 |
^ 0. |
|
5845
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
1073 |
]. |
64a385f14970
Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents:
5834
diff
changeset
|
1074 |
|
362 | 1075 |
(self find:anObject ifAbsent:0) == 0 ifTrue:[^ 0]. |
1 | 1076 |
^ 1 |
6191 | 1077 |
|
1078 |
"Modified: / 16.11.2001 / 10:30:14 / cg" |
|
1 | 1079 |
! |
1080 |
||
4795 | 1081 |
sameContentsAs:aCollection |
1082 |
"answer true, if all the elements in self and aCollection |
|
1083 |
are common. This is not defined as #=, since we cannot redefine #hash |
|
1084 |
for aCollection." |
|
1085 |
||
1086 |
aCollection size ~~ self size ifTrue:[ |
|
10090
af5b9428e8ae
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
9933
diff
changeset
|
1087 |
^ false |
4795 | 1088 |
]. |
1089 |
||
10090
af5b9428e8ae
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
9933
diff
changeset
|
1090 |
^ aCollection conform:[:e | (self includes:e)] |
4795 | 1091 |
|
1092 |
" |
|
1093 |
#(1 2 3) asSet sameContentsAs: #(1 2 3) |
|
1094 |
#(1 2 3 4) asSet sameContentsAs: #(1 2 3) |
|
1095 |
#(1 2 3) asSet sameContentsAs: #(1 2 3 3) |
|
1096 |
#(1 2 3 'aa') asSet sameContentsAs: #(1 2 3 'aa') |
|
1097 |
#(1 2 3 'aa') asIdentitySet sameContentsAs: #(1 2 3 'aa') |
|
1098 |
#(1 2 3 #aa) asIdentitySet sameContentsAs: #(1 2 3 #aa) |
|
1099 |
" |
|
1100 |
||
10090
af5b9428e8ae
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
9933
diff
changeset
|
1101 |
"Modified: / 13-10-2006 / 12:59:01 / cg" |
1 | 1102 |
! ! |
1103 |
||
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1104 |
!Set methodsFor:'visiting'! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1105 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1106 |
acceptVisitor:aVisitor with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1107 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1108 |
^ aVisitor visitSet:self with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1109 |
! ! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7654
diff
changeset
|
1110 |
|
4017
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1111 |
!Set::EmptySlot class methodsFor:'instance creation'! |
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1112 |
|
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1113 |
basicNew |
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1114 |
TheOneAndOnlyInstance isNil ifTrue:[ |
6994 | 1115 |
TheOneAndOnlyInstance := super basicNew |
4017
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1116 |
]. |
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1117 |
^ TheOneAndOnlyInstance |
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1118 |
|
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1119 |
! ! |
cdf103ce2e30
there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents:
3726
diff
changeset
|
1120 |
|
2259 | 1121 |
!Set class methodsFor:'documentation'! |
635 | 1122 |
|
1123 |
version |
|
17711 | 1124 |
^ '$Id: Set.st 10447 2009-06-14 13:09:55Z vranyj1 $' |
635 | 1125 |
! ! |
6917
979bfb9267e3
refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents:
6577
diff
changeset
|
1126 |
|
609 | 1127 |
Set initialize! |