mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Expose RedBlackTree::find_smallest_not_below()
This commit is contained in:
parent
02c18bf6de
commit
908d5a2853
Notes:
sideshowbarker
2024-07-17 11:38:11 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/908d5a2853 Pull-request: https://github.com/SerenityOS/serenity/pull/13752 Reviewed-by: https://github.com/awesomekling
2 changed files with 17 additions and 0 deletions
|
@ -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(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue