sapling/eden/fs/utils/CoverageSet.h
Andres Suarez fbdb46f5cb Tidy up license headers
Reviewed By: chadaustin

Differential Revision: D17872966

fbshipit-source-id: cd60a364a2146f0dadbeca693b1d4a5d7c97ff63
2019-10-11 05:28:23 -07:00

68 lines
1.4 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#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:
/**
* Removes all intervals from the set.
*/
void clear();
/**
* Returns true if no ranges are covered.
*/
bool empty() const noexcept;
/**
* 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