analyse: add chunk equality comparator

This commit is contained in:
Danny Robson 2020-12-06 06:22:18 +10:00
parent b2731f0968
commit 35a8420d28

View File

@ -13,7 +13,9 @@
#include <cruft/util/view.hpp> #include <cruft/util/view.hpp>
#include <cruft/util/parse/value.hpp> #include <cruft/util/parse/value.hpp>
#include <algorithm>
#include <iostream> #include <iostream>
#include <compare>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -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) int main (int argc, char const **argv)
{ {