From 1787d94907f8d619c85a43bf52a7e60a194c2b28 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Mon, 4 Apr 2022 00:19:31 +0300 Subject: [PATCH] AK: Add begin_from(V&) APIs to IntrusiveRedBlackTree This method exploits the fact that the values themselves hold the tree pointers, and as a result this let's us skip the O(logn) traversal down to the matching Node for a Key-Value pair. --- AK/IntrusiveRedBlackTree.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AK/IntrusiveRedBlackTree.h b/AK/IntrusiveRedBlackTree.h index 5bc0f79ec0..1a40804536 100644 --- a/AK/IntrusiveRedBlackTree.h +++ b/AK/IntrusiveRedBlackTree.h @@ -117,11 +117,13 @@ public: Iterator begin() { return Iterator(static_cast(this->m_minimum)); } Iterator end() { return {}; } Iterator begin_from(K key) { return Iterator(static_cast(BaseTree::find(this->m_root, key))); } + Iterator begin_from(V& value) { return Iterator(&(value.*member)); } using ConstIterator = BaseIterator; ConstIterator begin() const { return ConstIterator(static_cast(this->m_minimum)); } ConstIterator end() const { return {}; } ConstIterator begin_from(K key) const { return ConstIterator(static_cast(BaseTree::find(this->m_rootF, key))); } + ConstIterator begin_from(V const& value) const { return Iterator(&(value.*member)); } bool remove(K key) {