Reference » Collections and iterators » MVector

Elgrint::MVector<T> class

Declared in MVector.h


Linear ordered collection.


Base class: Collection

Template parameters:

Name Description

The type of any element in MVector. Must have a public copy constructor and a public destructor. If you use setCntQuick, then T also requires a default constructor, and if you use sort, then T must also define a binary operator<, which determines the sorting order.


Name Description
CIter Constant iterator for MVector.
Iter Non-constant iterator for MVector. The usage is identical to that of CIter, except for the regular differences between constant and non-constant iterators, as described in Collection::Iter.


Name Description
MVector(n,x) Init constructor. Creates a vector, which contains n copies of x.
MVector(v,startPos,endPos) Init constructor. Creates a vector, filled with elements of v in the [startPos..endPos) range.
MVector(x) Conversion constructor. Creates a vector, which contains a single element - a copy of x.


Name Description
_getCRef(pos) Returns a constant reference to the element at pos.
_getRef(pos) Returns a non-constant reference to the element at pos.
append(v,startPos,endPos) Appends all elements of v in the [startPos..endPos) range to this vector.
append(x) Appends a copy of x to the end of this vector in O(1) average time complexity.
disownIterators() Resets all iterators owned by this vector and returns true.
moveIterators(src,dst) Moves all iterators from position src to position dst.
popBack(n) Removes up to n elements from the tail of the vector.
set(atPos,newVal) Changes the value of element atPos to newVal.
setCapacity(n,optimizeCapacity) Makes sure that the vector's capacity (see getCapacity) is at least n elements.
setCnt(n,x) Makes sure that the vector contains exactly n elements.
setCntQuick(n) Makes sure that the vector contains exactly n elements, but is more efficient for plain types than setCnt.
setUserValue(val) Sets the "user value", associated with this vector (see getUserValue).
sort() Sorts all the elements in the vector in ascending order, according to operator< of type T.


Name Description
get(pos) Returns a copy of a vector element at pos.
getCapacity() Returns the number of elements that the vector can contain without any additional memory allocation.
getLast() Returns a copy of the last item in the vector.
getUserValue() Returns the current user value, associated with the vector.
hasIterators(ignoreCIters) Indicates the existence of iterators owned by this vector.

Static functions:

Name Description
getMaxUserValue() Returns the maximum possible user value (see getUserValue).


MVector is the simplest and the most useful collection - an encapsulation of a dynamic array data structure. All other collections are based on MVector (directly or indirectly).

'MVector' allows inserting or removing items only at the end (using append and popBack respectively). Both operations work at O(1) amortized time complexity.

The existing items (anywhere in the vector, not just at the end) can be extracted with get and modified with set in strict O(1) complexity.

The _getCRef and _getRef functions can be used instead of get and set - they are usually more efficient, though always less safe.

Another alternative is to use iterators - they provide a well-balanced compromise between efficiency and safety.

The existing items can also be sorted using sort.



Let us know

Please Contact us to report any errors on this page, or to suggest any improvements.

Miranor Home | About Miranor | About Elgrint | Create account | Login | Account settings | Contact Us | Privacy Policy | Site map

© Copyright 2014 by Miranor. All rights reserved. By using this site you agree to the Terms of Use.

Page last updated on August 10th, 2014.