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