Squeak Class Documentation category index | class index  
 
Bag
  category: Collections-Unordered
  superclass: Collection
  subclasses: IdentityBag

I represent an unordered collection of possibly duplicate elements.

I store these elements in a dictionary, tallying up occurrences of equal objects. Because I store an occurrence only once, my clients should beware that objects they store will not necessarily be retrieved such that == is true. If the client cares, a subclass of me should be created.

instance methods
  accessing
  at:
at:put:
cumulativeCounts
size
sortedCounts
sortedElements

  adding
  add:
add:withOccurrences:

  converting
  asBag
asSet

  copying
  copy

  enumerating
  do:

  private
  setContents:

  removing
  remove:ifAbsent:

  testing
  includes:
occurrencesOf:

class methods
  instance creation
  contentsClass
new
new:
newFrom:

instance methods
  accessing top  
 

at:

Primitive. Assumes receiver is indexable. Answer the value of an
indexable element in the receiver. Fail if the argument index is not an
Integer or is out of bounds. Essential. See Object documentation
whatIsAPrimitive.


 

at:put:

Primitive. Assumes receiver is indexable. Store the argument value in
the indexable element of the receiver indicated by index. Fail if the
index is not an Integer or is out of bounds. Or fail if the value is not of
the right type for this kind of collection. Answer the value that was
stored. Essential. See Object documentation whatIsAPrimitive.


 

cumulativeCounts

Answer with a collection of cumulative percents covered by elements so far.


 

size

Answer how many elements the receiver contains.


 

sortedCounts

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


 

sortedElements

Answer with a collection of elements with counts, sorted by element.


  adding top  
 

add:

Include newObject as one of the receiver's elements. Answer newObject.


 

add:withOccurrences:

Add newObject anInteger times to the receiver. Answer newObject.


  converting top  
 

asBag

Answer a Bag whose elements are the elements of the receiver.


 

asSet

Answer a set with the elements of the receiver.


  copying top  
 

copy

Answer another instance just like the receiver. Subclasses typically
override this method; they typically do not override shallowCopy.


  enumerating top  
 

do:

Refer to the comment in Collection|do:.


  private top  
 

setContents:


  removing top  
 

remove:ifAbsent:

Refer to the comment in Collection|remove:ifAbsent:.


  testing top  
 

includes:

Refer to the comment in Collection|includes:.


 

occurrencesOf:

Refer to the comment in Collection|occurrencesOf:.


class methods
  instance creation top  
 

contentsClass


 

new

Answer a new instance of the receiver (which is a class) with no indexable variables. Fail if the class is indexable.


 

new:

Answer an instance of this class with the number of indexable
variables specified by the argument, sizeRequested.


 

newFrom:

Answer an instance of me containing the same elements as aCollection.