26template <
class T,
unsigned int fixedBufferSize = 32>
class WEMVector
37 inline unsigned int num()
const
42 inline T*
at(
unsigned int pos)
const
44 return (pos < _length) ? _block[pos] :
nullptr;
59 return at(_length - 1);
71 virtual void swap(
unsigned int p1,
unsigned int p2);
101 unsigned int _length;
103 unsigned int _capacity;
123 _block = _fixedBuffer;
125 if (init > _capacity) {
127 _block =
new T*[_capacity];
133 *
this = std::move(
other);
136template <
class T,
unsigned int fixedBufferSize>
139 _length =
other._length;
141 _capacity =
other._capacity;
145 _block = _fixedBuffer;
146 for (
auto i = 0u;
i < _length; ++
i) {
147 _fixedBuffer[
i] =
other._fixedBuffer[
i];
151 _block =
other._block;
169 if (_block != _fixedBuffer) {
176 _block = _fixedBuffer;
183 for (
unsigned int i = 0;
i < _length;
i++) {
194 reserve(_capacity * 2);
202 if (_length == _capacity) {
205 _block[_length] =
elem;
215 _block[index] =
elem;
222 if (_length == _capacity) {
225 _block[_length] =
elem;
239template <
class T,
unsigned int fixedBufferSize>
256 if (pos != _length - 1) {
257 swap(pos, _length - 1);
276 for (
unsigned int i = 0;
i < _length;
i++) {
277 if (_block[
i] ==
elem) {
278 pos =
static_cast<int>(
i);
289 const int pos = lookup(
elem);
291 deleteAt(
static_cast<unsigned int>(pos));
300 const int pos = lookup(
elem);
302 for (
unsigned int i =
static_cast<unsigned int>(pos);
i < _length - 1;
i++) {
303 _block[
i] = _block[
i + 1];
314 if (init <= _capacity) {
320 for (
unsigned int i = 0;
i < _length;
i++) {
323 if (_block != _fixedBuffer) {
Dynamic templated vector.
virtual void clear()
Clears all internal pointers.
T * last()
Returns the last element.
WEMVector(unsigned int init=0)
Standard constructor.
WEMVector(WEMVector &&other) noexcept
virtual void replace(T *elem, unsigned int pos)
Replaces the given position with the given element.
const T * first() const
Returns the first element.
WEMVector & operator=(WEMVector &&other) noexcept
virtual void destroy()
Deletes all elements in this vector.
virtual unsigned int append(T *elem)
Appends the given element to back of this vector.
virtual void expand()
Grow vector, add extra block of size BLOCKSIZE.
T * at(unsigned int pos) const
Returns the element at the given position or returns NULL if out of range.
unsigned int num() const
Returns the number of elements in this vector.
virtual int removeUnSwapped(T *elem)
Deletes the element given by its pointer. Keeps the order of the elements!
virtual int lookup(T *elem) const
Searches for the given element in this vector and returns its position.
void resize(unsigned int newSize)
Resizes the vector to the given number of elements.
virtual void swap(unsigned int p1, unsigned int p2)
Swaps the two elements given by their indices in this vector.
virtual void deleteAt(unsigned int pos)
Deletes the element at the given position.
virtual void set(unsigned int pos, T *elem)
Sets the given element at the given position.
const T * last() const
Returns the last element.
virtual int remove(T *elem)
Deletes the element given by its pointer.
virtual unsigned int appendUnsafe(T *elem)
Append element to back of vector, don't check on element being non-NULL.
virtual void deleteLast()
Deletes the last element of this vector.
virtual ~WEMVector()
Standard destructor.
T * first()
Returns the first element.
void reserve(unsigned int init)
Reserves init elements; copies old ones if existing.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.