bonefish+mmlr:

Add a DoublyLinkedList::Contains() method to check if a list contains a certain
element.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43043 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz 2011-10-31 21:30:13 +00:00
parent a287d1c156
commit 7008d2f611

View File

@ -359,6 +359,9 @@ public:
inline Element* GetPrevious(Element* element) const;
inline Element* GetNext(Element* element) const;
inline bool Contains(Element* element) const;
// O(n)!
inline int32 Count() const;
// O(n)!
@ -617,6 +620,20 @@ DOUBLY_LINKED_LIST_CLASS_NAME::GetNext(Element* element) const
return result;
}
DOUBLY_LINKED_LIST_TEMPLATE_LIST
bool
DOUBLY_LINKED_LIST_CLASS_NAME::Contains(Element* _element) const
{
for (Element* element = First(); element; element = GetNext(element)) {
if (element == _element)
return true;
}
return false;
}
// Count
DOUBLY_LINKED_LIST_TEMPLATE_LIST
int32