author | Claus Gittinger <cg@exept.de> |
Sat, 01 Mar 2014 23:33:23 +0100 | |
changeset 16189 | d7b9978c07bb |
parent 16098 | 28eb81300399 |
child 16766 | c71254785e72 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
345 | 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 |
" |
|
5375 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
1 | 14 |
Collection subclass:#Bag |
1057 | 15 |
instanceVariableNames:'contents' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Unordered' |
|
1 | 19 |
! |
20 |
||
54 | 21 |
!Bag class methodsFor:'documentation'! |
22 |
||
88 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
345 | 26 |
All Rights Reserved |
88 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
54 | 37 |
documentation |
38 |
" |
|
88 | 39 |
Bag implements collections whose elements are unordered and have no |
154 | 40 |
external key. Elements may occur more than once in a bag. There is no defined |
8873 | 41 |
order within a bag. |
42 |
The default implementation uses a dictionary to store each objects occurrence |
|
43 |
count, using the object itself as key (i.e. using = and hash for inclusion |
|
345 | 44 |
tests). |
399 | 45 |
|
345 | 46 |
There is also an instance creation variant (#identityNew:) creating a |
47 |
bag which compares using #== and hashes using #identityHash. |
|
8873 | 48 |
(I'd say that an IdentityBag was a better thing to implement ... |
399 | 49 |
... but for compatibility ... we do it here as well) |
1 | 50 |
|
1283 | 51 |
[Instance variables:] |
52 |
||
8873 | 53 |
contents <Dictionary> for each element, the number of occurrences |
1283 | 54 |
|
1 | 55 |
|
1290 | 56 |
[author:] |
8873 | 57 |
Claus Gittinger |
1290 | 58 |
|
1283 | 59 |
[See also:] |
8873 | 60 |
Set IdentitySet |
61 |
Dictionary IdentityDictionary |
|
62 |
OrderedCollection Array |
|
54 | 63 |
" |
64 |
! ! |
|
1 | 65 |
|
66 |
!Bag class methodsFor:'instance creation'! |
|
67 |
||
14956 | 68 |
contentsClass |
69 |
"the default class to use for the underlying contents array, |
|
70 |
used when instantiated with new/new:" |
|
71 |
||
72 |
^ Dictionary |
|
73 |
! |
|
74 |
||
75 |
equalityNew |
|
76 |
"return a new empty Bag. |
|
77 |
Elements will be compared using equality compare (i.e. #= not #== identity)." |
|
78 |
||
79 |
^ self basicNew initContentsForEquality |
|
80 |
! |
|
81 |
||
345 | 82 |
equalityNew:size |
83 |
"return a new empty Bag with initial space for size elements. |
|
84 |
Elements will be compared using equality compare (i.e. #= not #== identity)." |
|
1 | 85 |
|
14956 | 86 |
^ self basicNew initContentsForEquality:size |
345 | 87 |
! |
88 |
||
5375 | 89 |
identityNew |
14956 | 90 |
"return a new empty Identity-Bag. |
5375 | 91 |
Elements will be compared using identity compare (i.e. #== not #= equality)." |
92 |
||
14956 | 93 |
^ self basicNew initContentsForIdentity |
5375 | 94 |
! |
95 |
||
345 | 96 |
identityNew:size |
97 |
"return a new empty Bag with initial space for size elements. |
|
98 |
Elements will be compared using identity compare (i.e. #== not #= equality)." |
|
99 |
||
5558 | 100 |
^ self basicNew initContentsForIdentity:size |
1 | 101 |
! |
102 |
||
609 | 103 |
new |
104 |
"return a new empty Bag which compares for equality (i.e. not identity)" |
|
1 | 105 |
|
5558 | 106 |
^ self basicNew initContents |
345 | 107 |
! |
108 |
||
609 | 109 |
new:size |
110 |
"return a new empty Bag with initial space for size elements. |
|
111 |
Elements will be compared using equality compare (i.e. #= not #== identity)." |
|
345 | 112 |
|
609 | 113 |
^ self equalityNew:size |
1 | 114 |
! ! |
115 |
||
7261 | 116 |
!Bag methodsFor:'Compatibility-Dolphin'! |
6411 | 117 |
|
118 |
asAssociations |
|
11935 | 119 |
"return the dictionary which associates occurrence-counts |
120 |
to the bags elements. |
|
121 |
Same as #contents for dolphin compatibility." |
|
122 |
||
14685 | 123 |
^ self contents |
6411 | 124 |
! ! |
125 |
||
1 | 126 |
!Bag methodsFor:'accessing'! |
127 |
||
128 |
at:index |
|
129 |
"report an error: at: is not allowed for Bags" |
|
130 |
||
131 |
^ self errorNotKeyed |
|
132 |
! |
|
133 |
||
134 |
at:index put:anObject |
|
135 |
"report an error: at:put: is not allowed for Bags" |
|
136 |
||
137 |
^ self errorNotKeyed |
|
345 | 138 |
! |
139 |
||
140 |
contents |
|
141 |
"return the dictionary which associates occurrence-counts |
|
142 |
to the bags elements." |
|
143 |
||
144 |
^ contents |
|
15732 | 145 |
|
146 |
" |
|
147 |
Bag new |
|
148 |
add:'abc'; |
|
149 |
add:'def'; |
|
150 |
add:'ghi'; |
|
151 |
add:'abc'; |
|
152 |
add:'def'; |
|
153 |
add:'abc'; |
|
154 |
add:'abc'; |
|
155 |
contents |
|
156 |
" |
|
15686 | 157 |
! |
158 |
||
159 |
sortedCounts |
|
15732 | 160 |
"Answer with a collection of counts associated to elements, sorted by decreasing count." |
15686 | 161 |
"Suggested by l. Uzonyi" |
162 |
||
163 |
^ (Array new:contents size |
|
164 |
streamContents:[:stream | |
|
165 |
contents associationsDo:[:each | stream nextPut:each value -> each key ] |
|
166 |
]) |
|
167 |
sort:[:x :y | x >= y ]; |
|
168 |
yourself |
|
15731 | 169 |
|
170 |
" |
|
171 |
Bag new |
|
172 |
add:'abc'; |
|
173 |
add:'def'; |
|
174 |
add:'ghi'; |
|
175 |
add:'abc'; |
|
176 |
add:'def'; |
|
177 |
add:'abc'; |
|
178 |
add:'abc'; |
|
179 |
sortedCounts |
|
180 |
" |
|
16098 | 181 |
! |
182 |
||
183 |
valuesSortedByCounts |
|
184 |
"Answer with a collection of values, sorted by decreasing count. |
|
185 |
Count informtion is lost in the result" |
|
186 |
||
187 |
^ self sortedCounts collect:[:assoc | assoc value]. |
|
188 |
||
189 |
" |
|
190 |
Bag new |
|
191 |
add:'abc'; |
|
192 |
add:'def'; |
|
193 |
add:'ghi'; |
|
194 |
add:'abc'; |
|
195 |
add:'def'; |
|
196 |
add:'abc'; |
|
197 |
add:'abc'; |
|
198 |
valuesSortedByCounts |
|
199 |
" |
|
1 | 200 |
! ! |
201 |
||
202 |
!Bag methodsFor:'adding & removing'! |
|
203 |
||
54 | 204 |
add:newObject |
345 | 205 |
"add the argument, anObject to the receiver. |
14896 | 206 |
Returns the object (sigh). |
1057 | 207 |
|
208 |
WARNING: do not add/remove elements while iterating over the receiver. |
|
14896 | 209 |
Iterate over a copy to do this." |
1 | 210 |
|
54 | 211 |
|n| |
212 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1110
diff
changeset
|
213 |
n := contents at:newObject ifAbsent:0. |
54 | 214 |
contents at:newObject put:(n + 1). |
215 |
^ newObject |
|
1057 | 216 |
|
217 |
"Modified: 1.3.1996 / 21:43:06 / cg" |
|
1 | 218 |
! |
219 |
||
1372
d7bd1b463a65
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
220 |
add:newObject withOccurrences:anInteger |
345 | 221 |
"add the argument, anObject anInteger times to the receiver. |
1057 | 222 |
Returns the object. |
223 |
||
224 |
WARNING: do not add/remove elements while iterating over the receiver. |
|
8873 | 225 |
Iterate over a copy to do this." |
1 | 226 |
|
54 | 227 |
|n| |
228 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1110
diff
changeset
|
229 |
n := contents at:newObject ifAbsent:0. |
54 | 230 |
contents at:newObject put:(n + anInteger). |
1 | 231 |
^ newObject |
1057 | 232 |
|
233 |
"Modified: 1.3.1996 / 21:43:12 / cg" |
|
1372
d7bd1b463a65
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
234 |
"Created: 11.5.1996 / 12:13:43 / cg" |
1 | 235 |
! |
236 |
||
237 |
remove:oldObject ifAbsent:anExceptionBlock |
|
345 | 238 |
"Remove oldObject from the collection. |
239 |
If it was not present, return the value of the exceptionBlock; |
|
1057 | 240 |
otherwise return the removed object. |
241 |
||
242 |
WARNING: do not add/remove elements while iterating over the receiver. |
|
8873 | 243 |
Iterate over a copy to do this." |
1 | 244 |
|
245 |
|count| |
|
246 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1110
diff
changeset
|
247 |
count := contents at:oldObject ifAbsent:0. |
1 | 248 |
(count == 0) ifTrue:[^ anExceptionBlock value]. |
249 |
(count == 1) ifTrue:[ |
|
8873 | 250 |
contents removeKey:oldObject |
251 |
] ifFalse:[ |
|
252 |
contents at:oldObject put:(count - 1) |
|
1 | 253 |
]. |
254 |
^ oldObject |
|
1057 | 255 |
|
256 |
"Modified: 1.3.1996 / 21:43:18 / cg" |
|
345 | 257 |
! |
258 |
||
1110 | 259 |
removeAll |
1164 | 260 |
"remove all objects from the receiver collection (i.e. make it empty). |
261 |
Returns the receiver." |
|
1110 | 262 |
|
263 |
contents := contents species new. |
|
264 |
||
265 |
" |
|
266 |
|b| |
|
267 |
||
268 |
b := Bag new. |
|
269 |
b add:1; add:2; add:3; add:2; add:1. |
|
1422 | 270 |
Transcript showCR:b. |
1110 | 271 |
|
272 |
b removeAll. |
|
273 |
||
1422 | 274 |
Transcript showCR:b |
1110 | 275 |
" |
276 |
||
1164 | 277 |
"Modified: 12.4.1996 / 13:34:34 / cg" |
1110 | 278 |
! |
279 |
||
345 | 280 |
removeAllOccurrencesOf:oldObject ifAbsent:anExceptionBlock |
281 |
"Remove all occurrences of oldObject from the collection. |
|
282 |
If it was not present, return the value of the exceptionBlock; |
|
1057 | 283 |
otherwise return the number of removes. |
284 |
||
285 |
WARNING: do not add/remove elements while iterating over the receiver. |
|
8873 | 286 |
Iterate over a copy to do this." |
345 | 287 |
|
288 |
|count| |
|
289 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1110
diff
changeset
|
290 |
count := contents at:oldObject ifAbsent:0. |
345 | 291 |
(count == 0) ifTrue:[^ anExceptionBlock value]. |
292 |
contents removeKey:oldObject. |
|
293 |
^ oldObject |
|
1057 | 294 |
|
295 |
"Modified: 1.3.1996 / 21:43:26 / cg" |
|
1 | 296 |
! ! |
297 |
||
8860 | 298 |
!Bag methodsFor:'bulk operations'! |
299 |
||
300 |
sum |
|
11522 | 301 |
"sum up all elements; return 0 for an empty collection. |
302 |
can be done easier, using bags knowledge." |
|
8860 | 303 |
|
304 |
|accu| |
|
305 |
||
11522 | 306 |
self isEmpty ifTrue:[ ^ 0 ]. |
11474 | 307 |
|
308 |
accu := nil. |
|
309 |
self |
|
310 |
valuesAndCountsDo:[:n :count | |
|
311 |
|thisAmount| |
|
312 |
||
313 |
thisAmount := count * n. |
|
314 |
accu := (accu isNil ifTrue:[thisAmount] ifFalse:[accu + thisAmount]) ]. |
|
8860 | 315 |
^ accu |
316 |
||
317 |
" |
|
11474 | 318 |
TestCase assert:((Bag new add:1; add:2; add:3; add:1; add:2; add:1; yourself) sum = 10). |
8860 | 319 |
" |
320 |
! ! |
|
321 |
||
6735
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
322 |
!Bag methodsFor:'comparing'! |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
323 |
|
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
324 |
= aBag |
11935 | 325 |
"Compare the receiver with the argument and return true if the |
326 |
receiver is equal to the argument (i.e. has the same size and elements). |
|
327 |
Otherwise return false." |
|
328 |
||
6735
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
329 |
aBag species == self species ifFalse:[^ false]. |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
330 |
self size == aBag size ifFalse:[^ false]. |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
331 |
self valuesAndCountsDo:[:val :cnt | |
11935 | 332 |
(aBag occurrencesOf:val) == cnt ifFalse:[^ false] |
6735
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
333 |
]. |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
334 |
^ true |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
335 |
! |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
336 |
|
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
337 |
hash |
11935 | 338 |
"return an integer useful for hashing on the receiver; |
339 |
redefined since = is redefined here." |
|
340 |
||
6735
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
341 |
|h| |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
342 |
|
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
343 |
h := self size. |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
344 |
self valuesAndCountsDo:[:val :cnt | |
11935 | 345 |
h := h + cnt hash. |
6735
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
346 |
]. |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
347 |
^ h |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
348 |
! ! |
fad09454a025
added #= and #hash (to put bags into Sets/Dictionaries)
Claus Gittinger <cg@exept.de>
parents:
6411
diff
changeset
|
349 |
|
609 | 350 |
!Bag methodsFor:'converting'! |
351 |
||
352 |
asBag |
|
353 |
"return the receiver as a bag" |
|
354 |
||
355 |
"could be an instance of a subclass..." |
|
356 |
self class == Bag ifTrue:[ |
|
357 |
^ self |
|
358 |
]. |
|
359 |
^ super asBag |
|
7161 | 360 |
! |
361 |
||
362 |
asSet |
|
363 |
"return the receiver as a set" |
|
364 |
||
365 |
^ contents keys copy |
|
366 |
||
367 |
" |
|
368 |
|b| |
|
369 |
||
370 |
b := Bag new. |
|
371 |
b add:1; add:2; add:3; add:1; add:1. |
|
372 |
b asSet. |
|
373 |
" |
|
609 | 374 |
! ! |
375 |
||
376 |
!Bag methodsFor:'copying'! |
|
377 |
||
378 |
postCopy |
|
379 |
"must copy the contents as well" |
|
380 |
||
381 |
contents := contents copy |
|
382 |
! ! |
|
383 |
||
1 | 384 |
!Bag methodsFor:'enumerating'! |
385 |
||
386 |
do:aBlock |
|
1057 | 387 |
"evaluate the block for all elements in the collection. |
388 |
||
389 |
WARNING: do not add/remove elements while iterating over the receiver. |
|
8873 | 390 |
Iterate over a copy to do this." |
1 | 391 |
|
54 | 392 |
contents keysAndValuesDo:[:key :value| |
8873 | 393 |
value timesRepeat:[ |
394 |
aBlock value:key |
|
395 |
] |
|
1 | 396 |
] |
1057 | 397 |
|
398 |
"Modified: 1.3.1996 / 21:42:39 / cg" |
|
345 | 399 |
! |
400 |
||
10835 | 401 |
valuesAndCounts |
11481 | 402 |
"return an orderedCollection containing value->count associations" |
10835 | 403 |
|
404 |
|coll| |
|
405 |
||
406 |
coll := OrderedCollection new. |
|
407 |
self valuesAndCountsDo:[:value :count | coll add:(value->count)]. |
|
408 |
^ coll |
|
409 |
||
410 |
"Modified: 1.3.1996 / 21:42:44 / cg" |
|
411 |
! |
|
412 |
||
345 | 413 |
valuesAndCountsDo:aTwoArgBlock |
414 |
"evaluate the block for all distinct elements in the collection, |
|
8873 | 415 |
passing both the element and the occurrence count as arguments. |
1057 | 416 |
|
417 |
WARNING: do not add/remove elements while iterating over the receiver. |
|
8873 | 418 |
Iterate over a copy to do this." |
345 | 419 |
|
420 |
^ contents keysAndValuesDo:aTwoArgBlock |
|
1057 | 421 |
|
422 |
"Modified: 1.3.1996 / 21:42:44 / cg" |
|
1 | 423 |
! ! |
609 | 424 |
|
12823 | 425 |
!Bag methodsFor:'printing & storing'! |
426 |
||
427 |
printElementsDo:aBlock |
|
14685 | 428 |
self valuesAndCountsDo:[:value :count| |
429 |
aBlock value:('%1(*%2)' bindWith:value with:count). |
|
12823 | 430 |
] |
431 |
! ! |
|
432 |
||
609 | 433 |
!Bag methodsFor:'private'! |
434 |
||
435 |
initContents |
|
14956 | 436 |
"set the contents to be an empty Dictionary. |
437 |
This is the default method for initialization, which can be redefined in subclasses." |
|
438 |
||
439 |
contents := self class contentsClass new |
|
440 |
! |
|
441 |
||
442 |
initContents:size |
|
443 |
"set the contents to be an empty Dictionary with initial size. |
|
444 |
This is the default method for initialization, which can be redefined in subclasses." |
|
445 |
||
446 |
contents := self class contentsClass new: size |
|
447 |
! |
|
448 |
||
449 |
initContentsForEquality |
|
609 | 450 |
"set the contents to be an empty Dictionary" |
451 |
||
452 |
contents := Dictionary new |
|
453 |
! |
|
454 |
||
14956 | 455 |
initContentsForEquality:size |
609 | 456 |
"set the contents to be an empty Dictionary with initial size" |
457 |
||
458 |
contents := Dictionary new:size |
|
459 |
! |
|
460 |
||
5375 | 461 |
initContentsForIdentity |
462 |
"set the contents to be an empty IdentityDictionary" |
|
463 |
||
464 |
contents := IdentityDictionary new |
|
465 |
! |
|
466 |
||
609 | 467 |
initContentsForIdentity:size |
468 |
"set the contents to be an empty IdentityDictionary with initial size" |
|
469 |
||
470 |
contents := IdentityDictionary new:size |
|
471 |
! ! |
|
472 |
||
5557 | 473 |
!Bag methodsFor:'queries'! |
474 |
||
475 |
size |
|
476 |
"return the number of bag elements" |
|
477 |
||
478 |
|count| |
|
479 |
||
480 |
count := 0. |
|
481 |
contents do:[:element | count := count + element]. |
|
482 |
^ count |
|
483 |
! ! |
|
484 |
||
15457 | 485 |
!Bag methodsFor:'statistical functions'! |
486 |
||
487 |
variance |
|
488 |
"compute the variance over a complete data set (and not of a sample)" |
|
489 |
||
490 |
|m sz sumDeltaSquares| |
|
491 |
||
492 |
m := self arithmeticMean. |
|
493 |
sumDeltaSquares := 0. |
|
494 |
sz := 0. |
|
495 |
self |
|
496 |
valuesAndCountsDo:[:val :count | |
|
497 |
sumDeltaSquares := sumDeltaSquares + ((val - m) squared). |
|
498 |
sz := sz + 1. |
|
499 |
]. |
|
500 |
||
501 |
^ sumDeltaSquares / sz |
|
502 |
||
503 |
" |
|
504 |
TestCase assert:( #(1 1 1 2 2 2 1 1 1 2 2 2) asBag variance = #(1 1 1 2 2 2 1 1 1 2 2 2) variance). |
|
505 |
TestCase assert:( #(1 1 1 1 1 0 0 0 0 0) asBag variance = #(1 1 1 1 1 0 0 0 0 0) variance). |
|
506 |
" |
|
507 |
! ! |
|
508 |
||
609 | 509 |
!Bag methodsFor:'testing'! |
510 |
||
511 |
includes:anObject |
|
512 |
"return true, if anObject is in the receiver" |
|
513 |
||
14685 | 514 |
^ (self occurrencesOf:anObject) > 0 |
609 | 515 |
! |
516 |
||
15429 | 517 |
isFixedSize |
518 |
"return true if the receiver cannot grow" |
|
519 |
||
520 |
^ false |
|
521 |
! |
|
522 |
||
609 | 523 |
occurrencesOf:anObject |
524 |
"return how many times anObject is in the receiver" |
|
525 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1110
diff
changeset
|
526 |
^ contents at:anObject ifAbsent:0 |
609 | 527 |
! ! |
528 |
||
633 | 529 |
!Bag class methodsFor:'documentation'! |
530 |
||
531 |
version |
|
16098 | 532 |
^ '$Header: /cvs/stx/stx/libbasic/Bag.st,v 1.50 2014-02-20 14:03:54 cg Exp $' |
12823 | 533 |
! |
534 |
||
535 |
version_CVS |
|
16098 | 536 |
^ '$Header: /cvs/stx/stx/libbasic/Bag.st,v 1.50 2014-02-20 14:03:54 cg Exp $' |
633 | 537 |
! ! |
14685 | 538 |