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