2018-12-05 23:07:13 +03:00
|
|
|
/*
|
2019-06-20 02:58:25 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-12-05 23:07:13 +03:00
|
|
|
*
|
2019-06-20 02:58:25 +03:00
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
2018-12-05 23:07:13 +03:00
|
|
|
*/
|
2019-10-11 15:26:59 +03:00
|
|
|
|
2018-12-05 23:07:13 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tracks contiguous coverage of intervals. Intervals are added dynamically.
|
|
|
|
* Then whether a given interval is fully covered can be queried.
|
|
|
|
*/
|
|
|
|
class CoverageSet {
|
|
|
|
public:
|
2018-12-06 22:33:06 +03:00
|
|
|
/**
|
|
|
|
* Removes all intervals from the set.
|
|
|
|
*/
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if no ranges are covered.
|
|
|
|
*/
|
|
|
|
bool empty() const noexcept;
|
|
|
|
|
2018-12-05 23:07:13 +03:00
|
|
|
/**
|
|
|
|
* Adds the interval [begin, end) to the set.
|
|
|
|
*/
|
|
|
|
void add(size_t begin, size_t end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the interval [begin, end) is fully covered by the
|
|
|
|
* previously-inserted intervals.
|
|
|
|
*/
|
|
|
|
bool covers(size_t begin, size_t end) const noexcept;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of intervals currently being tracked. This function is
|
|
|
|
* primarily for tests.
|
|
|
|
*/
|
|
|
|
size_t getIntervalCount() const noexcept;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Interval {
|
|
|
|
size_t begin;
|
|
|
|
size_t end;
|
|
|
|
|
|
|
|
bool operator<(const Interval& other) const noexcept {
|
|
|
|
return begin < other.begin;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The intervals are non-overlapping and non-adjacent. begin < end for all
|
|
|
|
* intervals.
|
|
|
|
*/
|
|
|
|
std::set<Interval> set_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|