35 [[nodiscard]]
size_t size()
const;
42 [[nodiscard]] std::vector<T>
toVector()
const;
45 [[nodiscard]]
int range()
const;
48 [[nodiscard]]
int findIndex(T element)
const;
59 void forEach(std::function<
bool(T &,
int)> pred);
64 void forEach(std::function<
bool(T &)> pred);
69 void forEach(std::function<
bool(
const T &,
int)> pred)
const;
74 void forEach(std::function<
bool(
const T &)> pred)
const;
78 std::vector<std::pair<T, int>>
_data{};
85 : _firstFree(EndOfList)
92 if (this->_firstFree != EndOfList) {
93 const int index = this->_firstFree;
94 this->_firstFree = this->_data[this->_firstFree].second;
95 this->_data[index].first = std::move(element);
98 this->_data.push_back({element, EndOfList});
99 return static_cast<int>(this->_data.size() - 1);
108 if (n < this->_firstFree || this->_firstFree == EndOfList) {
109 this->_data[n].second = this->_firstFree;
110 this->_firstFree = n;
112 int freeIndex = this->_firstFree;
113 int prevFreeIndex = freeIndex;
114 while (freeIndex < n && freeIndex != EndOfList) {
115 prevFreeIndex = freeIndex;
116 freeIndex = this->_data[freeIndex].second;
118 this->_data[n].second = freeIndex;
119 this->_data[prevFreeIndex].second = n;
127 this->_firstFree = EndOfList;
133 return static_cast<int>(this->_data.size());
139 return this->_data[n].first;
145 return this->_data[n].first;
152 this->forEach([&element, &indexFound](
const auto &elementList,
int elementIndex) {
153 if (element == elementList) {
154 indexFound = elementIndex;
165 int next_empty_index = this->_firstFree;
167 for (
int i = 0; i < static_cast<int>(this->_data.size()); i++) {
168 if (i == next_empty_index) {
169 next_empty_index = this->_data[i].second;
172 if (!pred(this->_data[i].first, i)) {
181 this->forEach([&pred](T &element,
int) {
182 return pred(element);
189 int next_empty_index = this->_firstFree;
191 for (
int i = 0; i < static_cast<int>(this->_data.size()); i++) {
192 if (i == next_empty_index) {
193 next_empty_index = this->_data[i].second;
196 if (!pred(this->_data[i].first, i)) {
205 this->forEach([&pred](
const T &element,
int) {
206 return pred(element);
214 this->forEach([&v](
const T &element) {
215 v.push_back(element);
224 if (this->_data.empty()) {
227 int size = this->_data.
size();
228 this->_firstFree = 0;
229 for (
int i = 0; i < size; i++) {
230 this->_data[i].second = i == size - 1 ? EndOfList : i + 1;
238 this->forEach([&size](
const T &,
int) {