memgraph/include/utils/iterator/count.hpp

36 lines
755 B
C++
Raw Normal View History

2016-08-30 12:29:30 +08:00
#pragma once
2016-08-30 15:53:02 +08:00
#include "utils/total_ordering.hpp"
2016-08-30 12:29:30 +08:00
// Represents number of to be returned elements from iterator. Where acutal
// number is probably somwhere in [min,max].
2016-08-30 15:53:02 +08:00
class Count : public TotalOrdering<Count>
2016-08-30 12:29:30 +08:00
{
public:
Count(size_t exact) : min(exact), max(exact) {}
Count(size_t min, size_t max) : min(min), max(max) {}
Count &min_zero()
{
min = 0;
return *this;
}
2016-08-30 15:53:02 +08:00
size_t avg() const { return ((max - min) >> 1) + min; }
friend constexpr bool operator<(const Count &lhs, const Count &rhs)
{
return lhs.avg() < rhs.avg();
}
friend constexpr bool operator==(const Count &lhs, const Count &rhs)
{
return lhs.avg() == rhs.avg();
}
2016-08-30 12:29:30 +08:00
size_t min;
size_t max;
};