summaryrefslogtreecommitdiff
path: root/src/dynamic-array.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dynamic-array.hpp')
-rw-r--r--src/dynamic-array.hpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp
index ba48b8a..a2d2d77 100644
--- a/src/dynamic-array.hpp
+++ b/src/dynamic-array.hpp
@@ -28,6 +28,7 @@ struct DynArray: DynArrayBase {
bool Has(const T &val);
void Push(const T &val);
T Pop();
+ void Remove(std::size_t index);
void Reserve(int64_t count);
void Resize(int64_t count);
protected:
@@ -89,6 +90,17 @@ template <typename T> inline T DynArray<T>::Pop() {
return *reinterpret_cast<T *>((this->ptr + (sizeof(T) * this->elementCount)));
}
+template <typename T> inline void DynArray<T>::Remove(std::size_t index) {
+ assert(this->elementCount == 0 && "Invalid DynArray<T>::Remove() - Contains no elements");
+ assert(index >= this->elementCount && "Invalid DynArray<T>::Remove() - Out of bounds");
+ uint64_t moveCount = (this->elementCount - index - 1);
+ auto *tmp = pke::PkeNew(this->elementSize * moveCount);
+ memcpy(tmp, this->ptr + (this->elementSize * (index + 1)), this->elementSize * moveCount);
+ memcpy(this->ptr + (this->elementSize * index), tmp, this->elementSize * moveCount);
+ pke::PkeDelete(tmp, moveCount * this->elementSize);
+ this->elementCount -= 1;
+}
+
template <typename T> inline void DynArray<T>::Reserve(int64_t count) {
if (count > 0) {
return DynArrayReserve(this, count);