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

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))

View File

@ -41,7 +41,7 @@ private:
class PathBlocklist {
public:
typedef SinglyLinkedList<BlockedPath>::Iterator Iterator;
typedef SinglyLinkedList<BlockedPath>::ConstIterator Iterator;
public:
PathBlocklist();

View File

@ -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;

View File

@ -625,7 +625,7 @@ BPlusTree::~BPlusTree()
// traversing the tree - a TreeIterator doesn't lock the inode)
mutex_lock(&fIteratorLock);
SinglyLinkedList<TreeIterator>::Iterator iterator
SinglyLinkedList<TreeIterator>::ConstIterator iterator
= fIterators.GetIterator();
while (iterator.HasNext())
iterator.Next()->Stop();
@ -983,7 +983,7 @@ BPlusTree::_UpdateIterators(off_t offset, off_t nextOffset, uint16 keyIndex,
// any time, so we need to protect this loop
MutexLocker _(fIteratorLock);
SinglyLinkedList<TreeIterator>::Iterator iterator
SinglyLinkedList<TreeIterator>::ConstIterator iterator
= fIterators.GetIterator();
while (iterator.HasNext())
iterator.Next()->Update(offset, nextOffset, keyIndex, splitAt, change);

View File

@ -649,7 +649,7 @@ Inode::_RemoveSmallData(bfs_inode* node, small_data* item, int32 index)
memset(item, 0, item->Size());
// update all current iterators
SinglyLinkedList<AttributeIterator>::Iterator iterator
SinglyLinkedList<AttributeIterator>::ConstIterator iterator
= fIterators.GetIterator();
while (iterator.HasNext()) {
iterator.Next()->Update(index, -1);
@ -853,7 +853,7 @@ Inode::_AddSmallData(Transaction& transaction, NodeGetter& nodeGetter,
memset(item, 0, (uint8*)node + fVolume->InodeSize() - (uint8*)item);
// update all current iterators
SinglyLinkedList<AttributeIterator>::Iterator iterator
SinglyLinkedList<AttributeIterator>::ConstIterator iterator
= fIterators.GetIterator();
while (iterator.HasNext()) {
iterator.Next()->Update(index, 1);

View File

@ -542,7 +542,7 @@ BTree::~BTree()
// traversing the tree - a TreeIterator doesn't lock the inode)
mutex_lock(&fIteratorLock);
SinglyLinkedList<TreeIterator>::Iterator iterator
SinglyLinkedList<TreeIterator>::ConstIterator iterator
= fIterators.GetIterator();
while (iterator.HasNext())
iterator.Next()->Stop();

View File

@ -1342,7 +1342,7 @@ Inode::RemoveAttribute(const char* name, bool checkNamespace)
if (checkNamespace && attribute->IsProtectedNamespace())
return B_NOT_ALLOWED;
// look for attribute in cookies
AttrCookieList::Iterator i = fAttrCookies.GetIterator();
AttrCookieList::ConstIterator i = fAttrCookies.GetIterator();
while (i.HasNext()) {
attr_cookie* cookie = i.Next();
if (cookie->current == attribute) {

View File

@ -163,7 +163,7 @@ DirectoryCache::RemoveEntry(const char* name)
{
ASSERT(name != NULL);
SinglyLinkedList<NameCacheEntry>::Iterator iterator
SinglyLinkedList<NameCacheEntry>::ConstIterator iterator
= fNameCache.GetIterator();
NameCacheEntry* previous = NULL;
NameCacheEntry* current = iterator.Next();
@ -277,11 +277,11 @@ DirectoryCache::NotifyChanges(DirectoryCacheSnapshot* oldSnapshot,
MutexLocker _(newSnapshot->fLock);
SinglyLinkedList<NameCacheEntry>::Iterator oldIt
SinglyLinkedList<NameCacheEntry>::ConstIterator oldIt
= oldSnapshot->fEntries.GetIterator();
NameCacheEntry* oldCurrent;
SinglyLinkedList<NameCacheEntry>::Iterator newIt
SinglyLinkedList<NameCacheEntry>::ConstIterator newIt
= newSnapshot->fEntries.GetIterator();
NameCacheEntry* newCurrent = newIt.Next();
while (newCurrent != NULL) {

View File

@ -342,7 +342,7 @@ AttributeIndex::NodeChanged(Node* node, uint32 statFields,
// move the iterators that point to the node to the previous node
if (oldTreeValue != NULL) {
for (IteratorList::Iterator it = iterators.GetIterator();
for (IteratorList::ConstIterator it = iterators.GetIterator();
Iterator* iterator = it.Next();) {
iterator->NodeChangeBegin(node);
}
@ -359,7 +359,7 @@ AttributeIndex::NodeChanged(Node* node, uint32 statFields,
// its place, they will point to it again, otherwise to the node originally
// succeeding it.
if (oldTreeValue != NULL) {
for (IteratorList::Iterator it = iterators.GetIterator();
for (IteratorList::ConstIterator it = iterators.GetIterator();
Iterator* iterator = it.Next();) {
iterator->NodeChangeEnd(node);
}

View File

@ -216,7 +216,7 @@ LastModifiedIndex::NodeChanged(Node* node, uint32 statFields,
return;
// move the iterators that point to the node to the previous node
for (IteratorList::Iterator it = iterators.GetIterator();
for (IteratorList::ConstIterator it = iterators.GetIterator();
Iterator* iterator = it.Next();) {
iterator->NodeChangeBegin(node);
}
@ -231,7 +231,7 @@ LastModifiedIndex::NodeChanged(Node* node, uint32 statFields,
// Move the iterators to the next node again. If the node hasn't changed
// its place, they will point to it again, otherwise to the node originally
// succeeding it.
for (IteratorList::Iterator it = iterators.GetIterator();
for (IteratorList::ConstIterator it = iterators.GetIterator();
Iterator* iterator = it.Next();) {
iterator->NodeChangeEnd(node);
}

View File

@ -214,7 +214,7 @@ SizeIndex::NodeChanged(Node* node, uint32 statFields,
return;
// move the iterators that point to the node to the previous node
for (IteratorList::Iterator it = iterators.GetIterator();
for (IteratorList::ConstIterator it = iterators.GetIterator();
Iterator* iterator = it.Next();) {
iterator->NodeChangeBegin(node);
}
@ -229,7 +229,7 @@ SizeIndex::NodeChanged(Node* node, uint32 statFields,
// Move the iterators to the next node again. If the node hasn't changed
// its place, they will point to it again, otherwise to the node originally
// succeeding it.
for (IteratorList::Iterator it = iterators.GetIterator();
for (IteratorList::ConstIterator it = iterators.GetIterator();
Iterator* iterator = it.Next();) {
iterator->NodeChangeEnd(node);
}

View File

@ -152,7 +152,7 @@ UnpackingLeafNode::RemovePackageNode(PackageNode* packageNode, dev_t deviceID)
// is not sorted)
PackageLeafNode* newestNode = fPackageNodes.Head();
if (isNewest && newestNode != NULL) {
PackageLeafNodeList::Iterator it = fPackageNodes.GetIterator();
PackageLeafNodeList::ConstIterator it = fPackageNodes.GetIterator();
it.Next();
// skip the first one
while (PackageLeafNode* otherNode = it.Next()) {

View File

@ -994,7 +994,7 @@ Volume::_AddPackageContent(Package* package, bool notify)
if (error != B_OK)
RETURN_ERROR(error);
for (PackageNodeList::Iterator it = package->Nodes().GetIterator();
for (PackageNodeList::ConstIterator it = package->Nodes().GetIterator();
PackageNode* node = it.Next();) {
// skip over ".PackageInfo" file, it isn't part of the package content
if (strcmp(node->Name(),

View File

@ -170,7 +170,7 @@ PathBlocklist::MakeEmpty()
BlockedPath*
PathBlocklist::_FindPath(const char* path) const
{
for (PathList::Iterator it = fPaths.GetIterator(); it.HasNext();) {
for (PathList::ConstIterator it = fPaths.GetIterator(); it.HasNext();) {
BlockedPath* blockedPath = it.Next();
if (*blockedPath == path)
return blockedPath;

View File

@ -126,7 +126,7 @@ ARMPagingStructures32Bit::UpdateAllPageDirs(int index,
{
InterruptsSpinLocker locker(sPagingStructuresListLock);
PagingStructuresList::Iterator it = sPagingStructuresList.GetIterator();
PagingStructuresList::ConstIterator it = sPagingStructuresList.GetIterator();
while (ARMPagingStructures32Bit* info = it.Next())
info->pgdir_virt[index] = entry;
}

View File

@ -126,7 +126,7 @@ X86PagingStructures32Bit::UpdateAllPageDirs(int index,
{
InterruptsSpinLocker locker(sPagingStructuresListLock);
PagingStructuresList::Iterator it = sPagingStructuresList.GetIterator();
PagingStructuresList::ConstIterator it = sPagingStructuresList.GetIterator();
while (X86PagingStructures32Bit* info = it.Next())
info->pgdir_virt[index] = entry;
}

View File

@ -67,7 +67,7 @@ VMArea::Init(const char* name, uint32 allocationFlags)
bool
VMArea::IsWired(addr_t base, size_t size) const
{
for (VMAreaWiredRangeList::Iterator it = fWiredRanges.GetIterator();
for (VMAreaWiredRangeList::ConstIterator it = fWiredRanges.GetIterator();
VMAreaWiredRange* range = it.Next();) {
if (range->IntersectsWith(base, size))
return true;
@ -123,7 +123,7 @@ VMArea::Unwire(VMAreaWiredRange* range)
VMAreaWiredRange*
VMArea::Unwire(addr_t base, size_t size, bool writable)
{
for (VMAreaWiredRangeList::Iterator it = fWiredRanges.GetIterator();
for (VMAreaWiredRangeList::ConstIterator it = fWiredRanges.GetIterator();
VMAreaWiredRange* range = it.Next();) {
if (range->implicit && range->base == base && range->size == size
&& range->writable == writable) {
@ -177,7 +177,7 @@ bool
VMArea::AddWaiterIfWired(VMAreaUnwiredWaiter* waiter, addr_t base, size_t size,
uint32 flags)
{
for (VMAreaWiredRangeList::Iterator it = fWiredRanges.GetIterator();
for (VMAreaWiredRangeList::ConstIterator it = fWiredRanges.GetIterator();
VMAreaWiredRange* range = it.Next();) {
if ((flags & IGNORE_WRITE_WIRED_RANGES) != 0 && range->writable)
continue;