Collections and iterators
Description
All collections (data structures) and their iterators (objects that reveal and modify the data in a collection).
Classes:
Name | Description |
---|---|
Collection | Generic collection (pseudo-class). |
MHash | Linear unordered collection with exceptionally fast insertions and removals. |
MImage | 2D matrix collection (of fixed size) of colored pixels. |
MList | Linear ordered collection, similar to MVector, but with more flexible insert/remove. |
MMap | Linear unordered collection that defines a 1-to-1 key-to-value relation. |
MSortList | Linear ordered collection with automatic sorting capability. |
MString | Linear ordered collection of MChar (Unicode-16) elements. |
MVector | Linear ordered collection. |
MWidthList | Linear ordered collection of abstract "widths" with O(lgn) insert/remove complexity. |
Details
A collection is an object, which contains a variable number of other objects (items) of a certain type. Items can be collections too.
Iterators are special objects that can reveal or modify the content of a collection.
Collections organize similar objects for a convenient and efficient usage. A collection is empty if it contains zero items. The number of items is limited only by the available memory.
Elgrint defines 8 types of collections, as seen above (the generic Collection is not a real class). Two of these (MString and MImage) contain items of a predefined type (MChar and MColor respectively). The rest are templates, which can contain items of almost any type.
Each collection has its own unique qualities, which make it most suitable for specific kind of tasks. Choosing not the most suitable collection for each task may result in poor performance.
Each collection type (except for MString) has one or more corresponding iterators to navigate within the collection. Iterator objects are instances of iterator classes, which are child classes of the corresponding collections.
Iterators can be of two kinds - constant (Collection::CIter) and non-constant (Collection::Iter). Constant iterators cannot modify the collection content. It is recommended to use constant iterators whenever possible - they are safer and sometimes more efficient.
Remarks
- All collections use fast (shared) copying mechanism (see Collection) and thus can be passed by value without performance penalty
- All mutator (setter) functions of all collection (except for Collection::setError) return true on success and false on error (memory error or numeric overflow). See also error reporting
- Iterators incur a penalty of O(k) on most mutators (see complexity), where k is the number of iterators owned by the collection. Therefore, iterators should be reset as soon as they are no longer needed (see Collection::CIter::reset)
Let us know
Please Contact us to report any errors on this page, or to suggest any improvements.