summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorMuhammad Zahalqa <m@tryfinally.com>2020-09-06 22:49:36 +0300
committerAndreas Kling <kling@serenityos.org>2020-09-06 21:56:32 +0200
commitad3e6ef344441e0dff06fa7a04909924ea9cc81b (patch)
tree78bd25f89351f0b162f75439d3ccb7f707eb4dad /AK
parentf1a6884a516a73bdba9653914aa5cc93f5280e56 (diff)
downloadserenity-ad3e6ef344441e0dff06fa7a04909924ea9cc81b.zip
AK: SinglyLinkedList use Traits<T>::equals in find
Use Traits<T>::equals for equality checking in search functions instead of operator==
Diffstat (limited to 'AK')
-rw-r--r--AK/SinglyLinkedList.h15
1 files changed, 6 insertions, 9 deletions
diff --git a/AK/SinglyLinkedList.h b/AK/SinglyLinkedList.h
index b12c0d0377..d41e9039d1 100644
--- a/AK/SinglyLinkedList.h
+++ b/AK/SinglyLinkedList.h
@@ -28,6 +28,7 @@
#include <AK/Assertions.h>
#include <AK/StdLibExtras.h>
+#include <AK/Traits.h>
#include <AK/Types.h>
namespace AK {
@@ -35,7 +36,7 @@ namespace AK {
template<typename ListType, typename ElementType>
class SinglyLinkedListIterator {
public:
- SinglyLinkedListIterator() {}
+ SinglyLinkedListIterator() { }
bool operator!=(const SinglyLinkedListIterator& other) const { return m_node != other.m_node; }
SinglyLinkedListIterator& operator++()
{
@@ -76,7 +77,7 @@ private:
};
public:
- SinglyLinkedList() {}
+ SinglyLinkedList() { }
~SinglyLinkedList() { clear(); }
bool is_empty() const { return !head(); }
@@ -152,11 +153,7 @@ public:
bool contains_slow(const T& value) const
{
- for (auto* node = m_head; node; node = node->next) {
- if (node->value == value)
- return true;
- }
- return false;
+ return find(value) != end();
}
using Iterator = SinglyLinkedListIterator<SinglyLinkedList, T>;
@@ -195,12 +192,12 @@ public:
ConstIterator find(const T& value) const
{
- return find([&](auto& other) { return value == other; });
+ return find([&](auto& other) { return Traits<T>::equals(value, other); });
}
Iterator find(const T& value)
{
- return find([&](auto& other) { return value == other; });
+ return find([&](auto& other) { return Traits<T>::equals(value, other); });
}
void remove(Iterator iterator)