author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 17 May 2016 10:05:14 +0100 | |
branch | jv |
changeset 19863 | 513bd7237fe7 |
parent 19861 | 95c7068e30ba |
parent 19845 | ef17a74c2bd7 |
child 20081 | 2961b4289773 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
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 |
" |
|
5362 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
14 |
"{ NameSpace: Smalltalk }" |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
15 |
|
12 | 16 |
Set subclass:#Dictionary |
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
17 |
instanceVariableNames:'valueArray' |
14318 | 18 |
classVariableNames:'' |
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
19 |
poolDictionaries:'' |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
20 |
category:'Collections-Unordered' |
1 | 21 |
! |
22 |
||
2094
42cd02703bf4
handle recursive printString/displayString
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
23 |
!Dictionary class methodsFor:'documentation'! |
68 | 24 |
|
88 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
28 |
All Rights Reserved |
88 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
68 | 39 |
documentation |
40 |
" |
|
41 |
a Dictionary is (conceptionally) a set of Associations storing key-value pairs. |
|
42 |
(The implementation uses two arrays to store the keys and values separately.) |
|
43 |
Searching for an element is done using a hash into the key array. |
|
362 | 44 |
Another way of looking at a dictionary is as a array which uses |
345 | 45 |
arbitrary access keys (i.e. not just integers as arrays do). |
46 |
||
47 |
Since the keys are unordered, no internal element order is defined |
|
362 | 48 |
(i.e. enumerating them may return elements in any order - even changing |
345 | 49 |
over time). |
50 |
||
68 | 51 |
Many methods for searching and hashing are inherited from Set. |
92 | 52 |
|
1279 | 53 |
[Instance variables:] |
345 | 54 |
|
15800 | 55 |
keyArray <Array> (from Set) the keys |
1279 | 56 |
|
15800 | 57 |
valueArray <Array> the values ('valueArray at:index' corresponds |
58 |
to the value stored under 'keyArray at:index') |
|
92 | 59 |
|
14318 | 60 |
Performance hints: |
362 | 61 |
since the dictionary does not really store associations internally, |
62 |
it is less efficient, to store/retrieve associations. The reason is |
|
14318 | 63 |
that these assocs are created temporarily in some extract methods. |
64 |
I.e. 'at:key put:value' is faster than 'add:anAssoc' |
|
345 | 65 |
and 'keysAndValuesDo:' is faster than 'associationsDo:' etc. |
92 | 66 |
|
362 | 67 |
If only symbols or smallIntegers are used as keys, use IdentityDictionaries |
68 |
for slightly better performance, since both hashing and comparison is faster. |
|
345 | 69 |
|
70 |
If you have a rough idea how big the dictionary is going to grow, |
|
71 |
create it using #new: instead of #new. Even if the size given is a |
|
72 |
poor guess (say half of the real size), there is some 20-30% performance |
|
73 |
win to expect, since many resizing operations are avoided when associations |
|
74 |
are added. |
|
362 | 75 |
|
5336 | 76 |
Special note: |
77 |
in previous versions, nil was not allowed as valid key |
|
78 |
This has been changed; internally, a special nil-key is used, |
|
79 |
which is converted back to nil whenever keys are accessed. |
|
80 |
||
1290 | 81 |
[See also:] |
15800 | 82 |
Set, IdentityDictionary, IdentitySet, WeakIdentitySet and |
83 |
WeakIdentityDictionary |
|
1290 | 84 |
|
85 |
[author:] |
|
15800 | 86 |
Claus Gittinger |
68 | 87 |
" |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
88 |
! |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
89 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
90 |
examples |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
91 |
" |
19123 | 92 |
[exBegin] |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
93 |
|d| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
94 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
95 |
d := Dictionary new. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
96 |
d at:'1' put:'one'. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
97 |
d at:2 put:'two'. |
14318 | 98 |
d at:2 |
19123 | 99 |
[exEnd] |
100 |
||
101 |
[exBegin] |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
102 |
|d| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
103 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
104 |
d := Dictionary new. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
105 |
d at:'1' put:'one'. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
106 |
d at:2 put:nil. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
107 |
d. |
14318 | 108 |
d at:2 |
19123 | 109 |
[exEnd] |
110 |
||
111 |
[exBegin] |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
112 |
|d| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
113 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
114 |
d := Dictionary new. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
115 |
d at:'1' put:'one'. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
116 |
d at:2 put:nil. |
14318 | 117 |
d includes:nil. |
19123 | 118 |
[exEnd] |
119 |
||
120 |
[exBegin] |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
121 |
|d| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
122 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
123 |
d := Dictionary new. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
124 |
d at:'1' put:'one'. |
14318 | 125 |
d includes:nil. |
19123 | 126 |
[exEnd] |
127 |
[exBegin] |
|
128 |
|d1 d2| |
|
129 |
||
130 |
d1 := Dictionary withKeys:#(a b c) andValues:#( 1 2 3). |
|
131 |
d2 := Dictionary newFrom:d1. |
|
132 |
d2. |
|
133 |
[exEnd] |
|
134 |
||
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
135 |
" |
68 | 136 |
! ! |
137 |
||
2094
42cd02703bf4
handle recursive printString/displayString
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
138 |
!Dictionary class methodsFor:'instance creation'! |
345 | 139 |
|
6100 | 140 |
decodeFromLiteralArray:anArray |
141 |
"create & return a new instance from information encoded in anArray." |
|
142 |
||
14318 | 143 |
|dictionary |
8831
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8434
diff
changeset
|
144 |
sz "{ Class: SmallInteger }"| |
6100 | 145 |
|
8831
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8434
diff
changeset
|
146 |
sz := anArray size. |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8434
diff
changeset
|
147 |
dictionary := self new:sz//2. |
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8434
diff
changeset
|
148 |
2 to:sz by:2 do:[:idx | |key val| |
14318 | 149 |
key := (anArray at:idx) decodeAsLiteralArray. |
150 |
val := (anArray at:idx+1) decodeAsLiteralArray. |
|
151 |
dictionary at:key put:val |
|
6100 | 152 |
]. |
8831
918f291920c2
Speed up #decodeFromLiteralArray:
Stefan Vogel <sv@exept.de>
parents:
8434
diff
changeset
|
153 |
^ dictionary |
6100 | 154 |
|
155 |
" |
|
156 |
(Dictionary new |
|
14318 | 157 |
at:1 put:'one'; |
158 |
at:2 put:'two'; |
|
159 |
yourself |
|
160 |
) literalArrayEncoding decodeAsLiteralArray |
|
6100 | 161 |
" |
162 |
! |
|
163 |
||
19138 | 164 |
withAssociations:aCollectionOfAssociations |
5255 | 165 |
"return a new instance where associations are taken from the argument" |
166 |
||
167 |
|newDict sz "{ Class: SmallInteger }"| |
|
168 |
||
19138 | 169 |
sz := aCollectionOfAssociations size. |
5255 | 170 |
newDict := self new:sz. |
19138 | 171 |
aCollectionOfAssociations do:[:assoc | |
172 |
newDict at:assoc key put:assoc value |
|
5255 | 173 |
]. |
174 |
^ newDict |
|
175 |
||
176 |
" |
|
14318 | 177 |
Dictionary withAssociations:(Array |
19138 | 178 |
with:#'one'->1 |
179 |
with:#'two'->2 |
|
180 |
with:#'three'->3 |
|
181 |
with:#'four'->4) |
|
5255 | 182 |
" |
183 |
||
184 |
"Created: / 11.2.2000 / 10:05:54 / cg" |
|
185 |
! |
|
186 |
||
357 | 187 |
withKeys:keyArray andValues:valueArray |
188 |
"return a new instance where keys and values are taken from |
|
189 |
the argumentArrays." |
|
190 |
||
191 |
|newDict sz "{ Class: SmallInteger }"| |
|
192 |
||
193 |
sz := keyArray size. |
|
194 |
newDict := self new:sz. |
|
195 |
keyArray with:valueArray do:[:key :value | |
|
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
196 |
newDict at:key put:value |
357 | 197 |
]. |
198 |
^ newDict |
|
199 |
||
200 |
" |
|
201 |
Dictionary withKeys:#('one' 'two' 'three' 'four') |
|
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
202 |
andValues:#(1 2 3 4) |
357 | 203 |
" |
54 | 204 |
! |
205 |
||
19224 | 206 |
withKeys:aCollection valueBlock:aOneArgBlock |
207 |
"return a Dictionary with keys from aCollection's elements, |
|
208 |
using aOneArgBlock to generate the values from aCollection's elements." |
|
209 |
||
210 |
|d| |
|
211 |
||
212 |
d := self new:aCollection size. |
|
213 |
aCollection do:[:each| |
|
214 |
d at:each put:(aOneArgBlock value:each). |
|
215 |
]. |
|
216 |
^ d |
|
217 |
||
218 |
" |
|
219 |
Dictionary withKeys:#(10 20 30 40 50 60 70 80 90) valueBlock:[:e| e asString] |
|
220 |
" |
|
221 |
! |
|
222 |
||
609 | 223 |
withKeysAndValues:anArray |
224 |
"return a new instance where keys and values are taken from alternating |
|
225 |
elements of anArray" |
|
54 | 226 |
|
609 | 227 |
|newDict sz "{ Class: SmallInteger }"| |
345 | 228 |
|
609 | 229 |
sz := anArray size. |
230 |
newDict := self new:(sz // 2). |
|
231 |
1 to:sz by:2 do:[:i | |
|
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
232 |
newDict at:(anArray at:i) put:(anArray at:i+1) |
609 | 233 |
]. |
234 |
^ newDict |
|
345 | 235 |
|
609 | 236 |
" |
237 |
Dictionary withKeysAndValues:#('one' 1 'two' 2 'three' 3 'four' 4) |
|
238 |
" |
|
19224 | 239 |
! |
240 |
||
241 |
withValues:aCollection keyBlock:aOneArgBlock |
|
242 |
"return a Dictionary with values from aCollection's elements, |
|
243 |
using aOneArgBlock to generate the keys from aCollection's elements." |
|
244 |
||
245 |
|d| |
|
246 |
||
247 |
d := self new:aCollection size. |
|
248 |
aCollection do:[:each| |
|
249 |
d at:(aOneArgBlock value:each) put:each. |
|
250 |
]. |
|
251 |
^ d |
|
252 |
||
253 |
" |
|
254 |
Dictionary withValues:#(10 20 30 40 50 60 70 80 90) keyBlock:[:e| e asString] |
|
255 |
" |
|
1 | 256 |
! ! |
257 |
||
7306 | 258 |
!Dictionary class methodsFor:'Compatibility-Squeak'! |
5362 | 259 |
|
260 |
newFrom:aCollectionOfAssociations |
|
261 |
"return a new instance where associations are taken from the argument" |
|
262 |
||
19123 | 263 |
aCollectionOfAssociations isDictionary ifTrue:[ |
264 |
^ self withAssociations:aCollectionOfAssociations associations |
|
265 |
]. |
|
5362 | 266 |
^ self withAssociations:aCollectionOfAssociations |
267 |
||
268 |
" |
|
269 |
Dictionary newFrom:(Array with:#foo->#Foo |
|
19123 | 270 |
with:#bar->#Bar) |
5362 | 271 |
" |
272 |
! ! |
|
273 |
||
12732 | 274 |
!Dictionary methodsFor:'Compatibility-Dolphin'! |
275 |
||
276 |
equals:aDictionary |
|
277 |
^ self = aDictionary |
|
278 |
! ! |
|
279 |
||
17671 | 280 |
!Dictionary methodsFor:'Compatibility-VW5.4'! |
281 |
||
282 |
contentsEquals: aDictionary |
|
283 |
"Anwer true if the receiver and aDictionary contain the same key/values. |
|
284 |
(ignoring the classes)" |
|
285 |
||
286 |
self size == aDictionary size ifFalse: [ ^false ]. |
|
287 |
||
288 |
self keysAndValuesDo: [ :key :value | |
|
289 |
( aDictionary at: key ifAbsent: [ ^false ] ) = value |
|
290 |
ifFalse: [ ^false ] |
|
291 |
]. |
|
292 |
^ true |
|
293 |
! ! |
|
294 |
||
1 | 295 |
!Dictionary methodsFor:'accessing'! |
296 |
||
609 | 297 |
associationAt:aKey |
14318 | 298 |
"return an association consisting of aKey and the element indexed |
299 |
by aKey - |
|
609 | 300 |
report an error, if no element is stored under aKey" |
301 |
||
15008 | 302 |
^ self associationAt:aKey ifAbsent:[self errorKeyNotFound:aKey] |
609 | 303 |
! |
304 |
||
305 |
associationAt:aKey ifAbsent:exceptionBlock |
|
14318 | 306 |
"return an association consisting of aKey and the element indexed by aKey - |
14971 | 307 |
return result of exceptionBlock if no element is stored under aKey. |
308 |
Warning: this is a comatibility interface only, with a different semantic as |
|
309 |
the original ST80 implementation. The returned assoc is created on the fly, |
|
310 |
and not the one stored in the receiver (there are not assocs there)" |
|
609 | 311 |
|
15008 | 312 |
|index| |
313 |
||
314 |
"/ must return the real key in the assoc - not aKey, which might be equal but not identical |
|
315 |
index := self find:aKey ifAbsent:0. |
|
316 |
index ~~ 0 ifTrue:[ |
|
317 |
^ Association key:(keyArray basicAt:index) value:(valueArray basicAt:index) |
|
318 |
]. |
|
319 |
^ exceptionBlock value |
|
609 | 320 |
! |
321 |
||
322 |
associations |
|
19468 | 323 |
"return an ordered collection containing the receiver's associations." |
609 | 324 |
|
325 |
|coll| |
|
326 |
||
327 |
coll := OrderedCollection new:(keyArray size). |
|
328 |
self associationsDo:[:assoc | coll add:assoc]. |
|
329 |
^ coll |
|
330 |
! |
|
331 |
||
1 | 332 |
at:aKey |
333 |
"return the element indexed by aKey - report an error if none found" |
|
334 |
||
6233 | 335 |
^ self at:aKey ifAbsent:[self errorKeyNotFound:aKey] |
1 | 336 |
! |
337 |
||
338 |
at:aKey ifAbsent:exceptionBlock |
|
14318 | 339 |
"return the element indexed by aKey - |
68 | 340 |
return result of exceptionBlock if no element is stored under aKey" |
2 | 341 |
|
5336 | 342 |
|index k| |
1 | 343 |
|
5336 | 344 |
(k := aKey) isNil ifTrue:[ |
14318 | 345 |
"/ nil is not allowed as key |
346 |
"/ |
|
347 |
"/ previous versions of ST/X raised an error |
|
348 |
"/ here. However, there seem to exist applications |
|
349 |
"/ which depend on getting the exceptionBlocks value |
|
350 |
"/ in this case ... well ... |
|
351 |
"/ ^ self errorInvalidKey:aKey |
|
5336 | 352 |
"/ no longer invalid. |
353 |
"/ ^ exceptionBlock value |
|
14318 | 354 |
k := NilEntry |
155 | 355 |
]. |
362 | 356 |
|
357 |
"/ I could have written: |
|
358 |
"/ index := self find:aKey ifAbsent:[^ exceptionBlock value] |
|
359 |
"/ but the code below is slighlty more efficient, since it avoids |
|
1146 | 360 |
"/ a block creation - thus speeding up the good case. |
362 | 361 |
|
5336 | 362 |
index := self find:k ifAbsent:0. |
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
|
363 |
index ~~ 0 ifTrue:[ |
14318 | 364 |
^ valueArray basicAt: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
|
365 |
]. |
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
|
366 |
^ exceptionBlock value. |
1 | 367 |
! |
368 |
||
16902 | 369 |
at:aKey ifAbsent:default update:aBlock |
370 |
"update the element stored under aKey with the result from |
|
371 |
evaluating aBlock with the previous stored value as argument, or with default, |
|
372 |
if there was no such key initially. |
|
373 |
I.e. this is the same as self at:aKey put:(aBlock value:(self at:aKey ifAbsent:default)). |
|
374 |
Return the new value stored. |
|
375 |
This is an optimized accessor, which only computes the hash value once." |
|
376 |
||
377 |
|k index "{ Class: SmallInteger }" |
|
378 |
newValue| |
|
379 |
||
380 |
(k := aKey) isNil ifTrue:[ |
|
381 |
k := NilEntry |
|
382 |
]. |
|
383 |
||
384 |
index := self findKeyOrNil:k. |
|
385 |
(keyArray basicAt:index) notNil ifTrue:[ |
|
386 |
"/ key present |
|
387 |
valueArray basicAt:index put:(newValue := aBlock value:(valueArray basicAt:index)). |
|
388 |
^ newValue |
|
389 |
]. |
|
390 |
"/ a new key |
|
391 |
keyArray basicAt:index put:k. |
|
392 |
valueArray basicAt:index put:(newValue := aBlock value:default). |
|
393 |
tally := tally + 1. |
|
394 |
||
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
395 |
self possiblyGrow. |
16902 | 396 |
^ newValue |
397 |
||
398 |
" |
|
399 |
|d| |
|
400 |
||
401 |
d := Dictionary new. |
|
402 |
d at:'one' ifAbsent:0 update:[:val | val + 1]. |
|
403 |
d at:'two' ifAbsent:0 update:[:val | val + 1]. |
|
404 |
d at:'three' ifAbsent:0 update:[:val | val + 1]. |
|
405 |
d at:'one' ifAbsent:0 update:[:val | val + 1]. |
|
406 |
d at:'two' ifAbsent:0 update:[:val | val + 1]. |
|
407 |
d |
|
408 |
" |
|
409 |
! |
|
410 |
||
3304
19ee5d1685d8
Make #at:ifAbsentPut: ST80 (and STBroker compatible).
Stefan Vogel <sv@exept.de>
parents:
3252
diff
changeset
|
411 |
at:aKey ifAbsentPut:valueBlock |
3215 | 412 |
"return the element indexed by aKey if present, |
3304
19ee5d1685d8
Make #at:ifAbsentPut: ST80 (and STBroker compatible).
Stefan Vogel <sv@exept.de>
parents:
3252
diff
changeset
|
413 |
if not present, store the result of evaluating valueBlock |
19ee5d1685d8
Make #at:ifAbsentPut: ST80 (and STBroker compatible).
Stefan Vogel <sv@exept.de>
parents:
3252
diff
changeset
|
414 |
under aKey and return it. |
3215 | 415 |
WARNING: do not add elements while iterating over the receiver. |
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
416 |
Iterate over a copy to do this." |
3215 | 417 |
|
418 |
|index "{ Class: SmallInteger }" |
|
19545 | 419 |
k newValue oldKeyArray| |
3215 | 420 |
|
5336 | 421 |
(k := aKey) isNil ifTrue:[ |
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
422 |
k := NilEntry |
3215 | 423 |
]. |
5336 | 424 |
|
425 |
index := self findKeyOrNil:k. |
|
426 |
(keyArray basicAt:index) notNil ifTrue:[ |
|
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
427 |
"/ already present |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
428 |
^ valueArray at:index. |
5336 | 429 |
]. |
430 |
"/ a new one |
|
19545 | 431 |
oldKeyArray := keyArray. |
5336 | 432 |
newValue := valueBlock value. |
19545 | 433 |
|
434 |
(keyArray == oldKeyArray and:[(keyArray basicAt:index) isNil]) ifTrue:[ |
|
435 |
"I haven't been changed while executing valueBlock. Do it fast..." |
|
436 |
keyArray basicAt:index put:k. |
|
437 |
valueArray basicAt:index put:newValue. |
|
438 |
tally := tally + 1. |
|
439 |
self possiblyGrow. |
|
440 |
] ifFalse:[ |
|
441 |
"I have been changed while performing the valueBlock" |
|
442 |
"/ self at:k put:newValue. |
|
19740 | 443 |
self error:'Dictionary: inconsistency while performing #at:ifAbsentPut:' mayProceed:true. |
444 |
"/ if you proceed, I will try again... |
|
445 |
^ self at:aKey ifAbsentPut:valueBlock. |
|
19545 | 446 |
]. |
3215 | 447 |
^ newValue |
448 |
||
449 |
" |
|
450 |
|d| |
|
451 |
||
452 |
d := Dictionary new. |
|
453 |
Transcript showCR:(d at:'foo' ifAbsentPut:'bar'). |
|
454 |
Transcript showCR:(d at:'foo2' ifAbsentPut:'bar2'). |
|
455 |
Transcript showCR:(d at:'foo' ifAbsentPut:'barX'). |
|
456 |
Transcript showCR:(d at:'foo2' ifAbsentPut:'bar2X'). |
|
457 |
" |
|
458 |
||
459 |
"Created: / 23.1.1998 / 18:28:26 / cg" |
|
3304
19ee5d1685d8
Make #at:ifAbsentPut: ST80 (and STBroker compatible).
Stefan Vogel <sv@exept.de>
parents:
3252
diff
changeset
|
460 |
"Modified: / 26.2.1998 / 19:10:09 / stefan" |
3215 | 461 |
! |
462 |
||
4871 | 463 |
at:aKey ifPresent:aBlock |
19275 | 464 |
"try to retrieve the value stored at aKey. |
465 |
If there is nothing stored under this key, do nothing. |
|
466 |
Otherwise, evaluate aBlock, passing the retrieved value as argument." |
|
4871 | 467 |
|
468 |
|v| |
|
469 |
||
470 |
v := self at:aKey ifAbsent:[^ nil]. |
|
471 |
^ aBlock value:v. |
|
19275 | 472 |
|
473 |
" |
|
474 |
|d| |
|
475 |
d := Dictionary new. |
|
476 |
d at:#foo put:'yes this is foo'. |
|
477 |
||
478 |
d at:#foo ifPresent:[:val | Transcript showCR:'the value of foo is: ',val]. |
|
479 |
d at:#bar ifPresent:[:val | Transcript showCR:'the value of bar is: ',val]. |
|
480 |
" |
|
4871 | 481 |
! |
482 |
||
1 | 483 |
at:aKey put:anObject |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
484 |
"add the argument anObject under key, aKey to the receiver. |
1221 | 485 |
Return anObject (sigh). |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
486 |
WARNING: do not add elements while iterating over the receiver. |
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
487 |
Iterate over a copy to do this." |
1 | 488 |
|
5336 | 489 |
|k index "{ Class: SmallInteger }"| |
1 | 490 |
|
5336 | 491 |
(k := aKey) isNil ifTrue:[ |
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
492 |
k := NilEntry |
5336 | 493 |
]. |
494 |
||
495 |
index := self findKeyOrNil:k. |
|
496 |
(keyArray basicAt:index) notNil ifTrue:[ |
|
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
497 |
"/ key already present |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
498 |
valueArray basicAt:index put:anObject. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
499 |
^ anObject |
5336 | 500 |
]. |
501 |
"/ a new key |
|
502 |
keyArray basicAt:index put:k. |
|
503 |
valueArray basicAt:index put:anObject. |
|
504 |
tally := tally + 1. |
|
1 | 505 |
|
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
506 |
self possiblyGrow. |
362 | 507 |
^ anObject |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
508 |
|
2328
0fd1d715e5a9
oops - the last one was not good
Claus Gittinger <cg@exept.de>
parents:
2324
diff
changeset
|
509 |
"Modified: 30.1.1997 / 14:59:10 / cg" |
1 | 510 |
! |
511 |
||
19273 | 512 |
at:aKey put:anObject ifPresent:aBlock |
11420 | 513 |
"if the receiver contains an element stored under aKey, |
514 |
retrieve it and evaluate aBlock passing the element as argument, |
|
515 |
return the blocks value. |
|
14318 | 516 |
If not, store aValue under the key. |
11420 | 517 |
Use this with an error-reporting block, to ensure that no keys are reused" |
518 |
||
19273 | 519 |
|k index "{ Class: SmallInteger }"| |
520 |
||
521 |
(k := aKey) isNil ifTrue:[ |
|
522 |
k := NilEntry |
|
523 |
]. |
|
524 |
||
525 |
index := self findKeyOrNil:k. |
|
526 |
(keyArray basicAt:index) notNil ifTrue:[ |
|
527 |
"/ key already present |
|
528 |
^ aBlock value:(valueArray basicAt:index). |
|
529 |
]. |
|
530 |
"/ a new key |
|
531 |
keyArray basicAt:index put:k. |
|
532 |
valueArray basicAt:index put:anObject. |
|
533 |
tally := tally + 1. |
|
534 |
||
535 |
self possiblyGrow. |
|
536 |
^ anObject |
|
11420 | 537 |
|
538 |
" |
|
539 |
|d| |
|
540 |
||
541 |
d := Dictionary new. |
|
19273 | 542 |
d at:'foo' put:1234 ifPresent:[:v| self error: 'duplicate: ', v printString ]. |
543 |
d at:'foo' put:1234 ifPresent:[:v| self halt:'duplicate: ', v printString. 5555 ]. |
|
11420 | 544 |
" |
545 |
! |
|
546 |
||
16902 | 547 |
at:aKey update:aBlock |
548 |
"update the element stored under aKey with the result from |
|
549 |
evaluating aBlock with the previous stored value as argument. |
|
550 |
Report an error if there was no such key initially. |
|
551 |
I.e. this is the same as self at:aKey put:(aBlock value:(self at:aKey)). |
|
552 |
Return the new value stored. |
|
553 |
This is an optimized accessor, which only computes the hash value once." |
|
554 |
||
555 |
|k index "{ Class: SmallInteger }" |
|
556 |
newValue| |
|
557 |
||
558 |
(k := aKey) isNil ifTrue:[ |
|
559 |
k := NilEntry |
|
560 |
]. |
|
561 |
||
562 |
index := self findKeyOrNil:k. |
|
563 |
(keyArray basicAt:index) notNil ifTrue:[ |
|
564 |
"/ key present |
|
565 |
valueArray basicAt:index put:(newValue := aBlock value:(valueArray basicAt:index)). |
|
566 |
^ newValue |
|
567 |
]. |
|
568 |
"/ a new key |
|
569 |
^ self errorKeyNotFound:k. |
|
570 |
||
571 |
" |
|
572 |
|d| |
|
573 |
||
574 |
d := Dictionary new. |
|
575 |
d at:'one' update:[:val | val + 1]. |
|
576 |
" |
|
577 |
||
578 |
" |
|
579 |
|d| |
|
580 |
d := Dictionary new. |
|
581 |
d at:'one' put:0. |
|
582 |
d at:'two' put:0. |
|
583 |
d at:'three' put:0. |
|
584 |
||
585 |
d at:'one' update:[:val | val + 1]. |
|
586 |
d at:'two' update:[:val | val + 1]. |
|
587 |
d at:'three' update:[:val | val + 1]. |
|
588 |
d at:'one' update:[:val | val + 1]. |
|
589 |
d at:'two' update:[:val | val + 1]. |
|
590 |
d |
|
591 |
" |
|
592 |
! |
|
593 |
||
609 | 594 |
keyAtEqualValue:aValue |
595 |
"return the key whose value is equal (i.e. using #= for compare) |
|
596 |
to the argument, nil if none found. |
|
597 |
This is a slow access, since there is no fast reverse mapping. |
|
598 |
NOTICE: |
|
14318 | 599 |
The value is searched using equality compare; |
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
600 |
use #keyAtValue: to compare for identity." |
77 | 601 |
|
609 | 602 |
^ self keyAtEqualValue:aValue ifAbsent:[nil] |
10 | 603 |
! |
604 |
||
609 | 605 |
keyAtEqualValue:aValue ifAbsent:exceptionBlock |
14318 | 606 |
"return the key whose value is equal (i.e. using #= for compare) |
609 | 607 |
to the argument, if not found, return the value of exceptionBlock. |
608 |
This is a slow access, since there is no fast reverse mapping. |
|
609 |
NOTICE: |
|
14318 | 610 |
The value is searched using equality compare; |
611 |
use #keyAtValue:ifAbsent: to compare for identity." |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
612 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
613 |
|idx k| |
54 | 614 |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
615 |
idx := 0. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
616 |
[true] whileTrue:[ |
14318 | 617 |
idx := valueArray indexOf:aValue startingAt:idx+1. |
618 |
idx == 0 ifTrue:[ |
|
619 |
^ exceptionBlock value |
|
620 |
]. |
|
621 |
(k := keyArray at:idx) notNil ifTrue:[ |
|
622 |
k ~~ DeletedEntry ifTrue:[ |
|
623 |
k == NilEntry ifTrue:[ |
|
624 |
^ nil |
|
625 |
]. |
|
626 |
^ k |
|
627 |
]. |
|
628 |
]. |
|
609 | 629 |
]. |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
630 |
"/ NOT REACHED |
54 | 631 |
! |
632 |
||
5336 | 633 |
keyAtIdentityValue:aValue |
345 | 634 |
"return the key whose value is identical (i.e. using #== for compare) |
635 |
to the argument, nil if none found. |
|
77 | 636 |
This is a slow access, since there is no fast reverse mapping. |
357 | 637 |
NOTICE: |
14318 | 638 |
The value is searched using identity compare; |
639 |
use #keyAtEqualValue: to compare for equality." |
|
10 | 640 |
|
5336 | 641 |
^ self keyAtIdentityValue:aValue ifAbsent:[nil] |
10 | 642 |
! |
643 |
||
5336 | 644 |
keyAtIdentityValue:aValue ifAbsent:exceptionBlock |
14318 | 645 |
"return the key whose value is identical (i.e. using #== for compare) |
345 | 646 |
to the argument, if not found, return the value of exceptionBlock. |
357 | 647 |
This is a slow access, since there is no fast reverse mapping. |
648 |
NOTICE: |
|
14318 | 649 |
The value is searched using identity compare; |
650 |
use #keyAtEqualValue:ifAbsent: to compare for equality." |
|
10 | 651 |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
652 |
|idx k| |
359 | 653 |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
654 |
idx := 0. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
655 |
[true] whileTrue:[ |
14318 | 656 |
idx := valueArray identityIndexOf:aValue startingAt:idx+1. |
657 |
idx == 0 ifTrue:[ |
|
658 |
^ exceptionBlock value |
|
659 |
]. |
|
660 |
(k := keyArray at:idx) notNil ifTrue:[ |
|
661 |
k ~~ DeletedEntry ifTrue:[ |
|
662 |
k == NilEntry ifTrue:[ |
|
663 |
^ nil |
|
664 |
]. |
|
665 |
^ k |
|
666 |
]. |
|
667 |
]. |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
668 |
]. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
669 |
"/ NOT REACHED |
357 | 670 |
! |
671 |
||
5336 | 672 |
keyAtValue:aValue |
673 |
"return the key whose value is identical (i.e. using #== for compare) |
|
674 |
to the argument, nil if none found. |
|
675 |
This is a slow access, since there is no fast reverse mapping. |
|
676 |
NOTICE: |
|
14318 | 677 |
The value is searched using identity compare; |
678 |
use #keyAtEqualValue: to compare for equality." |
|
5336 | 679 |
|
680 |
^ self keyAtIdentityValue:aValue ifAbsent:[nil] |
|
681 |
! |
|
682 |
||
683 |
keyAtValue:aValue ifAbsent:exceptionBlock |
|
14318 | 684 |
"return the key whose value is identical (i.e. using #== for compare) |
5336 | 685 |
to the argument, if not found, return the value of exceptionBlock. |
686 |
This is a slow access, since there is no fast reverse mapping. |
|
687 |
NOTICE: |
|
14318 | 688 |
The value is searched using identity compare; |
689 |
use #keyAtEqualValue:ifAbsent: to compare for equality." |
|
5336 | 690 |
|
691 |
^ self keyAtIdentityValue:aValue ifAbsent:exceptionBlock |
|
692 |
! |
|
693 |
||
609 | 694 |
keys |
695 |
"return a collection containing all keys of the receiver" |
|
696 |
||
697 |
|keySet| |
|
357 | 698 |
|
609 | 699 |
keySet := self emptyCollectionForKeys. |
14318 | 700 |
keyArray do:[:key | |
14320 | 701 |
(key notNil and:[key ~~ DeletedEntry]) ifTrue:[ |
702 |
key == NilEntry ifTrue:[ |
|
703 |
keySet add:nil |
|
704 |
] ifFalse:[ |
|
705 |
keySet add:key |
|
706 |
] |
|
707 |
] |
|
609 | 708 |
]. |
709 |
^ keySet |
|
357 | 710 |
! |
711 |
||
609 | 712 |
values |
12668 | 713 |
"return a collection containing all values of the receiver. |
714 |
This is to make value access to an OrderedDictionary compatible with any-Collection" |
|
359 | 715 |
|
609 | 716 |
|aCollection| |
359 | 717 |
|
609 | 718 |
aCollection := OrderedCollection new:valueArray size. |
719 |
self do:[:value| aCollection add:value]. |
|
720 |
^ aCollection |
|
1 | 721 |
! ! |
722 |
||
723 |
!Dictionary methodsFor:'adding & removing'! |
|
724 |
||
725 |
add:anAssociation |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
726 |
"add the argument, anAssociation to the receiver. |
14897 | 727 |
Returns the argument, anAssosciation. |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
728 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
729 |
WARNING: do not add elements while iterating over the receiver. |
14897 | 730 |
Iterate over a copy to do this." |
1 | 731 |
|
732 |
self at:(anAssociation key) put:(anAssociation value). |
|
733 |
^ anAssociation |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
734 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
735 |
"Modified: 1.3.1996 / 21:23:53 / cg" |
1 | 736 |
! |
737 |
||
8434
98ae6daa9aac
Fix #addAll: and #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
8395
diff
changeset
|
738 |
addAll:aCollection |
14318 | 739 |
"ANSI 5.7.2.1: |
8434
98ae6daa9aac
Fix #addAll: and #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
8395
diff
changeset
|
740 |
Message: addAll: dictionary |
98ae6daa9aac
Fix #addAll: and #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
8395
diff
changeset
|
741 |
Synopsis |
14318 | 742 |
Store the elements of dictionary in the receiver at the |
743 |
corresponding keys from dictionary. |
|
8434
98ae6daa9aac
Fix #addAll: and #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
8395
diff
changeset
|
744 |
Definition: <abstractDictionary> |
14318 | 745 |
This message is equivalent to repeatedly sending the #at:put: |
746 |
message to the receiver with each of the keys and elements in |
|
747 |
dictionary in turn. If a key in dictionary is key equivalent |
|
748 |
to a key in the receiver, the associated element in dictionary |
|
749 |
replaces the element in the receiver. |
|
8434
98ae6daa9aac
Fix #addAll: and #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
8395
diff
changeset
|
750 |
|
7750 | 751 |
Returns the argument, aCollection (sigh). |
752 |
||
753 |
WARNING: do not add elements while iterating over the receiver. |
|
14318 | 754 |
Iterate over a copy to do this." |
7750 | 755 |
|
8434
98ae6daa9aac
Fix #addAll: and #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
8395
diff
changeset
|
756 |
|
98ae6daa9aac
Fix #addAll: and #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
8395
diff
changeset
|
757 |
self ~~ aCollection ifTrue:[ |
14318 | 758 |
aCollection isSequenceable ifTrue:[ |
759 |
aCollection do:[:eachPair | |
|
760 |
self at:eachPair key put:eachPair value. |
|
761 |
]. |
|
762 |
] ifFalse:[ |
|
763 |
aCollection keysAndValuesDo:[:eachKey :eachValue | |
|
764 |
self at:eachKey put:eachValue. |
|
765 |
] |
|
766 |
]. |
|
7750 | 767 |
]. |
8434
98ae6daa9aac
Fix #addAll: and #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
8395
diff
changeset
|
768 |
^ aCollection |
7750 | 769 |
|
770 |
" |
|
771 |
|d1 d2| |
|
772 |
||
773 |
d1 := Dictionary new. |
|
774 |
d1 at:1 put:'one'. |
|
775 |
d1 at:2 put:'two'. |
|
776 |
d2 := Dictionary new. |
|
777 |
d2 at:3 put:'three'. |
|
778 |
d2 at:4 put:'four'. |
|
779 |
d1 addAll:d2. |
|
14318 | 780 |
d1. |
7750 | 781 |
" |
782 |
! |
|
783 |
||
2711 | 784 |
addPairsFrom:aSequenceableCollection |
11673 | 785 |
"merge consecutive key-value pairs from aSequenceableCollection into the receiver." |
2711 | 786 |
|
787 |
aSequenceableCollection pairWiseDo:[:key :value | |
|
14318 | 788 |
self at:key put:value. |
2711 | 789 |
] |
790 |
||
7751 | 791 |
" |
792 |
|d1 arr| |
|
793 |
||
794 |
d1 := Dictionary new. |
|
795 |
d1 at:1 put:'one'. |
|
796 |
d1 at:2 put:'two'. |
|
797 |
arr := #(3 'three' 4 'four'). |
|
798 |
d1 addPairsFrom:arr. |
|
14318 | 799 |
d1. |
7751 | 800 |
" |
801 |
||
2711 | 802 |
"Modified: 1.3.1996 / 21:24:03 / cg" |
803 |
! |
|
804 |
||
19813 | 805 |
clearContents |
806 |
"remove all elements from the receiver, but do not resize. |
|
807 |
Returns the receiver." |
|
808 |
||
809 |
keyArray atAllPut:nil. |
|
810 |
valueArray atAllPut:nil. |
|
811 |
tally := 0. |
|
812 |
! |
|
813 |
||
345 | 814 |
declare:key from:aDictionary |
815 |
"if the receiver does not include an association for key, |
|
816 |
take the association from aDictionary and add it to the receiver. |
|
817 |
If aDictionary does not contain such an association, use nil |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
818 |
as the value of the new dictionary. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
819 |
|
9066 | 820 |
Stubidity Notice: |
14318 | 821 |
Incompatibility with #declareAllFrom:, where the other values are |
822 |
defined unconditionally. |
|
9066 | 823 |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
824 |
WARNING: do not add elements while iterating over the receiver. |
14318 | 825 |
Iterate over a copy to do this." |
345 | 826 |
|
827 |
|value| |
|
828 |
||
829 |
(self includesKey:key) ifFalse:[ |
|
14318 | 830 |
value := aDictionary at:key ifAbsent:nil. |
831 |
self at:key put:value. |
|
345 | 832 |
] |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
833 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
834 |
"Modified: 1.3.1996 / 21:24:03 / cg" |
345 | 835 |
! |
836 |
||
16451 | 837 |
declareAll:keys from:aCollectionOrDictionary |
838 |
"declare all keys in the first argument, keys |
|
839 |
from values taken from the second argument, aCollectionOrDictionary. |
|
840 |
If aCollectionOrDictionary is a dictionary, access via the key; |
|
841 |
if it is a sequencable collection, add corresponding values pairwise." |
|
842 |
||
843 |
aCollectionOrDictionary isDictionary ifTrue:[ |
|
844 |
keys do:[:k | self at:k put:(aCollectionOrDictionary at:k) ] |
|
845 |
] ifFalse:[ |
|
846 |
keys with:aCollectionOrDictionary do:[:k :v | self at:k put:v ] |
|
847 |
]. |
|
848 |
||
849 |
" |
|
850 |
|d| |
|
851 |
||
852 |
d := Dictionary new. |
|
853 |
d declareAll:#(a b c) from:#(10 20 30). |
|
854 |
d. |
|
855 |
" |
|
856 |
" |
|
857 |
|d1 d2 d3| |
|
858 |
||
859 |
d1 := Dictionary new. |
|
860 |
d1 declareAll:#(a b c) from:#(10 20 30). |
|
861 |
d2 := Dictionary new. |
|
862 |
d2 declareAll:#( b c d) from:#(100 200 300). |
|
863 |
d3 := Dictionary new. |
|
864 |
d3 declareAll:#(a b c) from:d1. |
|
865 |
d3 declareAll:#(c d) from:d2. |
|
866 |
d3 |
|
867 |
" |
|
868 |
! |
|
869 |
||
9938 | 870 |
declareAllFrom:aDictionaryOrNil |
8434
98ae6daa9aac
Fix #addAll: and #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
8395
diff
changeset
|
871 |
"merge all key-value pairs from aDictionary into the receiver. |
98ae6daa9aac
Fix #addAll: and #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
8395
diff
changeset
|
872 |
|
9938 | 873 |
sigh: |
14318 | 874 |
For compatibility with #declare:from: the behavior should be changed as following: |
875 |
If the receiver already contains a key, the existing value is retained. |
|
876 |
To keep the compatibility with other smalltalks, the semantics of this remains |
|
877 |
as is, and #declareAllNewFrom: was added for convenience. |
|
878 |
See #declareAllNewFrom: which does exactly what this name implies." |
|
2711 | 879 |
|
9938 | 880 |
self ~~ aDictionaryOrNil ifTrue:[ |
14318 | 881 |
aDictionaryOrNil notNil ifTrue:[ |
882 |
aDictionaryOrNil keysAndValuesDo:[:key :value | |
|
883 |
self at:key put:value. |
|
884 |
]. |
|
885 |
] |
|
2711 | 886 |
] |
9938 | 887 |
|
9939 | 888 |
"Modified: / 18-09-2006 / 22:01:12 / cg" |
9938 | 889 |
! |
890 |
||
891 |
declareAllNewFrom:aDictionaryOrNil |
|
892 |
"merge all new key-value pairs from aDictionary into the receiver |
|
893 |
i.e. If the receiver already contains a key, the existing value is retained. |
|
894 |
See also #declareAllFrom:" |
|
895 |
||
896 |
self ~~ aDictionaryOrNil ifTrue:[ |
|
14318 | 897 |
aDictionaryOrNil notNil ifTrue:[ |
898 |
aDictionaryOrNil keysAndValuesDo:[:key :value | |
|
899 |
(self includesKey:key) ifFalse:[ |
|
900 |
self at:key put:value. |
|
901 |
]. |
|
902 |
] |
|
903 |
] |
|
9938 | 904 |
] |
905 |
||
906 |
"Created: / 18-09-2006 / 21:58:54 / cg" |
|
2711 | 907 |
! |
908 |
||
1 | 909 |
remove:oldObject ifAbsent:aBlock |
910 |
"remove oldObject from the collection and return it. |
|
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
911 |
If it was not in the collection return the value of aBlock. |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
912 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
913 |
This is blocked here; you have to use one of |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
914 |
#removeKey:, #saveRemoveKey:, #removeAssociation:, |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
915 |
#removeValue: or #saveRemoveValue:" |
1 | 916 |
|
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
917 |
^ self shouldNotImplement |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
918 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
919 |
"Modified: 1.3.1996 / 21:21:38 / cg" |
1 | 920 |
! |
921 |
||
6053
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
922 |
removeAllKeys:aKeyCollection |
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
923 |
"remove all associations under each key in aKeyCollection from the collection. |
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
924 |
If it was not in the collection report an error. |
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
925 |
|
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
926 |
WARNING: do not remove elements while iterating over the receiver. |
14318 | 927 |
See #saveRemoveKey: to do this." |
6053
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
928 |
|
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
929 |
aKeyCollection do:[:eachKey | |
14318 | 930 |
self removeKey:eachKey ifAbsent:[self errorKeyNotFound:eachKey] |
6053
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
931 |
]. |
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
932 |
! |
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
933 |
|
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
934 |
removeAllKeys:aKeyCollection ifAbsent:aBlock |
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
935 |
"remove all associations under each key in aKeyCollection from the collection. |
15527 | 936 |
If it was not in the collection return the result from evaluating aBlock |
937 |
(invoked for each missing element). |
|
6053
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
938 |
|
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
939 |
WARNING: do not remove elements while iterating over the receiver. |
15527 | 940 |
See #saveRemoveKey: to do this." |
6053
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
941 |
|
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
942 |
aKeyCollection do:[:eachKey | |
15527 | 943 |
self removeKey:eachKey ifAbsent:aBlock |
6053
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
944 |
]. |
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
945 |
! |
a97f27828c08
added #removeKeys: and #removeKeys:ifAbsent: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5865
diff
changeset
|
946 |
|
1 | 947 |
removeAssociation:assoc |
948 |
"remove the association from the collection. |
|
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
949 |
If it was not in the collection report an error. |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
950 |
Only the key is used in the passed argument, and a new |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
951 |
association, for the key and the previously stored value is returned. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
952 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
953 |
WARNING: do not remove elements while iterating over the receiver. |
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
954 |
See #saveRemoveKey: to do this." |
1 | 955 |
|
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
956 |
|key| |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
957 |
|
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
958 |
key := assoc key. |
2897 | 959 |
^ Association key:key value:(self removeKey:key) |
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
960 |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
961 |
"Modified: 1.3.1996 / 21:21:11 / cg" |
1 | 962 |
! |
963 |
||
964 |
removeKey:aKey |
|
965 |
"remove the association under aKey from the collection. |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
966 |
If it was not in the collection report an error. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
967 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
968 |
WARNING: do not remove elements while iterating over the receiver. |
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
969 |
See #saveRemoveKey: to do this." |
1 | 970 |
|
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
971 |
^ self removeKey:aKey ifAbsent:[self errorKeyNotFound:aKey] |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
972 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
973 |
"Modified: 1.3.1996 / 21:21:52 / cg" |
1 | 974 |
! |
975 |
||
976 |
removeKey:aKey ifAbsent:aBlock |
|
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
977 |
"remove the association under aKey from the collection, |
19845 | 978 |
return the value previously stored there. |
14318 | 979 |
If it was not in the collection return the result |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
980 |
from evaluating aBlock. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
981 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
982 |
WARNING: do not remove elements while iterating over the receiver. |
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
983 |
See #saveRemoveKey: to do this." |
1 | 984 |
|
3 | 985 |
|index "{ Class:SmallInteger }" |
14318 | 986 |
"/ next "{ Class:SmallInteger }" |
5336 | 987 |
oldValue k| |
1 | 988 |
|
5336 | 989 |
(k := aKey) isNil ifTrue:[ |
990 |
"/ no longer invalid |
|
991 |
"/ ^ self errorInvalidKey:aKey |
|
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
992 |
k := NilEntry |
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
993 |
]. |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
994 |
|
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
995 |
"/ below, I could have written: |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
996 |
"/ index := self find:aKey ifAbsent:[^ aBlock value] |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
997 |
"/ but the code below is slighlty more efficient, since it avoids |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
998 |
"/ a garbage block creation - thus speeding up the good case. |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
999 |
|
5336 | 1000 |
index := self find:k ifAbsent:0. |
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1001 |
index == 0 ifTrue:[^ aBlock value]. |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1002 |
|
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1003 |
oldValue := valueArray basicAt:index. |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1004 |
|
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1005 |
valueArray basicAt:index put:nil. |
5336 | 1006 |
keyArray basicAt:index put:DeletedEntry. |
77 | 1007 |
|
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1008 |
tally := tally - 1. |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1009 |
tally == 0 ifTrue:[ |
18332 | 1010 |
self initializeForCapacity:0 |
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1011 |
] ifFalse:[ |
5336 | 1012 |
"/ index == keyArray basicSize ifTrue:[ |
1013 |
"/ next := 1 |
|
1014 |
"/ ] ifFalse:[ |
|
1015 |
"/ next := index + 1. |
|
1016 |
"/ ]. |
|
1017 |
"/ (keyArray basicAt:next) notNil ifTrue:[ |
|
1018 |
"/ keyArray basicAt:index put:DeletedEntry |
|
1019 |
"/ ]. |
|
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1020 |
self possiblyShrink |
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1021 |
]. |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1022 |
^ oldValue |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1023 |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1024 |
"Modified: 1.3.1996 / 21:21:01 / cg" |
77 | 1025 |
! |
1026 |
||
5184
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1027 |
removeValue:aValue |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1028 |
"remove (first) the association to aValue from the collection, |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1029 |
return the key under which it was stored previously. |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1030 |
If it was not in the collection, report an error. |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1031 |
The value is searched using equality compare here, |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1032 |
but identity compare in the IdentityDictionary subclass. |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1033 |
|
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1034 |
Notice, this does a linear search through the values and may |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1035 |
therefore be slow for big dictionaries. |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1036 |
|
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1037 |
WARNING: do not remove elements while iterating over the receiver. |
14318 | 1038 |
See #saveRemoveValue: to do this." |
5184
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1039 |
|
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1040 |
^ self removeValue:aValue ifAbsent:[self errorValueNotFound:aValue] |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1041 |
|
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1042 |
" |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1043 |
|d| |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1044 |
|
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1045 |
d := Dictionary new. |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1046 |
d at:1 put:'one'. |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1047 |
d at:2 put:'two'. |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1048 |
d at:3 put:'three'. |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1049 |
d removeValue:'two'. |
14318 | 1050 |
d |
5184
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1051 |
" |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1052 |
! |
cbf20f052178
added #removeValue: - for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
5050
diff
changeset
|
1053 |
|
77 | 1054 |
removeValue:aValue ifAbsent:aBlock |
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1055 |
"remove (first) the association to aValue from the collection, |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1056 |
return the key under which it was stored previously. |
77 | 1057 |
If it was not in the collection return result from evaluating aBlock. |
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1058 |
The value is searched using equality compare here, |
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1059 |
but identity compare in the IdentityDictionary subclass. |
77 | 1060 |
|
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1061 |
Notice, this does a linear search through the values and may |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1062 |
therefore be slow for big dictionaries. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1063 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1064 |
WARNING: do not remove elements while iterating over the receiver. |
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1065 |
See #saveRemoveValue: to do this." |
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1066 |
|
14318 | 1067 |
|next "{ Class:SmallInteger }" |
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1068 |
oldKey| |
77 | 1069 |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1070 |
keyArray keysAndValuesDo:[:index :aKey | |
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1071 |
|idx "{Class:SmallInteger}"| |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1072 |
|
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1073 |
(aKey notNil and:[aKey ~~ DeletedEntry]) ifTrue:[ |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1074 |
idx := index. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1075 |
(self compareSame:(valueArray at:idx) with:aValue) ifTrue:[ |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1076 |
"found it" |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1077 |
valueArray basicAt:idx put:nil. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1078 |
oldKey := keyArray basicAt:idx. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1079 |
oldKey == NilEntry ifTrue:[ |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1080 |
oldKey := nil |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1081 |
]. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1082 |
keyArray basicAt:idx put:nil. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1083 |
tally := tally - 1. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1084 |
tally == 0 ifTrue:[ |
18332 | 1085 |
self initializeForCapacity:0. |
17264
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1086 |
^ oldKey |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1087 |
]. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1088 |
|
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1089 |
idx == keyArray basicSize ifTrue:[ |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1090 |
next := 1 |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1091 |
] ifFalse:[ |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1092 |
next := index + 1. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1093 |
]. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1094 |
(keyArray basicAt:next) notNil ifTrue:[ |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1095 |
keyArray basicAt:idx put:DeletedEntry |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1096 |
]. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1097 |
self possiblyShrink. |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1098 |
^ oldKey |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1099 |
] |
548ea4dc5aa4
renamed the private emptyCheck of Set & Dictionary
Claus Gittinger <cg@exept.de>
parents:
16902
diff
changeset
|
1100 |
] |
77 | 1101 |
]. |
1102 |
^ aBlock value |
|
641
ef3bcf9de54b
return values in remove*** methods fixed (ST-80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1103 |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1104 |
"Modified: 1.3.1996 / 21:22:11 / cg" |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1105 |
! |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1106 |
|
16512 | 1107 |
safeRemoveKey:aKey |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1108 |
"remove the association under aKey from the collection. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1109 |
Return the value previously stored there. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1110 |
If it was not in the collection return nil. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1111 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1112 |
In contrast to #removeKey:, this does not resize the underlying collection |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1113 |
and therefore does NOT rehash & change the elements order. |
18787 | 1114 |
Therefore this can be used while enumerating the receiver, |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1115 |
which is not possible if #removeKey: is used. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1116 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1117 |
WARNING: since no resizing is done, the physical amount of memory used |
16512 | 1118 |
by the container remains the same, although the logical size shrinks. |
18787 | 1119 |
You may want to manually resize the receiver using #possiblyShrink." |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1120 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1121 |
|index "{ Class:SmallInteger }" |
14318 | 1122 |
next "{ Class:SmallInteger }" |
5336 | 1123 |
oldValue k| |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1124 |
|
5336 | 1125 |
(k := aKey) isNil ifTrue:[ |
16512 | 1126 |
k := NilEntry |
5336 | 1127 |
]. |
1128 |
"/ aKey isNil ifTrue:[^ nil]. |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1129 |
|
5336 | 1130 |
index := self find:k ifAbsent:0. |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1131 |
index == 0 ifTrue:[^ nil]. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1132 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1133 |
oldValue := valueArray basicAt:index. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1134 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1135 |
valueArray basicAt:index put:nil. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1136 |
keyArray basicAt:index put:nil. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1137 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1138 |
tally := tally - 1. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1139 |
tally ~~ 0 ifTrue:[ |
16512 | 1140 |
index == keyArray basicSize ifTrue:[ |
1141 |
next := 1 |
|
1142 |
] ifFalse:[ |
|
1143 |
next := index + 1. |
|
1144 |
]. |
|
1145 |
(keyArray basicAt:next) notNil ifTrue:[ |
|
1146 |
keyArray basicAt:index put:DeletedEntry |
|
1147 |
]. |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1148 |
]. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1149 |
^ oldValue |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1150 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1151 |
"does NOT work: |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1152 |
|
16512 | 1153 |
|d| |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1154 |
|
16512 | 1155 |
d := Dictionary new. |
1156 |
d at:'one' put:1. |
|
1157 |
d at:'two' put:2. |
|
1158 |
d at:'three' put:3. |
|
1159 |
d at:'four' put:4. |
|
1160 |
d at:'five' put:5. |
|
1161 |
d at:'six' put:6. |
|
1162 |
d at:'seven' put:7. |
|
1163 |
d at:'eight' put:8. |
|
1164 |
d at:'nine' put:9. |
|
1165 |
d keysAndValuesDo:[:k :v | |
|
1166 |
v odd ifTrue:[ |
|
1167 |
d removeKey:k |
|
1168 |
] |
|
1169 |
]. |
|
1170 |
d inspect |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1171 |
" |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1172 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1173 |
"DOES work: |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1174 |
|
16512 | 1175 |
|d| |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1176 |
|
16512 | 1177 |
d := Dictionary new. |
1178 |
d at:'one' put:1. |
|
1179 |
d at:'two' put:2. |
|
1180 |
d at:'three' put:3. |
|
1181 |
d at:'four' put:4. |
|
1182 |
d at:'five' put:5. |
|
1183 |
d at:'six' put:6. |
|
1184 |
d at:'seven' put:7. |
|
1185 |
d at:'eight' put:8. |
|
1186 |
d at:'nine' put:9. |
|
1187 |
d keysAndValuesDo:[:k :v | |
|
1188 |
v odd ifTrue:[ |
|
1189 |
d safeRemoveKey:k |
|
1190 |
] |
|
1191 |
]. |
|
1192 |
d inspect |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1193 |
" |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1194 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1195 |
"Created: 1.3.1996 / 21:14:42 / cg" |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1196 |
"Modified: 1.3.1996 / 21:14:53 / cg" |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1197 |
! |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1198 |
|
16512 | 1199 |
safeRemoveValue:aValue |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1200 |
"remove the (first) association to aValue from the collection, |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1201 |
return the key under which it was stored previously. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1202 |
If it was not in the collection return nil. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1203 |
The value is searched using equality compare here, |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1204 |
but identity compare in the IdentityDictionary subclass. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1205 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1206 |
In contrast to #removeValue:, this does not resize the underlying collection |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1207 |
and therefore does NOT rehash & change the elements order. |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1208 |
Therefore, this can be used while enumerating the receiver, |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1209 |
which is not possible if #removeValue: is used. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1210 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1211 |
WARNING: since no resizing is done, the physical amount of memory used |
16512 | 1212 |
by the container remains the same, although the logical size shrinks. |
18787 | 1213 |
You may want to manually resize the receiver using #possiblyShrink." |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1214 |
|
14318 | 1215 |
|next "{ Class:SmallInteger }" |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1216 |
oldKey| |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1217 |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1218 |
keyArray keysAndValuesDo:[:index :aKey | |
16512 | 1219 |
|idx "{Class:SmallInteger}"| |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1220 |
|
16512 | 1221 |
(aKey notNil and:[aKey ~~ DeletedEntry]) ifTrue:[ |
1222 |
idx := index. |
|
1223 |
(self compareSame:(valueArray at:idx) with:aValue) ifTrue:[ |
|
1224 |
"found it" |
|
1225 |
valueArray basicAt:idx put:nil. |
|
1226 |
oldKey := keyArray basicAt:idx. |
|
1227 |
oldKey == NilEntry ifTrue:[ |
|
1228 |
oldKey := nil |
|
1229 |
]. |
|
1230 |
keyArray basicAt:idx put:nil. |
|
1231 |
tally := tally - 1. |
|
1232 |
tally ~~ 0 ifTrue:[ |
|
1233 |
idx == keyArray basicSize ifTrue:[ |
|
1234 |
next := 1 |
|
1235 |
] ifFalse:[ |
|
1236 |
next := index + 1. |
|
1237 |
]. |
|
1238 |
(keyArray basicAt:next) notNil ifTrue:[ |
|
1239 |
keyArray basicAt:idx put:DeletedEntry |
|
1240 |
]. |
|
1241 |
]. |
|
1242 |
^ oldKey |
|
1243 |
] |
|
1244 |
] |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1245 |
]. |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1246 |
^ aValue |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1247 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1248 |
"does NOT work: |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1249 |
|
16512 | 1250 |
|d| |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1251 |
|
16512 | 1252 |
d := Dictionary new. |
1253 |
d at:'one' put:1. |
|
1254 |
d at:'two' put:2. |
|
1255 |
d at:'three' put:3. |
|
1256 |
d at:'four' put:4. |
|
1257 |
d at:'five' put:5. |
|
1258 |
d at:'six' put:6. |
|
1259 |
d at:'seven' put:7. |
|
1260 |
d at:'eight' put:8. |
|
1261 |
d at:'nine' put:9. |
|
1262 |
d keysAndValuesDo:[:k :v | |
|
1263 |
v odd ifTrue:[ |
|
1264 |
d removeValue:v ifAbsent:nil |
|
1265 |
] |
|
1266 |
]. |
|
1267 |
d inspect |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1268 |
" |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1269 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1270 |
"DOES work: |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1271 |
|
16512 | 1272 |
|d| |
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1273 |
|
16512 | 1274 |
d := Dictionary new. |
1275 |
d at:'one' put:1. |
|
1276 |
d at:'two' put:2. |
|
1277 |
d at:'three' put:3. |
|
1278 |
d at:'four' put:4. |
|
1279 |
d at:'five' put:5. |
|
1280 |
d at:'six' put:6. |
|
1281 |
d at:'seven' put:7. |
|
1282 |
d at:'eight' put:8. |
|
1283 |
d at:'nine' put:9. |
|
1284 |
d keysAndValuesDo:[:k :v | |
|
1285 |
v odd ifTrue:[ |
|
1286 |
d safeRemoveValue:v |
|
1287 |
] |
|
1288 |
]. |
|
1289 |
d inspect |
|
1053
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1290 |
" |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1291 |
|
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1292 |
"Created: 1.3.1996 / 21:17:10 / cg" |
ac1ea83233e6
added saveRemoveKey:/saveRemoveValue: & commentaries
Claus Gittinger <cg@exept.de>
parents:
641
diff
changeset
|
1293 |
"Modified: 1.3.1996 / 21:23:04 / cg" |
16512 | 1294 |
! |
1295 |
||
1296 |
saveRemoveKey:aKey |
|
1297 |
<resource: #obsolete> |
|
1298 |
"bad spelling - kept for backward compatibility (2014-06-04)" |
|
1299 |
||
1300 |
^ self safeRemoveKey:aKey. |
|
1301 |
! |
|
1302 |
||
1303 |
saveRemoveValue:aValue |
|
1304 |
<resource: #obsolete> |
|
1305 |
"bad spelling - kept for backward compatibility (2014-06-04)" |
|
1306 |
||
1307 |
^ self safeRemoveValue:aValue. |
|
1 | 1308 |
! ! |
1309 |
||
5279 | 1310 |
!Dictionary methodsFor:'comparing'! |
1311 |
||
1312 |
= aCollection |
|
14318 | 1313 |
"return true, if the argument is a Dictionary containing the same |
5279 | 1314 |
key-value pairs as I do" |
1315 |
||
1316 |
aCollection species == self species ifFalse:[^ false]. |
|
1317 |
aCollection size == self size ifFalse:[^ false]. |
|
1318 |
"/ all of of my key-value associations must be in the other collection ... |
|
1319 |
self keysAndValuesDo:[:key :value | |
|
14318 | 1320 |
((aCollection at:key ifAbsent:[^ false]) = value) ifFalse:[^ false] |
5279 | 1321 |
]. |
1322 |
^ true |
|
1323 |
||
1324 |
" |
|
1325 |
|d1 d2| |
|
1326 |
||
1327 |
d1 := Dictionary new. |
|
1328 |
d2 := Dictionary new. |
|
1329 |
d1 at:1 put:'one'. |
|
1330 |
d1 at:'one' put:1. |
|
1331 |
d1 at:2 put:#two. |
|
1332 |
d1 at:'two' put:2. |
|
1333 |
||
1334 |
d2 at:1 put:'one'. |
|
1335 |
d2 at:'one' put:1. |
|
1336 |
d2 at:2 put:#two. |
|
1337 |
d2 at:'two' put:2. |
|
14318 | 1338 |
d1 = d2 |
5279 | 1339 |
" |
1340 |
||
1341 |
" |
|
1342 |
|d1 d2| |
|
1343 |
||
1344 |
d1 := Dictionary new. |
|
1345 |
d2 := Dictionary new. |
|
1346 |
d1 at:1 put:'uno'. |
|
1347 |
d1 at:'one' put:1. |
|
1348 |
d1 at:2 put:#two. |
|
1349 |
d1 at:'two' put:2. |
|
1350 |
||
1351 |
d2 at:1 put:'one'. |
|
1352 |
d2 at:'one' put:1. |
|
1353 |
d2 at:2 put:#two. |
|
1354 |
d2 at:'two' put:2. |
|
14318 | 1355 |
d1 = d2 |
5279 | 1356 |
" |
1357 |
||
1358 |
" |
|
1359 |
|d1 d2| |
|
1360 |
||
1361 |
d1 := Dictionary new. |
|
1362 |
d2 := Dictionary new. |
|
1363 |
d1 at:10 put:'one'. |
|
1364 |
d1 at:'one' put:1. |
|
1365 |
d1 at:2 put:#two. |
|
1366 |
d1 at:'two' put:2. |
|
1367 |
||
1368 |
d2 at:1 put:'one'. |
|
1369 |
d2 at:'one' put:1. |
|
1370 |
d2 at:2 put:#two. |
|
1371 |
d2 at:'two' put:2. |
|
14318 | 1372 |
d1 = d2 |
5279 | 1373 |
" |
1374 |
||
1375 |
||
1376 |
||
1377 |
! ! |
|
1378 |
||
3252
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1379 |
!Dictionary methodsFor:'converting'! |
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1380 |
|
7906 | 1381 |
asDictionary |
1382 |
^ self |
|
1383 |
! |
|
1384 |
||
14997 | 1385 |
asNewDictionary |
1386 |
"return myself as an unique new dictionary" |
|
1387 |
||
1388 |
^ self copy |
|
1389 |
! |
|
1390 |
||
14271 | 1391 |
associationsOrderedBy:aCollectionOfKeys |
1392 |
"return an OrderedCollection of my key-value pairs, ordered by the given key list" |
|
1393 |
||
1394 |
self assert:(aCollectionOfKeys size == self size). |
|
1395 |
^ aCollectionOfKeys collect:[:eachKey | eachKey -> (self at:eachKey) ] as: OrderedCollection |
|
1396 |
||
1397 |
" |
|
1398 |
|d| |
|
1399 |
||
1400 |
d := Dictionary new. |
|
1401 |
d at:'zzz' put:3. |
|
1402 |
d at:'aaa' put:1. |
|
1403 |
d at:'eee' put:2. |
|
1404 |
d. |
|
14318 | 1405 |
d valuesOrderedBy:#('aaa' 'eee' 'zzz'). |
1406 |
d associationsOrderedBy:#('aaa' 'eee' 'zzz'). |
|
14271 | 1407 |
" |
1408 |
||
1409 |
"Created: / 31-07-2012 / 17:32:34 / cg" |
|
1410 |
! |
|
1411 |
||
3252
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1412 |
fromLiteralArrayEncoding:encoding |
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1413 |
"read my values from an encoding. |
14318 | 1414 |
The encoding is supposed to be of the form: |
1415 |
(Dictionary key1 val1 ... keyN valN)" |
|
3252
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1416 |
|
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1417 |
2 to:encoding size by:2 do:[:i | |
14318 | 1418 |
|key val| |
3252
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1419 |
|
14318 | 1420 |
key := encoding at:i. |
1421 |
val := encoding at:i+1. |
|
1422 |
self at:key put:val |
|
3252
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1423 |
]. |
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1424 |
|
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1425 |
" |
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1426 |
Dictionary new fromLiteralArrayEncoding:#(Dictionary 'hello' 'world' 1 'foo') |
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1427 |
" |
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1428 |
|
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1429 |
"Created: / 30.1.1998 / 04:30:47 / cg" |
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1430 |
! |
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1431 |
|
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1432 |
literalArrayEncoding |
9413 | 1433 |
|literalArrray idx| |
3252
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1434 |
|
9413 | 1435 |
literalArrray := Array new:(self size * 2)+1. |
1436 |
literalArrray at:1 put:self class name. |
|
1437 |
idx := 2. |
|
1438 |
self keysAndValuesDo:[:eachKey :eachValue | |
|
14318 | 1439 |
literalArrray |
1440 |
at:idx put:eachKey literalArrayEncoding; |
|
1441 |
at:idx+1 put:eachValue literalArrayEncoding. |
|
1442 |
idx := idx + 2. |
|
3252
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1443 |
]. |
9413 | 1444 |
^ literalArrray |
1445 |
||
1446 |
" |
|
1447 |
|dict| |
|
3252
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1448 |
|
9413 | 1449 |
dict := Dictionary new. |
1450 |
dict at:1 put:'bla'. |
|
1451 |
dict at:'fasel' put:#[1 2 3 4]. |
|
1452 |
dict literalArrayEncoding |
|
1453 |
" |
|
14271 | 1454 |
! |
1455 |
||
1456 |
valuesOrderedBy:aCollectionOfKeys |
|
1457 |
"return an OrderedCollection of my values, ordered by the given key list" |
|
1458 |
||
1459 |
self assert:(aCollectionOfKeys size == self size). |
|
1460 |
^ aCollectionOfKeys collect:[:eachKey | self at:eachKey ] as: OrderedCollection |
|
1461 |
||
1462 |
"Created: / 31-07-2012 / 17:33:12 / cg" |
|
3252
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1463 |
! ! |
da066eafc2c5
added literalArrayEncoding support
Claus Gittinger <cg@exept.de>
parents:
3215
diff
changeset
|
1464 |
|
155 | 1465 |
!Dictionary methodsFor:'copying'! |
1466 |
||
11909 | 1467 |
, anotherDictionaryOrAssociation |
1468 |
"return a new dictionary containing a merged set of associations. |
|
1469 |
If anotherDictionaryOrAssociation includes any of the receiver's keys, |
|
14318 | 1470 |
the value from anotherDictionaryOrAssociation will be placed into the |
11909 | 1471 |
returned result." |
9066 | 1472 |
|
1473 |
|newDictionary| |
|
1474 |
||
11909 | 1475 |
newDictionary := self copy. |
1476 |
newDictionary declareAllFrom:anotherDictionaryOrAssociation. |
|
9066 | 1477 |
^ newDictionary |
11909 | 1478 |
|
1479 |
" |
|
1480 |
|d1 d2| |
|
1481 |
||
1482 |
d1 := Dictionary new. |
|
1483 |
d1 at:#a put:'aaa'. |
|
1484 |
d1 at:#b put:'bbb'. |
|
1485 |
||
1486 |
d2 := Dictionary new. |
|
1487 |
d2 at:#b put:'bbbb'. |
|
1488 |
d2 at:#c put:'ccc'. |
|
1489 |
||
1490 |
d1 , d2 |
|
1491 |
" |
|
1492 |
" |
|
1493 |
|d1 d2| |
|
1494 |
||
1495 |
d1 := Dictionary new. |
|
1496 |
d1 at:#a put:'aaa'. |
|
1497 |
d1 at:#b put:'bbb'. |
|
1498 |
d2 := d1 , (#c -> 'ccc'). |
|
1499 |
d2 |
|
1500 |
" |
|
9066 | 1501 |
! |
1502 |
||
155 | 1503 |
postCopy |
1504 |
"have to copy the valueArray too" |
|
1505 |
||
1506 |
super postCopy. |
|
1507 |
valueArray := valueArray shallowCopy |
|
1508 |
! ! |
|
1509 |
||
217 | 1510 |
!Dictionary methodsFor:'enumerating'! |
1 | 1511 |
|
1512 |
allKeysDo:aBlock |
|
302 | 1513 |
"perform the block for all keys in the collection. |
1514 |
Obsolete: use keysDo: for ST-80 compatibility." |
|
1 | 1515 |
|
5865 | 1516 |
<resource:#obsolete> |
1517 |
||
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1518 |
self obsoleteMethodWarning:'please use #keysDo:'. |
155 | 1519 |
^ super do:aBlock |
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1520 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1521 |
"Modified: 20.4.1996 / 11:22:01 / cg" |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1522 |
! |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1523 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1524 |
associationsCollect:aBlock |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1525 |
"for each key-value pair in the receiver, evaluate the argument, aBlock |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1526 |
and return a collection with the results. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1527 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1528 |
See also: |
14318 | 1529 |
#keysAndValuesCollect: (which passes separate keys & values) |
1530 |
#collect: (which only passes values) |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1531 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1532 |
This is much like #keysAndValuesCollect:, but aBlock gets the |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1533 |
key and value as a single association argument. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1534 |
#keysAndValuesCollect: and is a bit faster therefore (no intermediate objects). |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1535 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1536 |
WARNING: do not add/remove elements while iterating over the receiver. |
14318 | 1537 |
Iterate over a copy to do this." |
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1538 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1539 |
|newCollection| |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1540 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1541 |
newCollection := OrderedCollection new. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1542 |
self keysAndValuesDo:[:key :value | |
14318 | 1543 |
newCollection add:(aBlock value:(Association key:key value:value)) |
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1544 |
]. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1545 |
^ newCollection |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1546 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1547 |
" |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1548 |
|ages| |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1549 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1550 |
ages := Dictionary new. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1551 |
ages at:'cg' put:37. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1552 |
ages at:'ca' put:33. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1553 |
ages at:'sv' put:36. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1554 |
ages at:'tk' put:28. |
14318 | 1555 |
ages associationsCollect:[:assoc | |
1556 |
assoc key , '''s age is ' , assoc value printString] |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1557 |
" |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1558 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1559 |
"Modified: 20.4.1996 / 11:31:27 / cg" |
1 | 1560 |
! |
1561 |
||
1562 |
associationsDo:aBlock |
|
1056 | 1563 |
"perform the block for all associations in the collection. |
1564 |
||
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1565 |
See also: |
14318 | 1566 |
#do: (which passes values to its block) |
1567 |
#keysDo: (which passes only keys to its block) |
|
1568 |
#keysAndValuesDo: (which passes keys&values) |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1569 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1570 |
This is much like #keysAndValuesDo:, but aBlock gets the |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1571 |
key and value as a single association argument. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1572 |
#keysAndValuesDo: and is a bit faster therefore (no intermediate objects). |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1573 |
|
1056 | 1574 |
WARNING: do not add/remove elements while iterating over the receiver. |
14318 | 1575 |
Iterate over a copy to do this." |
1 | 1576 |
|
38 | 1577 |
|key n "{ Class: SmallInteger }"| |
1 | 1578 |
|
1579 |
tally == 0 ifTrue:[^ self]. |
|
38 | 1580 |
n := keyArray basicSize. |
1581 |
1 to:n do:[:index | |
|
14318 | 1582 |
key := keyArray basicAt:index. |
1583 |
(key notNil and:[key ~~ DeletedEntry]) ifTrue:[ |
|
1584 |
key == NilEntry ifTrue:[ |
|
1585 |
key := nil |
|
1586 |
]. |
|
1587 |
aBlock value:(Association key:key value:(valueArray basicAt:index)) |
|
1588 |
] |
|
1 | 1589 |
] |
1056 | 1590 |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1591 |
"Modified: 20.4.1996 / 11:31:39 / cg" |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1592 |
! |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1593 |
|
13721
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1594 |
associationsDo:aBlock separatedBy:sepBlock |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1595 |
"perform the block for all associations in the collection. |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1596 |
|
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1597 |
See also: |
14318 | 1598 |
#do: (which passes values to its block) |
1599 |
#keysDo: (which passes only keys to its block) |
|
1600 |
#keysAndValuesDo: (which passes keys&values) |
|
13721
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1601 |
|
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1602 |
This is much like #keysAndValuesDo:, but aBlock gets the |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1603 |
key and value as a single association argument. |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1604 |
#keysAndValuesDo: and is a bit faster therefore (no intermediate objects). |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1605 |
|
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1606 |
WARNING: do not add/remove elements while iterating over the receiver. |
14318 | 1607 |
Iterate over a copy to do this." |
13721
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1608 |
|
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1609 |
|key n "{ Class: SmallInteger }" |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1610 |
first| |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1611 |
|
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1612 |
tally == 0 ifTrue:[^ self]. |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1613 |
|
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1614 |
first := true. |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1615 |
n := keyArray basicSize. |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1616 |
1 to:n do:[:index | |
14318 | 1617 |
key := keyArray basicAt:index. |
1618 |
(key notNil and:[key ~~ DeletedEntry]) ifTrue:[ |
|
1619 |
key == NilEntry ifTrue:[ |
|
1620 |
key := nil |
|
1621 |
]. |
|
1622 |
first ifTrue:[ |
|
1623 |
first := false. |
|
1624 |
] ifFalse:[ |
|
1625 |
sepBlock value |
|
1626 |
]. |
|
1627 |
aBlock value:(Association key:key value:(valueArray basicAt:index)) |
|
1628 |
] |
|
13721
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1629 |
] |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1630 |
|
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1631 |
"Modified: / 20-04-1996 / 11:31:39 / cg" |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1632 |
"Created: / 23-09-2011 / 14:07:43 / cg" |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1633 |
! |
733cce16b968
added: #associationsDo:separatedBy:
Claus Gittinger <cg@exept.de>
parents:
13328
diff
changeset
|
1634 |
|
2425
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1635 |
associationsReverseDo:aBlock |
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1636 |
"perform the block for all associations in the collection. |
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1637 |
Since dictionary does not define any order of its elements, |
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1638 |
this is the same as #associationsDo: here. |
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1639 |
Provided for protocol compatibility with OrderedDictionary" |
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1640 |
|
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1641 |
^ self associationsDo:aBlock |
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1642 |
|
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1643 |
"Created: 28.2.1997 / 16:08:52 / cg" |
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1644 |
! |
3c23ae3de6d6
added #associationsReverseDo: for OD compatibility
Claus Gittinger <cg@exept.de>
parents:
2328
diff
changeset
|
1645 |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1646 |
associationsSelect:aBlock |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1647 |
"return a new collection with all elements from the receiver, for which |
14318 | 1648 |
the argument aBlock evaluates to true. |
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1649 |
The block gets keys and values as an association argument. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1650 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1651 |
See also: #keysAndValuesSelect: (which is slightly faster), |
14318 | 1652 |
#select: (which only passes the value) |
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1653 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1654 |
This is much like #keysAndValuesSelect:, but aBlock gets the |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1655 |
key and value as a single association argument. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1656 |
#keysAndValuesSelect: and is a bit faster therefore (no intermediate objects). |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1657 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1658 |
WARNING: do not add/remove elements while iterating over the receiver. |
14318 | 1659 |
Iterate over a copy to do this." |
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1660 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1661 |
|newCollection| |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1662 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1663 |
newCollection := self species new. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1664 |
self keysAndValuesDo:[:key :value | |
14318 | 1665 |
(aBlock value:(Association key:key value:value)) ifTrue:[ |
1666 |
newCollection at:key put:value |
|
1667 |
] |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1668 |
]. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1669 |
^ newCollection |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1670 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1671 |
" |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1672 |
|ages| |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1673 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1674 |
ages := Dictionary new. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1675 |
ages at:'cg' put:37. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1676 |
ages at:'ca' put:33. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1677 |
ages at:'sv' put:36. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1678 |
ages at:'tk' put:28. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1679 |
|
14318 | 1680 |
ages associationsSelect:[:assoc | |
1681 |
(assoc key startsWith:'c') or:[assoc value < 30]]. |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1682 |
" |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1683 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1684 |
"Modified: 20.4.1996 / 11:31:15 / cg" |
1 | 1685 |
! |
1686 |
||
609 | 1687 |
collect:aBlock |
1688 |
"for each element in the receiver, evaluate the argument, aBlock |
|
1056 | 1689 |
and return a Bag with the results. |
1690 |
||
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1691 |
See also: |
14318 | 1692 |
#associationsCollect: (which passes key-value associations) |
1693 |
#keysAndValuesCollect: (which passes keys & values separately) |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1694 |
|
1056 | 1695 |
WARNING: do not add/remove elements while iterating over the receiver. |
14318 | 1696 |
Iterate over a copy to do this." |
609 | 1697 |
|
1698 |
|newCollection| |
|
1699 |
||
1700 |
newCollection := Bag new. |
|
1701 |
self do:[:each | |
|
14318 | 1702 |
newCollection add:(aBlock value:each) |
609 | 1703 |
]. |
1704 |
^ newCollection |
|
1056 | 1705 |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1706 |
"Modified: 20.4.1996 / 11:29:58 / cg" |
609 | 1707 |
! |
1708 |
||
1 | 1709 |
do:aBlock |
1056 | 1710 |
"perform the block for all values in the collection. |
1711 |
||
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1712 |
See also: |
14318 | 1713 |
#associationsDo: (which passes key-value associations) |
1714 |
#keysAndValuesDo: (which passes keys & values separately) |
|
1715 |
#keysDo: (which passes keys only) |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1716 |
|
1056 | 1717 |
WARNING: do not add/remove elements while iterating over the receiver. |
14318 | 1718 |
Iterate over a copy to do this." |
1 | 1719 |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1720 |
|key n "{ Class: SmallInteger }" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1721 |
deletedEntry| |
1 | 1722 |
|
1723 |
tally == 0 ifTrue:[^ self]. |
|
38 | 1724 |
n := keyArray basicSize. |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1725 |
deletedEntry := DeletedEntry. |
38 | 1726 |
1 to:n do:[:index | |
14318 | 1727 |
key := keyArray basicAt:index. |
1728 |
(key notNil and:[key ~~ deletedEntry]) ifTrue:[ |
|
1729 |
aBlock value:(valueArray basicAt:index) |
|
1730 |
]. |
|
1 | 1731 |
] |
1056 | 1732 |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1733 |
"Modified: 20.4.1996 / 11:32:11 / cg" |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1734 |
! |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1735 |
|
3 | 1736 |
keysAndValuesDo:aTwoArgBlock |
1737 |
"evaluate the argument, aBlock for every element in the collection, |
|
1056 | 1738 |
passing both key and element as arguments. |
1739 |
||
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1740 |
See also: |
14318 | 1741 |
#associationsDo: (which passes keys->value pairs) |
1742 |
#do: (which only passes values) |
|
1743 |
#keysDo: (which only passes keys) |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1744 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1745 |
This is much like #associationsDo:, but aBlock gets the |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1746 |
key and value as two separate arguments. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1747 |
#associationsDo: is a bit slower. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1748 |
|
1056 | 1749 |
WARNING: do not add/remove elements while iterating over the receiver. |
14318 | 1750 |
Iterate over a copy to do this." |
3 | 1751 |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1752 |
|key n "{ Class: SmallInteger }" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1753 |
deletedEntry| |
3 | 1754 |
|
1755 |
tally == 0 ifTrue:[^ self]. |
|
38 | 1756 |
n := keyArray basicSize. |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1757 |
deletedEntry := DeletedEntry. |
38 | 1758 |
1 to:n do:[:index | |
14318 | 1759 |
key := keyArray basicAt:index. |
1760 |
(key notNil and:[key ~~ deletedEntry]) ifTrue:[ |
|
1761 |
key == NilEntry ifTrue:[ |
|
1762 |
key := nil |
|
1763 |
]. |
|
1764 |
aTwoArgBlock value:key value:(valueArray basicAt:index) |
|
1765 |
]. |
|
3 | 1766 |
] |
1056 | 1767 |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1768 |
"Modified: 20.4.1996 / 11:33:42 / cg" |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1769 |
! |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1770 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1771 |
keysAndValuesSelect:aBlock |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1772 |
"return a new collection with all elements from the receiver, for which |
14318 | 1773 |
the argument aBlock evaluates to true. |
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1774 |
The block gets keys and values as separate arguments. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1775 |
|
14318 | 1776 |
See also: |
1777 |
#associationsSelect: (which passes key-value pairs), |
|
1778 |
#keysSelect: (which passes key values), |
|
1779 |
#select: (which only passes the value) |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1780 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1781 |
This is much like #associationsSelect:, but aBlock gets the |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1782 |
key and value as two separate arguments. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1783 |
#associationsSelect: is a bit slower. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1784 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1785 |
WARNING: do not add/remove elements while iterating over the receiver. |
14318 | 1786 |
Iterate over a copy to do this." |
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1787 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1788 |
|newCollection| |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1789 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1790 |
newCollection := self species new. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1791 |
self keysAndValuesDo:[:key :value | |
14318 | 1792 |
(aBlock value:key value:value) ifTrue:[ |
1793 |
newCollection at:key put:value |
|
1794 |
] |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1795 |
]. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1796 |
^ newCollection |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1797 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1798 |
" |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1799 |
|ages| |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1800 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1801 |
ages := Dictionary new. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1802 |
ages at:'cg' put:37. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1803 |
ages at:'ca' put:33. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1804 |
ages at:'sv' put:36. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1805 |
ages at:'tk' put:28. |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1806 |
|
14318 | 1807 |
ages keysAndValuesSelect:[:name :age | |
1808 |
(name startsWith:'c') or:[age < 30]]. |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1809 |
" |
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1810 |
|
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1811 |
"Modified: 20.4.1996 / 11:34:29 / cg" |
3 | 1812 |
! |
1813 |
||
609 | 1814 |
keysDo:aBlock |
13044 | 1815 |
"evaluate the argument, aBlock for every key in the collection. |
1056 | 1816 |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1817 |
See also: |
14318 | 1818 |
#associationsDo: (which passes key-value associations) |
1819 |
#keysAndValuesDo: (which passes keys & values separately) |
|
1820 |
#do: (which passes values only) |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1821 |
|
1056 | 1822 |
WARNING: do not add/remove elements while iterating over the receiver. |
14318 | 1823 |
Iterate over a copy to do this." |
1 | 1824 |
|
5336 | 1825 |
|sz "{ Class: SmallInteger }" |
1826 |
key| |
|
1056 | 1827 |
|
5336 | 1828 |
sz := keyArray size. |
1829 |
1 to:sz do:[:index | |
|
14318 | 1830 |
key := keyArray at:index. |
1831 |
(key notNil and:[key ~~ DeletedEntry]) ifTrue:[ |
|
1832 |
key == NilEntry ifTrue:[ |
|
1833 |
key := nil |
|
1834 |
]. |
|
1835 |
aBlock value:key |
|
1836 |
] |
|
5336 | 1837 |
] |
13044 | 1838 |
|
1839 |
"Modified: / 24-08-2010 / 10:13:58 / cg" |
|
1 | 1840 |
! |
1841 |
||
11430 | 1842 |
keysSelect:aBlock |
1843 |
"return a new collection with all elements from the receiver, for which |
|
14318 | 1844 |
the argument aBlock evaluates to true. |
11430 | 1845 |
The block gets the individual keys as its single argument. |
1846 |
||
14318 | 1847 |
See also: |
1848 |
#associationsSelect: (which passes key->value associations), |
|
1849 |
#keysAndValuesSelect: (which passes key & value args) |
|
1850 |
#select: (which passes values as arg), |
|
11430 | 1851 |
|
1852 |
WARNING: do not add/remove elements while iterating over the receiver. |
|
14318 | 1853 |
Iterate over a copy to do this." |
11430 | 1854 |
|
1855 |
|newCollection| |
|
1856 |
||
1857 |
newCollection := self species new. |
|
1858 |
self keysAndValuesDo:[:key :value | |
|
14318 | 1859 |
(aBlock value:key) ifTrue:[ |
1860 |
newCollection at:key put:value |
|
1861 |
] |
|
11430 | 1862 |
]. |
1863 |
^ newCollection |
|
1864 |
||
1865 |
" |
|
1866 |
|d| |
|
1867 |
||
1868 |
d := Dictionary new. |
|
1869 |
d at:#foo put:#bar. |
|
1870 |
d at:#bar put:#baz. |
|
1871 |
d at:#baz put:#foo. |
|
1872 |
||
1873 |
d select:[:el | el startsWith:'b']. |
|
1874 |
" |
|
1875 |
||
1876 |
"Modified: / 12-10-2006 / 11:24:06 / cg" |
|
1877 |
! |
|
1878 |
||
1 | 1879 |
select:aBlock |
1880 |
"return a new collection with all elements from the receiver, for which |
|
14318 | 1881 |
the argument aBlock evaluates to true. |
10077 | 1882 |
The block gets the individual values as its single argument. |
1056 | 1883 |
|
14318 | 1884 |
See also: |
1885 |
#associationsSelect: (which passes key->value associations), |
|
1886 |
#keysAndValuesSelect: (which passes key & value args) |
|
1887 |
#keysSelect: (which passes key values), |
|
1233
21452b1c61eb
more enumaration variations & commentary
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
1888 |
|
1056 | 1889 |
WARNING: do not add/remove elements while iterating over the receiver. |
14318 | 1890 |
Iterate over a copy to do this." |
1 | 1891 |
|
1892 |
|newCollection| |
|
1893 |
||
1894 |
newCollection := self species new. |
|
77 | 1895 |
self keysAndValuesDo:[:key :value | |
14318 | 1896 |
(aBlock value:value) ifTrue:[ |
1897 |
newCollection at:key put:value |
|
1898 |
] |
|
1 | 1899 |
]. |
1900 |
^ newCollection |
|
77 | 1901 |
|
1902 |
" |
|
1903 |
|d| |
|
1904 |
||
1905 |
d := Dictionary new. |
|
1906 |
d at:#foo put:#bar. |
|
1907 |
d at:#bar put:#baz. |
|
1908 |
d at:#baz put:#foo. |
|
1909 |
||
1910 |
d select:[:el | el startsWith:'b']. |
|
1911 |
" |
|
1056 | 1912 |
|
10077 | 1913 |
"Modified: / 12-10-2006 / 11:24:06 / cg" |
7653
0a81451a7a59
added #valuesDo: for compatibility
Claus Gittinger <cg@exept.de>
parents:
7306
diff
changeset
|
1914 |
! |
0a81451a7a59
added #valuesDo: for compatibility
Claus Gittinger <cg@exept.de>
parents:
7306
diff
changeset
|
1915 |
|
0a81451a7a59
added #valuesDo: for compatibility
Claus Gittinger <cg@exept.de>
parents:
7306
diff
changeset
|
1916 |
valuesDo:aBlock |
0a81451a7a59
added #valuesDo: for compatibility
Claus Gittinger <cg@exept.de>
parents:
7306
diff
changeset
|
1917 |
"perform the block for all values in the collection. |
0a81451a7a59
added #valuesDo: for compatibility
Claus Gittinger <cg@exept.de>
parents:
7306
diff
changeset
|
1918 |
Same as #do: - for VisualWorks compatibility" |
0a81451a7a59
added #valuesDo: for compatibility
Claus Gittinger <cg@exept.de>
parents:
7306
diff
changeset
|
1919 |
|
0a81451a7a59
added #valuesDo: for compatibility
Claus Gittinger <cg@exept.de>
parents:
7306
diff
changeset
|
1920 |
^ self do:aBlock |
1 | 1921 |
! ! |
1922 |
||
609 | 1923 |
|
17671 | 1924 |
|
609 | 1925 |
!Dictionary methodsFor:'printing & storing'! |
1926 |
||
3192 | 1927 |
printElementsDo:aBlock |
1928 |
"redefined, so #printOn: prints associations" |
|
609 | 1929 |
|
3192 | 1930 |
^ self associationsDo:aBlock |
609 | 1931 |
|
3192 | 1932 |
"Created: / 20.1.1998 / 14:11:02 / stefan" |
609 | 1933 |
! |
1934 |
||
1935 |
storeOn:aStream |
|
1936 |
"output a printed representation (which can be re-read) |
|
1937 |
onto the argument aStream" |
|
1938 |
||
1939 |
|isEmpty| |
|
1940 |
||
1941 |
thisContext isRecursive ifTrue:[ |
|
15857 | 1942 |
RecursiveStoreError raiseRequestWith:self. |
1943 |
('Dictionary [error]: storeOn: of self referencing collection.') errorPrintCR. |
|
1944 |
aStream nextPutAll:'#recursive'. |
|
1945 |
^ self |
|
609 | 1946 |
]. |
1947 |
||
1948 |
aStream nextPutAll:'('. |
|
1949 |
aStream nextPutAll:(self class name). |
|
1950 |
aStream nextPutAll:' new'. |
|
1951 |
isEmpty := true. |
|
1952 |
self keysAndValuesDo:[:key :value | |
|
15857 | 1953 |
aStream nextPutAll:' at:'. |
1954 |
key storeOn:aStream. |
|
1955 |
aStream nextPutAll:' put:'. |
|
1956 |
value storeOn:aStream. |
|
1957 |
aStream nextPutAll:'; '. |
|
1958 |
isEmpty := false |
|
609 | 1959 |
]. |
1960 |
isEmpty ifFalse:[aStream nextPutAll:' yourself']. |
|
1961 |
aStream nextPut:$) |
|
1962 |
||
1963 |
" |
|
1964 |
Dictionary new storeOn:Transcript |
|
1965 |
||
1966 |
(Dictionary new at:1 put:'hello'; yourself) storeOn:Transcript |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1967 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
1968 |
(Dictionary new at:1 put:'hello'; at:2 put:nil; yourself) storeOn:Transcript |
609 | 1969 |
" |
1970 |
||
1971 |
" |
|
1972 |
|d| |
|
1973 |
d := Dictionary new. |
|
1974 |
d at:1 put:'hello'. |
|
1975 |
d at:'hello' put:#world. |
|
1976 |
d storeOn:Transcript |
|
1977 |
" |
|
1978 |
||
1979 |
" |
|
1980 |
|d| |
|
1981 |
d := Dictionary new. |
|
1982 |
d at:1 put:'hello'. |
|
1983 |
d at:'hello' put:#world. |
|
1984 |
d at:2 put:d. |
|
1985 |
d storeOn:Transcript |
|
1986 |
" |
|
1417 | 1987 |
|
2288 | 1988 |
"Modified: 28.1.1997 / 00:37:46 / cg" |
609 | 1989 |
! ! |
1990 |
||
1 | 1991 |
!Dictionary methodsFor:'private'! |
1992 |
||
345 | 1993 |
compareSame:element1 with:element2 |
1256 | 1994 |
"compare two elements for being the same. Here, return true if the |
1995 |
elements are equal (i.e. using #=). |
|
1996 |
Redefinable in subclasses." |
|
1997 |
||
345 | 1998 |
^ element1 = element2 |
1256 | 1999 |
|
2000 |
"Modified: 22.4.1996 / 17:34:27 / cg" |
|
345 | 2001 |
! |
2002 |
||
609 | 2003 |
emptyCollectionForKeys |
1256 | 2004 |
"return an empty collection to hold keys. Here, a Set is returned. |
2005 |
Redefinable in subclasses." |
|
2006 |
||
609 | 2007 |
^ Set new:(self size) |
1256 | 2008 |
|
2009 |
"Modified: 22.4.1996 / 17:35:17 / cg" |
|
1 | 2010 |
! |
2011 |
||
2012 |
grow:newSize |
|
2013 |
"grow the receiver to make space for at least newSize elements. |
|
2014 |
To do this, we have to rehash into the new arrays. |
|
2015 |
(which is done by re-adding all elements to a new, empty key/value array pair)." |
|
2016 |
||
92 | 2017 |
|key deletedEntry oldKeyArray oldValueArray n |
14318 | 2018 |
oldSize "{ Class:SmallInteger }" |
10 | 2019 |
newIndex "{ Class:SmallInteger }" | |
1 | 2020 |
|
10 | 2021 |
oldKeyArray := keyArray. |
2022 |
oldValueArray := valueArray. |
|
1 | 2023 |
|
249 | 2024 |
n := self class goodSizeFrom:newSize. |
2025 |
oldSize := oldKeyArray size. |
|
2026 |
n == oldSize ifTrue:[^ self]. |
|
2027 |
||
10 | 2028 |
keyArray := self keyContainerOfSize:n. |
92 | 2029 |
valueArray := self valueContainerOfSize:n. |
1 | 2030 |
|
249 | 2031 |
|
92 | 2032 |
deletedEntry := DeletedEntry. |
10 | 2033 |
1 to:oldSize do:[:index | |
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2034 |
key := oldKeyArray basicAt:index. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2035 |
(key notNil and:[key ~~ deletedEntry]) ifTrue:[ |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2036 |
newIndex := self findNil:key. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2037 |
keyArray basicAt:newIndex put:key. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2038 |
valueArray basicAt:newIndex put:(oldValueArray basicAt:index). |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2039 |
] |
1 | 2040 |
] |
2041 |
! |
|
2042 |
||
18332 | 2043 |
initializeForCapacity:minSize |
2044 |
"initialize the contents array (for at least minSize slots) |
|
2045 |
and set tally to zero. |
|
2046 |
The size is increased to the next prime for better hashing behavior." |
|
2047 |
||
2048 |
|n| |
|
2049 |
||
2050 |
n := self class goodSizeFrom:minSize. |
|
18342 | 2051 |
(keyArray notNil and:[n == keyArray size]) ifTrue:[ |
18332 | 2052 |
keyArray atAllPut:nil. |
2053 |
valueArray atAllPut:nil. |
|
2054 |
] ifFalse:[ |
|
2055 |
keyArray := self keyContainerOfSize:n. |
|
2056 |
valueArray := self valueContainerOfSize:n. |
|
2057 |
]. |
|
2058 |
tally := 0 |
|
2059 |
||
2060 |
"Modified: / 5.8.1998 / 10:48:51 / cg" |
|
2061 |
! |
|
2062 |
||
1 | 2063 |
rehash |
2064 |
"rehash contents - is done by re-adding all elements to a new, empty key/value array pair)." |
|
2065 |
||
14318 | 2066 |
| oldKeyArray oldValueArray key |
2 | 2067 |
n "{ Class:SmallInteger }" |
2068 |
newIndex "{ Class:SmallInteger }" | |
|
1 | 2069 |
|
2070 |
oldKeyArray := keyArray. |
|
2071 |
oldValueArray := valueArray. |
|
2072 |
||
2073 |
n := keyArray size. |
|
10 | 2074 |
keyArray := self keyContainerOfSize:n. |
92 | 2075 |
valueArray := self valueContainerOfSize:n. |
1 | 2076 |
|
2 | 2077 |
1 to:n do:[:index | |
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2078 |
key := oldKeyArray basicAt:index. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2079 |
(key notNil and:[key ~~ DeletedEntry]) ifTrue:[ |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2080 |
newIndex := self findNil:key. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2081 |
keyArray basicAt:newIndex put:key. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2082 |
valueArray basicAt:newIndex put:(oldValueArray basicAt:index). |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2083 |
] |
1 | 2084 |
] |
2085 |
! |
|
2086 |
||
2087 |
rehashFrom:startIndex |
|
77 | 2088 |
"rehash elements starting at index - after a remove. |
14318 | 2089 |
NOTE: this method is no longer needed; |
2090 |
the trick using DeletedEntry avoids the need to do this time |
|
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2091 |
consuming operation, making remove pretty fast :-) |
77 | 2092 |
" |
1 | 2093 |
|
2094 |
|key i length |
|
2095 |
index "{ Class:SmallInteger }" | |
|
2096 |
||
2097 |
length := keyArray basicSize. |
|
2098 |
index := startIndex. |
|
2099 |
key := keyArray basicAt:index. |
|
2100 |
[key notNil] whileTrue:[ |
|
12669
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2101 |
key ~~ DeletedEntry ifTrue:[ |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2102 |
i := self findNil:key. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2103 |
i == index ifTrue:[ |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2104 |
^ self |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2105 |
]. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2106 |
keyArray basicAt:i put:key. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2107 |
valueArray basicAt:i put:(valueArray basicAt:index). |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2108 |
keyArray basicAt:index put:nil. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2109 |
valueArray basicAt:index put:nil. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2110 |
]. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2111 |
index == length ifTrue:[ |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2112 |
index := 1 |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2113 |
] ifFalse:[ |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2114 |
index := index + 1. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2115 |
]. |
2acc2409c3f4
changed: #declareAllNewFrom:
Claus Gittinger <cg@exept.de>
parents:
12668
diff
changeset
|
2116 |
key := keyArray basicAt:index. |
1 | 2117 |
] |
77 | 2118 |
! |
2119 |
||
609 | 2120 |
valueContainerOfSize:n |
2121 |
"return a container for values of size n. |
|
2122 |
Extracted to make life of weak subclasses easier ..." |
|
44 | 2123 |
|
609 | 2124 |
^ Array basicNew:n |
2125 |
! ! |
|
2126 |
||
1460 | 2127 |
!Dictionary methodsFor:'searching'! |
2128 |
||
16808 | 2129 |
findFirst:aBlock ifNone:exceptionValue |
2130 |
"find the index of the first element, for which evaluation of the argument, aBlock returns true; |
|
2131 |
return its index or the value from exceptionValue if none detected. |
|
2132 |
This is much like #detect:ifNone:, however, here an INDEX is returned, |
|
2133 |
while #detect:ifNone: returns the element. |
|
2134 |
||
2135 |
Here we return the first key for which aBlock matches the value. |
|
2136 |
Note that there is no order in a Dictionary, so any element is first." |
|
2137 |
||
2138 |
self keysAndValuesDo:[:eachKey :eachValue| (aBlock value:eachValue) ifTrue:[^ eachKey]]. |
|
2139 |
^ exceptionValue value. |
|
2140 |
||
2141 |
" |
|
2142 |
(Dictionary withKeys:#('a' 'b' 'c') andValues:#('bla' 'hello' 'hallo')) |
|
2143 |
findFirst:[:v| v first = $h]. |
|
2144 |
" |
|
2145 |
! |
|
2146 |
||
1460 | 2147 |
findFirstKey:aBlock |
2148 |
"find and return the first key, for which evaluation of the argument, aBlock |
|
1703 | 2149 |
returns true; return nil if none is detected." |
1460 | 2150 |
|
2151 |
self keysDo:[:key | |
|
14318 | 2152 |
(aBlock value:key) ifTrue:[^ key]. |
1460 | 2153 |
]. |
2154 |
^ nil |
|
2155 |
||
2156 |
"Created: 5.6.1996 / 11:55:50 / stefan" |
|
1703 | 2157 |
"Modified: 8.10.1996 / 22:01:59 / cg" |
1460 | 2158 |
! ! |
2159 |
||
609 | 2160 |
!Dictionary methodsFor:'testing'! |
44 | 2161 |
|
609 | 2162 |
includes:anObject |
2163 |
"return true, if the argument, aValue is stored in the dictionary, |
|
2164 |
i.e. if there is an associaten, with aValue as value. |
|
2165 |
This is a slow search, since there is no fast reverse mapping; |
|
2166 |
the values have to be all scanned without any hashing. |
|
2167 |
You need a special collection (or two Dictionaries) to get this |
|
2168 |
reverse mapping fast." |
|
2169 |
||
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2170 |
^ self includesEqualValue:anObject |
1256 | 2171 |
|
2172 |
"Modified: 22.4.1996 / 17:20:11 / cg" |
|
609 | 2173 |
! |
68 | 2174 |
|
609 | 2175 |
includesAssociation:anAssociation |
2176 |
"return true, if there is an association in the receiver with the |
|
2177 |
same key and value as the argument, anAssociation. |
|
2178 |
NOTICE: in contrast to #includes:, this compares both key and value." |
|
2179 |
||
2180 |
|val| |
|
44 | 2181 |
|
609 | 2182 |
val := self at:(anAssociation key) ifAbsent:[^ false]. |
3318
d8173a888c93
oops - compareSame was wrong (used with #includesAssociation:)
Claus Gittinger <cg@exept.de>
parents:
3304
diff
changeset
|
2183 |
^ self compareSame:val with:anAssociation value |
d8173a888c93
oops - compareSame was wrong (used with #includesAssociation:)
Claus Gittinger <cg@exept.de>
parents:
3304
diff
changeset
|
2184 |
|
d8173a888c93
oops - compareSame was wrong (used with #includesAssociation:)
Claus Gittinger <cg@exept.de>
parents:
3304
diff
changeset
|
2185 |
"Modified: / 5.3.1998 / 20:35:00 / cg" |
609 | 2186 |
! |
2187 |
||
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2188 |
includesEqualValue:aValue |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2189 |
"return true, if the argument, aValue is stored in the dictionary, |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2190 |
i.e. if there is an associaten, with aValue as value. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2191 |
This is a slow search, since there is no fast reverse mapping; |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2192 |
the values have to be all scanned without any hashing. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2193 |
You need a special collection (or two Dictionaries) to get this |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2194 |
reverse mapping fast." |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2195 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2196 |
aValue isNil ifTrue:[ |
14318 | 2197 |
"/ need a special case for that ... |
2198 |
^ self includesIdenticalValue:aValue. |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2199 |
]. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2200 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2201 |
^ valueArray includes:aValue |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2202 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2203 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2204 |
|d| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2205 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2206 |
d := Dictionary new. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2207 |
d at:'1' put:'one'. |
14318 | 2208 |
d includes:nil. |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2209 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2210 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2211 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2212 |
|d| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2213 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2214 |
d := Dictionary new. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2215 |
d at:'1' put:'one'. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2216 |
d at:2 put:nil. |
14318 | 2217 |
d includes:nil. |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2218 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2219 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2220 |
! |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2221 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2222 |
includesIdenticalValue:aValue |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2223 |
"return true, if the argument, aValue is stored in the dictionary, |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2224 |
i.e. if there is an associaten, with aValue as value. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2225 |
This is a slow search, since there is no fast reverse mapping; |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2226 |
the values have to be all scanned without any hashing. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2227 |
You need a special collection (or two Dictionaries) to get this |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2228 |
reverse mapping fast." |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2229 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2230 |
|idx| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2231 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2232 |
aValue isNil ifTrue:[ |
14318 | 2233 |
"/ need a special case for that ... |
2234 |
idx := 0. |
|
2235 |
[true] whileTrue:[ |
|
2236 |
idx := valueArray identityIndexOf:nil startingAt:idx+1. |
|
2237 |
idx == 0 ifTrue:[^ false]. |
|
2238 |
(keyArray at:idx) notNil ifTrue:[^ true]. |
|
2239 |
] |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2240 |
]. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2241 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2242 |
^ valueArray includesIdentical:aValue |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2243 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2244 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2245 |
|d| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2246 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2247 |
d := Dictionary new. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2248 |
d at:'1' put:'one'. |
14318 | 2249 |
d includes:nil. |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2250 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2251 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2252 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2253 |
|d| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2254 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2255 |
d := Dictionary new. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2256 |
d at:'1' put:'one'. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2257 |
d at:2 put:nil. |
14318 | 2258 |
d includes:nil. |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2259 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2260 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2261 |
! |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2262 |
|
609 | 2263 |
includesKey:aKey |
2264 |
"return true, if the argument, aKey is a key in the receiver" |
|
2265 |
||
14318 | 2266 |
^ (self find:(aKey ? NilEntry) ifAbsent:0) ~~ 0 |
9570
008049e411b5
includesKey: returned a wrong answer for a nil key.
Claus Gittinger <cg@exept.de>
parents:
9413
diff
changeset
|
2267 |
|
008049e411b5
includesKey: returned a wrong answer for a nil key.
Claus Gittinger <cg@exept.de>
parents:
9413
diff
changeset
|
2268 |
"Modified: / 17-08-2006 / 21:06:41 / cg" |
609 | 2269 |
! |
293 | 2270 |
|
609 | 2271 |
includesValue:aValue |
2272 |
"return true, if the argument, aValue is stored in the dictionary, |
|
2273 |
i.e. if there is an associaten, with aValue as value. |
|
2274 |
This is a slow search, since there is no fast reverse mapping; |
|
2275 |
the values have to be all scanned without any hashing. |
|
2276 |
You need a special collection (or two Dictionaries) to get this |
|
2277 |
reverse mapping fast." |
|
293 | 2278 |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2279 |
^ self includesEqualValue:aValue |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2280 |
|
609 | 2281 |
! |
293 | 2282 |
|
15363 | 2283 |
isDictionary |
2284 |
"return true, if the receiver is some kind of dictionary; |
|
2285 |
true returned here - the method is redefined from Object." |
|
2286 |
||
2287 |
^ true |
|
2288 |
! |
|
2289 |
||
609 | 2290 |
occurrencesOf:anObject |
2291 |
"count & return how often anObject is stored in the dictionary. |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2292 |
This counts values - not keys. Uses #= (i.e. equality) compare." |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2293 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2294 |
|idx count| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2295 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2296 |
anObject isNil ifTrue:[ |
14318 | 2297 |
"/ need a special case for that ... |
2298 |
idx := 0. |
|
2299 |
count := 0. |
|
2300 |
[true] whileTrue:[ |
|
2301 |
idx := valueArray identityIndexOf:nil startingAt:idx+1. |
|
2302 |
idx == 0 ifTrue:[^ count]. |
|
2303 |
(keyArray at:idx) notNil ifTrue:[ |
|
2304 |
count := count + 1 |
|
2305 |
] |
|
2306 |
] |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2307 |
]. |
609 | 2308 |
|
2309 |
^ valueArray occurrencesOf:anObject |
|
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2310 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2311 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2312 |
|d| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2313 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2314 |
d := Dictionary new. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2315 |
d at:'1' put:'one'. |
14318 | 2316 |
d occurrencesOf:nil. |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2317 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2318 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2319 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2320 |
|d| |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2321 |
|
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2322 |
d := Dictionary new. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2323 |
d at:'1' put:'one'. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2324 |
d at:2 put:nil. |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2325 |
d at:5 put:nil. |
14318 | 2326 |
d occurrencesOf:nil. |
5050
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2327 |
" |
ea292b958108
allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents:
4871
diff
changeset
|
2328 |
|
1 | 2329 |
! ! |
609 | 2330 |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7906
diff
changeset
|
2331 |
!Dictionary methodsFor:'visiting'! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7906
diff
changeset
|
2332 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7906
diff
changeset
|
2333 |
acceptVisitor:aVisitor with:aParameter |
16728 | 2334 |
"dispatch for visitor pattern; send #visitDictionary:with: to aVisitor" |
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7906
diff
changeset
|
2335 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7906
diff
changeset
|
2336 |
^ aVisitor visitDictionary:self with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7906
diff
changeset
|
2337 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
7906
diff
changeset
|
2338 |
|
2094
42cd02703bf4
handle recursive printString/displayString
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
2339 |
!Dictionary class methodsFor:'documentation'! |
633 | 2340 |
|
2341 |
version |
|
18787 | 2342 |
^ '$Header$' |
12659 | 2343 |
! |
2344 |
||
2345 |
version_CVS |
|
18787 | 2346 |
^ '$Header$' |
633 | 2347 |
! ! |
14897 | 2348 |