BiVector
template <class T>
class BiVector
|
T |
Type of elements stored in the BiVector. T is required to be moveable and must have either deep copy constructor, pick constructor or default constructor. |
Vector flavor of bidirectional container. Allows adding elements at both sides of sequence in constant amortized time.
Like any other NTL container, BiVector is a moveable type with pick and optional deep copy transfer semantics. Calling methods of picked a BiVector is logic error with the exceptions of
void operator=(pick_ Vector& v)
void operator<<=(const Vector& v) (defined using DeepCopyOptionTemplate)
void Clear()
bool IsPicked() const
Optional deep copy is implemented through DeepCopyOptionTemplate macro.
Members
T& AddHead()
Adds a new default constructed element at the head of the BiVector. The new element will be at position 0.
Requires T to have default constructor.
Invalidates iterators and references to the BiVector.
|
Return value |
Reference to the newly added default constructed element. |
T& AddTail()
Adds a new default constructed element at the tail of the BiVector. The new element will be at position GetCount() - 1.
Requires T to have default constructor.
Invalidates iterators and references to the BiVector.
|
Return value |
Reference to the newly added default constructed element. |
void AddHead(const T& x)
Adds a new element with the specified value at the head of the BiVector. The new element will be at position 0.
Requires T to have deep copy constructor.
Invalidates iterators and references to the BiVector.
|
x |
The value that is copied to the newly created element. |
void AddTail(const T& x)
Adds a new element with the specified value at the tail of the BiVector. The new element will be at position GetCount() - 1.
Requires T to have deep copy constructor.
Invalidates iterators and references to the BiVector.
|
x |
The value that is copied to the newly created element. |
void AddHeadPick(pick_ T& x)
Adds a new element at the head of the BiVector and picks value of the parameter. The new element will be at position 0.
Requires T to have pick constructor.
Invalidates iterators and references to the BiVector.
|
x |
Source instance of T that is to be picked. |
void AddTailPick(pick_ T& x)
Adds a new element at the tail of the BiVector and picks value of the parameter. The new element will be at position GetCount() - 1.
Requires T to have pick constructor.
Invalidates iterators and references to the BiVector.
|
x |
Source instance of T that is to be picked. |
T& Head()
Returns a reference to the head of the BiVector. Same as operator[](0).
|
Return value |
Reference to the head of the BiVector. |
T& Tail()
Returns a reference to the tail of the BiVector. Same as operator[](GetCount() - 1).
|
Return value |
Reference to the tail of the BiVector. |
const T& Head() const
Returns a reference to the head of the BiVector. Same as operator[](0).
|
Return value |
Constant reference to the head of the BiVector. |
const T& Tail() const
Returns a reference to the tail of the BiVector. Same as operator[](GetCount() - 1).
|
Return value |
Constant reference to the tail of the BiVector. |
void DropHead()
Removes the element at the head of the BiVector.
Invalidates iterators and references to the BiVector.
void DropTail()
Removes the element at the tail of the BiVector.
Invalidates iterators and references to the BiVector.
T& operator[](int i)
Returns a reference to the element at the specified position.
|
i |
Position of the element. |
|
Return value |
Reference to the element. |
const T& operator[](int i) const
Returns a reference to the element at the specified position.
|
i |
Position of the element. |
|
Return value |
Constant reference to the element. |
int GetCount() const
Returns the number of elements in the BiVector.
|
Return value |
Actual number of elements. |
bool IsEmpty() const
Tests whether the BiVector is empty. Same as GetCount() == 0.
|
Return value |
true if Vector is empty, false otherwise. |
void Clear()
Removes all elements from the BiVector.
void Shrink()
Minimizes memory consumption of the BiVector by minimizing capacity.
void Reserve(int n)
Reserves capacity. If required capacity is greater than the current capacity, capacity is increased to the required value.
int GetAlloc() const
Returns current capacity of the BiVector.
|
Return value |
Capacity of the BiVector. |
friend BiVector& operator<<(BiVector& b, const T& x)
Operator replacement of void AddTail(const T&x). By returning a reference to the BiVector it allows adding more elements in a single expression, thus e.g. allowing to construct a temporary BiVector as part of an expression like Foo(BiVector<int>() << 1 << 2 << 4).
Requires T to have deep copy constructor.
Invalidates iterators and references to the BiVector.
|
x |
The value that is copied to the newly created element. |
|
Return value |
Reference to the BiVector (that is *this). |
friend BiVector& operator>>(const T& x, BiVector& b)
Operator replacement of void AddHead(const T&x). By returning a reference to the BiVector it allows adding more elements in a single expression, thus e.g. allowing to construct a temporary BiVector as part of an expression like Foo(1 >> (2 >> BiVector<int>())).
Requires T to have deep copy constructor.
Invalidates iterators and references to the BiVector.
|
x |
The value that is copied to the newly created element. |
|
Return value |
Reference to BiVector (that is *this). |
void Serialize(Stream& s)
Serializes content of the BiVector to/from the Stream. Works only if NTL is used as part of UPP.
Requires T to have serialization operator defined.
bool IsPicked()
Default constructor. Constructs an empty BiVector.
~BiVector()
Destructor. Invokes the destructor of every element in the BiVector.
BiVector(pick_ BiVector& src)
Pick constructor. Transfers source BiVector in low constant time, but destroys it by picking.
void operator=(pick_ BiVector& src)
Pick operator. Transfers source BiVector in low constant time, but destroys it by picking.
bool IsPicked()
Returns true if BiVector is in picked state.
|
Return value |
true if BiVector is in picked state, false otherwise. |
BiVector(const BiVector& src, int)
Optional deep copy constructor.
Requires T to have deep copy constructor or optional deep copy constructor.
typedef T ValueType
Typedef of T for use in templated algorithms.
typedef IIterator<BiVector> Iterator
Iterator type.
typedef ConstIIterator<BiVector> ConstIterator
Constant iterator type.
ConstIterator Begin() const
Returns a constant iterator to the first element in the BiVector.
ConstIterator End() const
Returns a constant iterator to the position just beyond the last element in the BiVector.
ConstIterator GetIter(int pos) const
Returns a constant iterator to the element at the specified position. Same as Begin() + i. The benefit of this method is that pos is range checked in debug mode.
Iterator Begin()
Returns a non-constant iterator to the first element in the BiVector.
Iterator End()
Returns non-constant iterator to the position just beyond the last element in the BiVector.
Iterator GetIter(int pos)
Returns a non-constant iterator to the element at the specified position. Same as Begin() + pos. The benefit of this method is that pos is range checked in debug mode.
friend void Swap(BiVector& a, BiVector& b)
Specialization of the generic Swap for BiVectors. Swaps BiVectors in low constant time operation.
|
a |
First BiVector to swap. |
|
b |
Second BiVector to swap. |
|