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