diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-04-04 00:19:31 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-04 00:16:11 +0200 |
commit | 1787d94907f8d619c85a43bf52a7e60a194c2b28 (patch) | |
tree | 93a1a64c643204f463cde8f1fb189a9d8e260147 /AK | |
parent | 30e6b313b4095473765b443370794ef88e071f27 (diff) | |
download | serenity-1787d94907f8d619c85a43bf52a7e60a194c2b28.zip |
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.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/IntrusiveRedBlackTree.h | 2 |
1 files changed, 2 insertions, 0 deletions
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<TreeNode*>(this->m_minimum)); } Iterator end() { return {}; } Iterator begin_from(K key) { return Iterator(static_cast<TreeNode*>(BaseTree::find(this->m_root, key))); } + Iterator begin_from(V& value) { return Iterator(&(value.*member)); } using ConstIterator = BaseIterator<const V>; ConstIterator begin() const { return ConstIterator(static_cast<TreeNode*>(this->m_minimum)); } ConstIterator end() const { return {}; } ConstIterator begin_from(K key) const { return ConstIterator(static_cast<TreeNode*>(BaseTree::find(this->m_rootF, key))); } + ConstIterator begin_from(V const& value) const { return Iterator(&(value.*member)); } bool remove(K key) { |