eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SmallBag':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: SmallBag


Inheritance:

   Object
   |
   +--Collection
      |
      +--Bag
         |
         +--SmallBag

Package:
stx:libbasic2
Category:
Collections-Unordered
Version:
rev: 1.2 date: 2019/02/10 13:44:06
user: cg
file: SmallBag.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


SmallBag behaves like Bag, but is tuned for a small number of distinct objects (in the order of 10),
by not using a dictionary, but a linear array holding count-value pairs in consecutive slots.
Only use it when many small bags are required, as this will be slower if too many (distinct) elements are added.

[Instance variables:]
    contents        <Array>    holds count/value info in consecutive slots


Related information:

    Bag
    Set
    IdentitySet
    Dictionary
    IdentityDictionary
    OrderedCollection
    Array

Instance protocol:

accessing
o  contents
return the dictionary which associates occurrence-counts
to the bags elements.

usage example(s):

     SmallBag new contents     
     SmallBag new size     

adding & removing
o  add: newObject
add the argument, anObject to the receiver.
Returns the object.

WARNING: do not add/remove elements while iterating over the receiver.
Iterate over a copy to do this.

o  add: newObject withOccurrences: nMore
add the argument, anObject anInteger times to the receiver.
Returns the object.

WARNING: do not add/remove elements while iterating over the receiver.
Iterate over a copy to do this.

o  remove: oldObject ifAbsent: anExceptionBlock
Remove oldObject from the collection.
If it was not present, return the value of the exceptionBlock;
otherwise return the removed object.

WARNING: do not add/remove elements while iterating over the receiver.
Iterate over a copy to do this.

o  removeAll

o  removeAllOccurrencesOf: oldObject ifAbsent: anExceptionBlock
Remove oldObject completely from the collection.
If it was not present, return the value of the exceptionBlock;
otherwise return the removed object.

WARNING: do not add/remove elements while iterating over the receiver.
Iterate over a copy to do this.

converting
o  asSet
return the receiver as a set

enumerating
o  do: aBlock
evaluate the block for all elements in the collection.

WARNING: do not add/remove elements while iterating over the receiver.
Iterate over a copy to do this.

o  valuesAndCountsDo: aBlock
evaluate the block for all distinct elements in the collection,
passing both the element and the occurrence count as arguments.

WARNING: do not add/remove elements while iterating over the receiver.
Iterate over a copy to do this.

private
o  initContents
set the contents to be an empty contents array

o  initContents: size
set the contents to be an empty contents array with initial size

queries
o  occurrencesOf: anObject
return how often anObject is in the receiver

o  size
return the number of bag elements



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Sat, 20 Apr 2024 04:41:09 GMT