From 658e0780a6dc28416333ff3d053fc030aa16e4f1 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Sat, 30 Aug 2014 10:22:51 -0700 Subject: [PATCH] feat(util/rb_tree): add max (element) method Signed-off-by: Leonardo de Moura --- src/util/rb_tree.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/rb_tree.h b/src/util/rb_tree.h index 5b932795b0..08a9968f97 100644 --- a/src/util/rb_tree.h +++ b/src/util/rb_tree.h @@ -207,6 +207,15 @@ class rb_tree : public CMP { return &it->m_value; } + static T const * max(node const & n) { + node_cell const * it = n.m_ptr; + if (!it) + return nullptr; + while (it->m_right) + it = it->m_right.m_ptr; + return &it->m_value; + } + node erase(node && n, T const & v) { lean_assert(n); node h = ensure_unshared(n.steal()); @@ -349,6 +358,7 @@ public: } T const * min() const { return min(m_root); } + T const * max() const { return max(m_root); } bool contains(T const & v) const { return find(v) != nullptr; } template