Back: Autoload-accessing
Up: Class reference
Forward: Bag class-basic
 
Top: GNU Smalltalk User's Guide
Contents: Table of Contents
Index: Class index
About: About this document

6.7 Bag

Defined in namespace Smalltalk
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.

6.7.1 Bag class: basic  (class)
6.7.2 Bag: Adding to a collection  (instance)
6.7.3 Bag: enumerating the elements of a collection  (instance)
6.7.4 Bag: extracting items  (instance)
6.7.5 Bag: printing  (instance)
6.7.6 Bag: Removing from a collection  (instance)
6.7.7 Bag: storing  (instance)
6.7.8 Bag: testing collections  (instance)


6.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


6.7.2 Bag: Adding to a collection

add: newObject
Add an occurrence of newObject to the receiver. Answer newObject

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


6.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.


6.7.4 Bag: extracting items

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


6.7.5 Bag: printing

printOn: aStream
Put on aStream a representation of the receiver


6.7.6 Bag: Removing from a collection

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


6.7.7 Bag: storing

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


6.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




This document was generated on May, 12 2002 using texi2html