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.5 date: 2021/01/20 15:40:16
user: cg
file: SmallBag.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

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

copyright

COPYRIGHT (c) 2013 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

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
(comment from inherited method)
remove all objects from the receiver collection (i.e. make it empty).
Returns the receiver.

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

Usage example(s):

     |b|

     b := Bag new.
     b add:1; add:2; add:3; add:1; add:1.
     b asSet.

enumerating
o  do: aBlock
evaluate the block for all elements in the collection.
Notice: the order of evaluation is not defined (and may appear random, actually)

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

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

o  initContentsForIdentity: 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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:55:04 GMT