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.
This commit is contained in:
Idan Horowitz 2022-04-04 00:19:31 +03:00 committed by Andreas Kling
parent 30e6b313b4
commit 1787d94907

View file

@ -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)
{