Back: Autoload-accessing Up: Base classes Forward: Bag class-basic   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document

1.7 Bag

Defined in namespace Smalltalk
Superclass: Collection
Category: Collections-Unordered
My instances are unordered collections of objects. You can think of me as a set with a memory; that is, if the same object is added to me twice, then I will report that that element has been stored twice.

1.7.1 Bag class: basic  (class)
1.7.2 Bag: adding  (instance)
1.7.3 Bag: enumerating the elements of a collection  (instance)
1.7.4 Bag: extracting items  (instance)
1.7.5 Bag: printing  (instance)
1.7.6 Bag: removing  (instance)
1.7.7 Bag: storing  (instance)
1.7.8 Bag: testing collections  (instance)


1.7.1 Bag class: basic

new
Answer a new instance of the receiver

new: size
Answer a new instance of the receiver, with space for size distinct objects


1.7.2 Bag: adding

add: newObject
Add an occurrence of newObject to the receiver. Answer newObject. Fail if newObject is nil.

add: newObject withOccurrences: anInteger
If anInteger > 0, add anInteger occurrences of newObject to the receiver. If anInteger < 0, remove them. Answer newObject. Fail if newObject is nil.


1.7.3 Bag: enumerating the elements of a collection

asSet
Answer a set with the elements of the receiver

do: aBlock
Evaluate the block for all members in the collection.


1.7.4 Bag: extracting items

sortedByCount
Answer a collection of counts with elements, sorted by decreasing count.


1.7.5 Bag: printing

printOn: aStream
Put on aStream a representation of the receiver


1.7.6 Bag: removing

remove: oldObject ifAbsent: anExceptionBlock
Remove oldObject from the collection and return it. If can't be found, answer instead the result of evaluationg anExceptionBlock


1.7.7 Bag: storing

storeOn: aStream
Put on aStream some Smalltalk code compiling to the receiver


1.7.8 Bag: testing collections

= aBag
Answer whether the receiver and aBag contain the same objects

hash
Answer an hash value for the receiver

includes: anObject
Answer whether we include anObject

occurrencesOf: anObject
Answer the number of occurrences of anObject found in the receiver

size
Answer the total number of objects found in the receiver



Back: Bag-storing Up: Bag Forward: Behavior   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document


This document was generated on February, 22 2012 using texi2html