27 void quickSort(
int low,
int high,
28 std::function<
bool(
const T&,
const T&)> compare) {
30 int pivotIndex = partition(low, high, compare);
31 quickSort(low, pivotIndex - 1, compare);
32 quickSort(pivotIndex + 1, high, compare);
37 int partition(
int low,
int high,
38 std::function<
bool(
const T&,
const T&)> compare) {
42 for (
int j = low; j < high; j++) {
43 if (compare(data[j], pivot)) {
45 std::swap(data[i], data[j]);
49 std::swap(data[i + 1], data[high]);
57 List(T* Data,
size_t Size) : data(Data), size(Size), capacity(Size) {}
60 List(
const List& other) : size(other.size), capacity(other.capacity) {
61 data =
new T[capacity];
62 for (
size_t i = 0; i < size; ++i) {
63 data[i] = other.data[i];
69 : data(other.data), size(other.size), capacity(other.capacity) {
80 capacity = other.capacity;
81 data =
new T[capacity];
82 for (
size_t i = 0; i < size; ++i) {
83 data[i] = other.data[i];
95 capacity = other.capacity;
103 List(std::initializer_list<T> initList) {
104 for (
const T& value : initList) {
113 void add(
const T& value) {
114 if (size == capacity)
resize();
115 data[size++] = value;
119 if (size == capacity)
resize();
120 data[size++] = std::move(value);
123 void add(std::initializer_list<T> AddList) {
124 for (
auto&& item : AddList) {
125 add(std::move(item));
140 T&
at(
size_t index) {
145 const T&
at(
size_t index)
const {
154 bool empty()
const {
return size == 0; }
160 const void*
GetRawData()
const {
return static_cast<const void*
>(data); }
164 const T*
begin()
const {
return data; }
165 T*
end() {
return data + size; }
166 const T*
end()
const {
return data + size; }
174 for (
size_t i = 0; i < size; ++i) {
188 size_t newCapacity = (capacity == 0) ? 1 : capacity * 2;
193 if (newCapacity <= capacity)
return;
195 T* newData =
new T[newCapacity];
196 for (
size_t i = 0; i < size; ++i) {
197 newData[i] = std::move(data[i]);
201 capacity = newCapacity;
204 void insert(
size_t index,
const T& value) {
206 if (size == capacity)
resize();
208 for (
size_t i = size; i > index; --i) {
209 data[i] = data[i - 1];
218 for (
size_t i = index; i < size - 1; ++i) {
219 data[i] = std::move(data[i + 1]);
223 data[size - 1] = T();
228 void sort(std::function<
bool(
const T&,
const T&)> compare) {
229 quickSort(0, size - 1, compare);
233 for (
size_t i = 0; i < size / 2; ++i) {
234 std::swap(data[i], data[size - 1 - i]);
239 std::swap(data, other.data);
240 std::swap(size, other.size);
241 std::swap(capacity, other.capacity);
245 T*
find(std::function<
bool(
const T&)> predicate) {
246 for (
size_t i = 0; i < size; ++i) {
247 if (predicate(data[i]))
return &data[i];
252 const T*
find(std::function<
bool(
const T&)> predicate)
const {
253 for (
size_t i = 0; i < size; ++i) {
254 if (predicate(data[i]))
return &data[i];
260 for(
int i = 0; i < size; i++)
const void * GetRawData() const
const T * GetData() const
void add(std::initializer_list< T > AddList)
T * find(std::function< bool(const T &)> predicate)
size_t GetByteSize() const
~List()
Frees the backing array.
const T & at(size_t index) const
void resize(size_t newCapacity)
T & operator[](size_t index)
List(List &&other) noexcept
List & operator=(List &&other) noexcept
void sort(std::function< bool(const T &, const T &)> compare)
List & operator=(const List &other)
const T * find(std::function< bool(const T &)> predicate) const
void swap(List &other) noexcept
const T & operator[](size_t index) const
void insert(size_t index, const T &value)
List(std::initializer_list< T > initList)
size_t GetCapacity() const
int32_t indexOf(const T &value)
Root namespace for everything the engine exposes.