Containers

The standard library provides a number of containers, that can store collections of other elements. They are implemented as parameterized types, meaning that the system generates concrete types for different types. These types are not immediately related to each other. That means that the type Array<Base> is not convertible to Array<Derived> easily. Due to the implementation of the types in C++, most containers are, however, derived from a common base class. For example, both Array<Str> and Array<Int> inherit from ArrayBase. The base classes are generally not very interesting, as they only implement the part of the interface that is the same regardless of the type stored in the container.

In the remainder of this document, the following notation is used for generic types:

All containers in the standard library have the following members:

The types below are generally usable in C++ as well, but there are some minor differences in the interfaces due to how the integration between C++ and Storm works.

Array

The type core.Array<T> (T[] in Basic Storm) is an array of the type T. Elements can thus be accessed by index using the [] operator. Dynamically grows to fit the elements, but does not automatically shrink.

It has the following members:

Queue

The type core.Queue<T> is queue of elements of the type T. Dynamically grows to fit the elements, but does not automatically shrink.

It has the following members:

Priority Queue

The type core.PQueue<C> is a priority queue of elements of type C. Uses the < operator of the type to compare elements and extract the largest one. It is also possible to create a PQueue with a custom predicate function that is used instead of the default < operator, or for types without a < operator. It is implemented as a heap internally, and returns the largest element first.

It is not possible to iterate through elements in the priority queue.

It has the following members:

Hash Map

The type core.Map<H, T> (H->T in Basic Storm) is a hash table with keys of type H and values of type T. As such, elements are not ordered in any particular way when iterating through the container. Automatically grows to fit the elements, but does not shrink automatically unless cleared.

Elements can be accessed in any of the following ways:

There is also a type RefMap<O, T> (O&->T in Basic Storm) that is identical to Map<H, T> except that it always uses object identity to identify objects. The RefMap type can thus not use value types as keys.

Hash Set

The type core.Set<H> is a hash table with keys of type H. The interface is similar to Map, but the functionaliy is reduced since there are no values associated with the keys. As such, the remaining ones are:

There is also a type RefSet<O> that is identical to Map<H, T> except that it always uses object identity to identify objects. It can thus not use value types as keys.

Weak Hash Set

The type core.WeakSet<A> is a weak set of actors. The actors are compared based on their identity. Since the set is weak, elements that are added to the set are not kept alive unless other parts of the system refer to the actors. As such, a WeakSet is useful to keep track of registered callbacks, but to have them automatically de-registered whenever they are no longer used elsewhere. Note, however, that finalization and removal from a WeakSet is not guaranteed to happen quickly, and objects may thus linger for a while after all non-weak references have disappeared.

In contrast to most other containers, the WeakSet may automatically shrink its storage when enough objects have been removed.

The interface to WeakSet is fairly simple: