From ae067bcce6391b2e0376501572579202661f6379 Mon Sep 17 00:00:00 2001 From: Ben FrantzDale Date: Thu, 5 Apr 2018 18:22:46 -0400 Subject: [PATCH] Add min/max functions to get the extent of the tree. --- IntervalTree.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/IntervalTree.h b/IntervalTree.h index 1bf2c20..5ed3405 100644 --- a/IntervalTree.h +++ b/IntervalTree.h @@ -158,6 +158,18 @@ class IntervalTree { assert(is_valid().first); } + Scalar min() const { + assert(!empty()); + if (left) { return left->min(); } + return std::min_element(intervals.begin(), intervals.end(), + IntervalStartCmp())->start; + } + Scalar max() const { + assert(!empty()); + if (right) { return right->max(); } + return std::max_element(intervals.begin(), intervals.end(), + IntervalStopCmp())->stop; + } // Call f on all intervals near the range [start, stop]: template void visit_near(const Scalar& start, const Scalar& stop, UnaryFunction f) const {