From d5a6313c71ed1592bc0bc4e35cf4490729b8cabe Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 11 May 2015 18:36:23 -0700 Subject: [PATCH] Add RangeSet::lebesgue_sum --- src/ripple/basics/RangeSet.h | 4 ++++ src/ripple/basics/impl/RangeSet.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/ripple/basics/RangeSet.h b/src/ripple/basics/RangeSet.h index 903e6a1e4..c66a945fe 100644 --- a/src/ripple/basics/RangeSet.h +++ b/src/ripple/basics/RangeSet.h @@ -57,6 +57,10 @@ public: std::string toString () const; + /** Returns the sum of the Lebesgue measures of all sub-ranges. */ + std::size_t + lebesgue_sum() const; + /** Check invariants of the data. This is for diagnostics, and does nothing in release builds. diff --git a/src/ripple/basics/impl/RangeSet.cpp b/src/ripple/basics/impl/RangeSet.cpp index 362545c0e..0bfc627fd 100644 --- a/src/ripple/basics/impl/RangeSet.cpp +++ b/src/ripple/basics/impl/RangeSet.cpp @@ -235,6 +235,15 @@ void RangeSet::simplify () } } +std::size_t +RangeSet::lebesgue_sum() const +{ + std::size_t sum = mRanges.size(); + for (auto const& e : mRanges) + sum += e.second - e.first; + return sum; +} + void RangeSet::checkInternalConsistency () const noexcept { #ifndef NDEBUG