11.3: Collection Implementations

Pharo by Example 5.0 · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-SA 3.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    11.3: Collection Implementations

    Some collection classes categorized by implementation technique.
    Figure \(\PageIndex{1}\): Some collection classes categorized by implementation technique.

    These categorizations by functionality are not our only concern; we must also consider how the collection classes are implemented. As shown in Figure \(\PageIndex{1}\), five main implementation techniques are employed.

    • Arrays store their elements in the (indexable) instance variables of the collection object itself; as a consequence, arrays must be of a fixed size, but can be created with a single memory allocation.
    • OrderedCollections and SortedCollections store their elements in an array that is referenced by one of the instance variables of the collection. Consequently, the internal array can be replaced with a larger one if the collection grows beyond its storage capacity.
    • The various kinds of set and dictionary also reference a subsidiary array for storage, but use the array as a hash table. Bags use a subsidiary Dictionary, with the elements of the bag as keys and the number of occurrences as values.
    • LinkedLists use a standard singly-linked representation.
    • Intervals are represented by three integers that record the two endpoints and the step size.

    In addition to these classes, there are also weak variants of Array, Set and of the various kinds of dictionary. These collections hold onto their elements weakly, i.e., in a way that does not prevent the elements from being garbage collected. The Pharo virtual machine is aware of these classes and handles them specially.


    This page titled 11.3: Collection Implementations was last modified on Sat, 19 Dec 2020 08:13:41 GMT and is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by via source content that was edited to the style and standards of the LibreTexts platform.