From 7008d2f61167277c317608d00693a5e6c26aaa93 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Mon, 31 Oct 2011 21:30:13 +0000 Subject: [PATCH] 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 --- headers/private/kernel/util/DoublyLinkedList.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/headers/private/kernel/util/DoublyLinkedList.h b/headers/private/kernel/util/DoublyLinkedList.h index 50e5fa1281..23216894d3 100644 --- a/headers/private/kernel/util/DoublyLinkedList.h +++ b/headers/private/kernel/util/DoublyLinkedList.h @@ -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