33 using Comparer =
int (*)(
const Element& lhs,
const Element& rhs);
35 template <
bool is_const>
class Iterator :
public std::iterator<std::random_access_iterator_tag, Element>
38 using V =
typename std::conditional<is_const, const Vector, Vector>::type;
39 using E =
typename std::conditional<is_const, const Element, Element>::type;
43 Iterator(
V& vector,
unsigned index) : vector(vector), index(index)
69 return &vector == &rhs.vector && index == rhs.index;
93 Vector(
unsigned int initialCapacity = 10,
unsigned int capacityIncrement = 10);
99 bool contains(
const Element& elem)
const;
101 int indexOf(
const Element& elem)
const;
109 unsigned int size()
const;
110 void copyInto(Element* array)
const;
111 bool add(
const Element& obj)
124 bool setSize(
unsigned int newSize);
126 const Element&
elementAt(
unsigned int index)
const;
128 const void remove(
unsigned int index);
130 bool setElementAt(
const Element& obj,
unsigned int index);
131 const Element&
get(
unsigned int index)
const 136 const Element&
operator[](
unsigned int index)
const override;
137 Element&
operator[](
unsigned int index)
override;
147 if(
_data !=
nullptr) {
155 other._data =
nullptr;
158 other._increment = 0;
166 return Iterator<false>(*
this, 0);
171 return Iterator<false>(*
this,
count());
176 return Iterator<true>(*
this, 0);
179 Iterator<true>
end()
const 181 return Iterator<true>(*
this,
count());
200 if(
_data ==
nullptr) {
212 if(
_data !=
nullptr) {
220 if(
_data ==
nullptr) {
224 for(
unsigned int i = 0; i <
_size; i++) {
247 if(array !=
nullptr) {
248 for(
unsigned int i = 0; i <
_size; i++) {
249 array[i] = *
_data[i];
260 return *
_data[index];
274 for(
unsigned int i = 0; i <
_size; i++) {
275 if(*
_data[i] == elem) {
304 unsigned int i =
_size;
308 if(*
_data[i] == elem) {
346 Element** temp =
new Element*[newCapacity];
348 if(temp ==
nullptr) {
353 memcpy(temp,
_data,
sizeof(Element*) *
_size);
373 Element* newItem =
new Element(obj);
374 if(newItem ==
nullptr) {
378 for(
unsigned int i = index; i <=
_size; i++) {
379 Element* tmp =
_data[i];
400 for(
unsigned int i = 0; i <
_size; i++) {
409 for(
unsigned int i = 0; i <
_size; i++) {
410 if(*
_data[i] == obj) {
428 for(i = index + 1; i <
_size; i++) {
451 if(newSize <
_size) {
452 for(
unsigned int i = newSize; i <
_size; i++) {
465 Element** temp =
new Element*[
_size];
466 if(temp ==
nullptr) {
470 for(
unsigned int i = 0; i <
_size; i++) {
495 return *
_data[index];
500 for(
unsigned j = 1; j <
_size; j++)
504 for(i = j - 1; (i >= 0) && compareFunction(*
_data[i], *key) > 0; i--)
const Element & lastElement() const
Definition: WVector.h:288
Iterator operator++(int)
Definition: WVector.h:53
int lastIndexOf(const Element &elem) const
Definition: WVector.h:297
E & operator*() const
Definition: WVector.h:82
void trimToSize()
Definition: WVector.h:462
bool contains(const Element &elem) const
Definition: WVector.h:240
unsigned int _increment
Definition: WVector.h:190
int indexOf(const Element &elem) const
Definition: WVector.h:272
Iterator< false > end()
Definition: WVector.h:169
const Element & elementAt(unsigned int index) const
Definition: WVector.h:254
Definition: Countable.h:19
Vector class template.
Definition: WVector.h:30
const Vector< Element > & operator=(const Vector< Element > &rhv)
Definition: WVector.h:139
Element ** _data
Definition: WVector.h:191
unsigned int capacity() const
Definition: WVector.h:235
const void remove(unsigned int index)
Definition: WVector.h:392
bool ensureCapacity(unsigned int minCapacity)
Definition: WVector.h:339
unsigned int _capacity
Definition: WVector.h:189
bool operator!=(const Iterator &rhs) const
Definition: WVector.h:72
bool insertElementAt(const Element &obj, unsigned int index)
Definition: WVector.h:359
Element & operator*()
Definition: WVector.h:77
bool add(const Element &obj)
Definition: WVector.h:111
bool isEmpty() const
Definition: WVector.h:283
void removeElementAt(unsigned int index)
Definition: WVector.h:418
Iterator & operator++()
Definition: WVector.h:47
unsigned int count() const override
Definition: WVector.h:105
const Vector< Element > & operator=(const Vector< Element > &&other) noexcept
Definition: WVector.h:145
bool setSize(unsigned int newSize)
Definition: WVector.h:445
void sort(Comparer compareFunction)
Definition: WVector.h:498
Iterator< false > begin()
Definition: WVector.h:164
typename std::conditional< is_const, const Element, Element >::type E
Definition: WVector.h:39
bool removeElement(const Element &obj)
Definition: WVector.h:407
bool operator==(const Iterator &rhs) const
Definition: WVector.h:67
Iterator< true > end() const
Definition: WVector.h:179
void size_t const void * key
Definition: blake2s.h:33
void copyFrom(const Vector &rhv)
Definition: WVector.h:210
~Vector()
Definition: WVector.h:229
void removeAllElements()
Definition: WVector.h:397
int(*)(const Parameter &lhs, const Parameter &rhs) Comparer
Definition: WVector.h:33
Iterator(const Iterator &)=default
unsigned int _size
Definition: WVector.h:188
bool setElementAt(const Element &obj, unsigned int index)
Definition: WVector.h:435
void clear()
Definition: WVector.h:117
const Element & operator[](unsigned int index) const override
Definition: WVector.h:481
Iterator operator+=(size_t distance)
Definition: WVector.h:60
const Element & firstElement() const
Definition: WVector.h:263
Vector(unsigned int initialCapacity=10, unsigned int capacityIncrement=10)
Definition: WVector.h:194
Iterator< true > begin() const
Definition: WVector.h:174
unsigned int size() const
Definition: WVector.h:316
bool addElement(const Element &obj)
Definition: WVector.h:321
Iterator(V &vector, unsigned index)
Definition: WVector.h:43
typename std::conditional< is_const, const Vector, Vector >::type V
Definition: WVector.h:38
void copyInto(Element *array) const
Definition: WVector.h:245