SinglyLinkedList: The sole Iterator is really ConstIterator.

It behaves the same way as DoublyLinkedList's ConstIterator,
so let's name it the same way for consistency.
This commit is contained in:
Augustin Cavalier
2024-09-04 14:15:20 -04:00
parent 3e6902c3f4
commit df44e515de
17 changed files with 36 additions and 36 deletions
+7 -7
View File
@@ -97,16 +97,16 @@ class SinglyLinkedList {
typedef SinglyLinkedListLink<Element> Link;
public:
class Iterator {
class ConstIterator {
public:
Iterator(const List* list)
ConstIterator(const List* list)
:
fList(list)
{
Rewind();
}
Iterator(const Iterator& other)
ConstIterator(const ConstIterator& other)
{
*this = other;
}
@@ -124,7 +124,7 @@ class SinglyLinkedList {
return element;
}
Iterator& operator=(const Iterator& other)
ConstIterator& operator=(const ConstIterator& other)
{
fList = other.fList;
fNext = other.fNext;
@@ -160,10 +160,10 @@ class SinglyLinkedList {
inline Element* GetNext(Element* element) const;
inline int32_t Size() const;
inline int32_t Count() const;
// O(n)!
inline Iterator GetIterator() const { return Iterator(this); }
inline ConstIterator GetIterator() const { return ConstIterator(this); }
private:
Element *fFirst;
@@ -247,7 +247,7 @@ SINGLY_LINKED_LIST_CLASS_NAME::GetNext(Element* element) const
// Size
SINGLY_LINKED_LIST_TEMPLATE_LIST
int32_t
SINGLY_LINKED_LIST_CLASS_NAME::Size() const
SINGLY_LINKED_LIST_CLASS_NAME::Count() const
{
int32_t count = 0;
for (Element* element = First(); element; element = GetNext(element))
+1 -1
View File
@@ -41,7 +41,7 @@ private:
class PathBlocklist {
public:
typedef SinglyLinkedList<BlockedPath>::Iterator Iterator;
typedef SinglyLinkedList<BlockedPath>::ConstIterator Iterator;
public:
PathBlocklist();
@@ -94,16 +94,16 @@ class SinglyLinkedList {
typedef SinglyLinkedListLink<Element> Link;
public:
class Iterator {
class ConstIterator {
public:
Iterator(const List* list)
ConstIterator(const List* list)
:
fList(list)
{
Rewind();
}
Iterator(const Iterator& other)
ConstIterator(const ConstIterator& other)
{
*this = other;
}
@@ -121,7 +121,7 @@ class SinglyLinkedList {
return element;
}
Iterator& operator=(const Iterator& other)
ConstIterator& operator=(const ConstIterator& other)
{
fList = other.fList;
fNext = other.fNext;
@@ -164,7 +164,7 @@ class SinglyLinkedList {
inline int32 Count() const;
// O(n)!
inline Iterator GetIterator() const { return Iterator(this); }
inline ConstIterator GetIterator() const { return ConstIterator(this); }
private:
Element *fFirst;