aboutsummaryrefslogtreecommitdiff
path: root/backend/ListIterator.hpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-31 14:14:09 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-31 14:14:09 +0100
commitf8d8d7499ba4433678db2a68fb1cae74448ca31e (patch)
treefc96bef89fc3206277d1fcf1e3df5ad733b7e652 /backend/ListIterator.hpp
parenta0e14fa424494ed35da1bd6e5e54bb36178259a7 (diff)
make ListIterator continue working on a changing list
Diffstat (limited to 'backend/ListIterator.hpp')
-rw-r--r--backend/ListIterator.hpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/backend/ListIterator.hpp b/backend/ListIterator.hpp
index b6b7a36..30a556f 100644
--- a/backend/ListIterator.hpp
+++ b/backend/ListIterator.hpp
@@ -3,16 +3,16 @@
#include "ListIterator.h"
template <typename T>
-ListRange<T>::ListRange(const List<T> & list) : list(list) { }
+ListRange<T>::ListRange(List<T> & list) : list(list) { }
template <typename T>
-ListIterator<T> ListRange<T>::begin() const {
- return { this->list, 0 };
+ListIterator<T> ListRange<T>::begin() {
+ return { this->list.tail };
}
template <typename T>
-ListIterator<T> ListRange<T>::end() const {
- return { this->list, this->list.size() };
+ListIterator<T> ListRange<T>::end() {
+ return { this->list.head };
}
template <typename T>
@@ -21,21 +21,27 @@ size_t ListRange<T>::size() const {
}
template <typename T>
-ListIterator<T>::ListIterator(const List<T> & list, size_t index) : list(list), index(index) { }
+ListIterator<T>::ListIterator(ListLink<T> * & here) {
+ this->here = here;
+ if (this->here != nullptr)
+ this->next = this->here->next;
+}
template <typename T>
-T ListIterator<T>::operator * () const {
- return this->list[this->index];
+T & ListIterator<T>::operator * () const {
+ return this->here->value;
}
template <typename T>
ListIterator<T> & ListIterator<T>::operator ++ () {
- this->index++;
+ this->here = this->next;
+ if (this->here != nullptr)
+ this->next = this->here->next;
return *this;
}
template <typename T>
bool ListIterator<T>::operator != (const ListIterator<T> & rhs) const {
- return this->index < rhs.index;
+ return this->here != nullptr;
}