template <class T, class HashFn = StdHash<T> >
class ArrayIndex : private MoveableAndDeepCopyOption< ArrayIndex<T, HashFn > >, public AIndex<T, Array<T>, HashFn>
T |
Type or base class of elements stored in Array. There is no common requirement for T. |
HashFn |
Hashing class. Must have defined unsigned operator()(const T& x) method returning hash value for elements. Defaults to StdHash<T> which requires unsigned GetHashValue(const T&) function returning hash value of elements to be defined. |
Array flavor of index. Inherits most of its functionality from AIndex and adds only members specific for its flavor.
Like any other NTL container, ArrayIndex is a moveable type with pick and optional deep copy transfer semantics. Optional deep copy operator is inherited from AIndex class. Pick operator is implicitly defined by composition.
Constructor and Assignment Detail
|
|
ArrayIndex()
Constructor. Constructs an empty ArrayIndex.
ArrayIndex(ArrayIndex&& s)
Pick constructor.
ArrayIndex(const ArrayIndex& s, int)
Optional deep copy constructor.
Requires T to have deep copy constructor or optional deep copy constructor.
explicit ArrayIndex(Array<T>&& s)
Pick constructor from Array.
ArrayIndex(const Array<T>& s, int)
Deep-copy constructs ArrayIndex from Array.
Requires T to have deep copy constructor or optional deep copy constructor.
ArrayIndex& operator=(Array<T>&& x)
Pick assignment from Array.
ArrayIndex& operator=(ArrayIndex<T>&& x)
Pick assignment.
ArrayIndex(std::initializer_list<T> init)
C++ 11 initialization.
T& Add(const T& x, unsigned _hash)
Adds a new element with a precomputed hash value. The precomputed hash value must be the same as the hash value that would be the result of HashFn. The benefit of using a precomputed hash value is that sometimes you can compute hash-value as the part of an other process, like fetching a string from an input stream. This method has to be reimplemented in ArrayIndex (using simple forwarding) due to overloading of Add in other forms. Returns a reference to the element.
Requires T to have deep copy constructor.
Invalidates iterators to the ArrayIndex.
|
_hash |
Precomputed hash value. |
T& Add(const T& x)
Adds a new element to Index. This method has to be reimplemented in ArrayIndex (using simple forwarding) due to overloading of Add in other forms. Returns a reference to the element.
Requires T to have deep copy constructor.
Invalidates iterators to the ArrayIndex.
T& Set(int i, const T& x, unsigned _hash)
Replaces the element at the specified position with a new element with the specified value, using a precomputed hash-value. Speed of this operation depends on the total number of elements with the same value as the specified one in ArrayIndex. This method has to be reimplemented in ArrayIndex (using simple redirection) due to overloading of Set in other forms. Returns a reference to the element.
Requires T to have deep copy constructor.
Invalidates iterators to the ArrayIndex.
|
_hash |
Precomputed hash value. |
T& Set(int i, const T& x)
Replaces element at specified position with new element with specified value. Speed of this operation depends on the total number of elements with the same value as the specified one in ArrayIndex. This method has to be reimplemented in ArrayIndex (using simple redirection) due to overloading of Set in other forms. Returns a reference to the element.
Requires T to have deep copy constructor.
Invalidates iterators to the ArrayIndex.
T& Add(T *newt, unsigned _hash)
Adds a new element created on the heap to the ArrayIndex using a precomputed hash value. The element is specified by a pointer to the object. ArrayIndex takes over ownership of the pointed element. This variant allows the use of an ArrayIndex as a polymorphic container, because the type of the added element can be either T or a type derived from T. No constructor is applied. Returns a reference to the element.
|
newt |
Element created on the heap. |
T& Add(T *newt)
Adds a new element to the ArrayIndex. The element is specified by a pointer to the object. ArrayIndex takes over ownership of the pointed element. This variant allows the use of an ArrayIndex as a polymorphic container, because the type of the added element can be either T or a type derived from T. No constructor is applied. Returns a reference to the element.
T& Set(int i, T *newt, unsigned _hash)
Replaces the element at the specified position by an element previously created on the heap. ArrayIndex takes over ownership of the element. Returns a reference to the element.
|
newt |
New element created on heap. |
T& Set(int i, T *newt)
Replaces the element at the specified position by an element previously created on the heap. ArrayIndex takes over ownership of the element. Returns a reference to the element.
|
newt |
New element created on heap. |
|