sapling/eden/fs/utils/CoverageSet.h
Chad Austin 86f0a3bd44 use CoverageSet to drop blobs when they're fully read by FUSE
Summary:
Drop interest in cached blobs at various points in the FileInode
lifecycle.

Reviewed By: strager

Differential Revision: D12991762

fbshipit-source-id: 19fd94938c96485160d547ecbd259ffeb39b2341
2018-12-06 12:04:17 -08:00

70 lines
1.5 KiB
C++

/*
* Copyright (c) 2018-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#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