from Types.hpp:444
class Vector
{
public:
Vector()
{
clear();
}
T& operator[](uint16_t idx)
{
return _elem[idx];
}
const T& operator[](uint16_t idx) const
{
return _elem[idx];
}
void add(T e)
{
assert(_size < capacity && "Vector capacity exceeded");
if (_size < capacity)
{
_elem[_size++] = e;
}
}
void remove(T e)
{
for (int i = 0; i < _size; i++)
{
if (_elem[i] == e)
{
for (int j = i; j < _size && j < capacity - 1; j++)
{
_elem[j] = _elem[j + 1];
}
_size--;
}
}
}
T removeAt(uint16_t index)
{
T tmp;
if (index < _size)
{
tmp = _elem[index];
for (int i = index; i < _size; i++)
{
_elem[i] = _elem[i + 1];
}
_size--;
}
return tmp;
}
T quickRemoveAt(uint16_t index)
{
T tmp;
if (index < _size)
{
tmp = _elem[index];
_size--;
if (index < _size)
{
_elem[index] = _elem[_size];
}
}
return tmp;
}
void reverse()
{
uint16_t a = 0;
uint16_t b = _size;
for (; a < --b; a++)
{
T tmp = _elem[a];
_elem[a] = _elem[b];
_elem[b] = tmp;
}
}
bool contains(T elem)
{
for (uint16_t i = 0; i < _size; i++)
{
if (elem == _elem[i])
{
return true;
}
}
return false;
}
uint16_t size() const
{
return _size;
}
bool isEmpty() const
{
return _size == 0;
}
uint16_t maxCapacity() const
{
return capacity;
}
void clear()
{
_size = 0;
}
private:
T _elem[capacity];
uint16_t _size;
};