From 35a8420d28057a48b4afb5b0aa29c89180291093 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 6 Dec 2020 06:22:18 +1000 Subject: [PATCH] analyse: add chunk equality comparator --- tools/analyse.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/analyse.cpp b/tools/analyse.cpp index 7a1fbf3..e38ae2d 100644 --- a/tools/analyse.cpp +++ b/tools/analyse.cpp @@ -13,7 +13,9 @@ #include #include +#include #include +#include /////////////////////////////////////////////////////////////////////////////// @@ -28,6 +30,41 @@ enum { }; +//----------------------------------------------------------------------------- +static +std::strong_ordering +region_ordering ( + emory::chunk::region const &a, + emory::chunk::region const &b +) { + if (auto const cmp = a.size () <=> b.size (); cmp != 0) + return cmp; + for (int i = 0; i < std::ssize (a.digest); ++i) + if (auto const cmp = a.digest[i] <=> b.digest[i]; cmp != 0) + return cmp; + return std::strong_ordering::equal; +} + + +static bool region_less (emory::chunk::region const &a, emory::chunk::region const &b) +{ + return region_ordering (a, b) < 0; +} + + +static bool region_equal (emory::chunk::region const &a, emory::chunk::region const &b) +{ + return region_ordering (a, b) == 0; +} + + +//static bool overlap (emory::chunk::region const &a, emory::chunk::region const &b) +//{ +// return a.offset.first < b.offset.second && +// b.offset.first < a.offset.second; +//} + + //----------------------------------------------------------------------------- int main (int argc, char const **argv) {