AK: Expose RedBlackTree::find_smallest_not_below()

This commit is contained in:
Tim Schumacher 2022-04-20 18:42:30 +02:00 committed by Andreas Kling
parent 02c18bf6de
commit 908d5a2853
Notes: sideshowbarker 2024-07-17 11:38:11 +09:00
2 changed files with 17 additions and 0 deletions

View file

@ -55,6 +55,14 @@ public:
return node_to_value(*node);
}
Container find_smallest_not_below(K key)
{
auto* node = static_cast<TreeNode*>(BaseTree::find_smallest_not_below(this->m_root, key));
if (!node)
return nullptr;
return node_to_value(*node);
}
void insert(K key, V& value)
{
auto& node = value.*member;
@ -208,6 +216,7 @@ class IntrusiveRedBlackTree<K, V, NonnullRefPtr<V>, member> : public IntrusiveRe
public:
[[nodiscard]] NonnullRefPtr<V> find(K key) const { return IntrusiveRedBlackTree<K, V, RefPtr<V>, member>::find(key).release_nonnull(); }
[[nodiscard]] NonnullRefPtr<V> find_largest_not_above(K key) const { return IntrusiveRedBlackTree<K, V, RefPtr<V>, member>::find_largest_not_above(key).release_nonnull(); }
[[nodiscard]] NonnullRefPtr<V> find_smallest_not_below(K key) const { return IntrusiveRedBlackTree<K, V, RefPtr<V>, member>::find_smallest_not_below(key).release_nonnull(); }
};
}

View file

@ -467,6 +467,14 @@ public:
return &node->value;
}
[[nodiscard]] V* find_smallest_not_below(K key)
{
auto* node = static_cast<Node*>(BaseTree::find_smallest_not_below(this->m_root, key));
if (!node)
return nullptr;
return &node->value;
}
ErrorOr<void> try_insert(K key, V const& value)
{
return try_insert(key, V(value));