Skip to content

Commit

Permalink
Use closed intervals consistently
Browse files Browse the repository at this point in the history
Summary:
In `glean.cpp` we were using unspecified intervals but assuming they
were closed. Probably wasn't actually causing a problem in practice,
but we should get this right.

Reviewed By: phlalx

Differential Revision: D66958853

fbshipit-source-id: f0f74d84b551a8f3d0bd93ed1770559af19679f5
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Dec 10, 2024
1 parent 6087f4c commit c2337f7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion glean/cpp/glean.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ class BatchBase {

struct Owned {
std::string unit;
boost::icl::interval_set<Id> facts;
rts::closed_interval_set<Id> facts;
Id start;
Id finish;
};
Expand Down
10 changes: 4 additions & 6 deletions glean/rts/substitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace facebook {
namespace glean {
namespace rts {

using namespace boost::icl;

Substitution::Substitution(Id first, size_t size)
: base(first), items(size, Id::invalid()) {}

Expand All @@ -32,7 +30,7 @@ Id Substitution::firstFreeId() const {
std::vector<Id> Substitution::substIntervals(
const std::vector<Id>& intervals) const {
CHECK_EQ(intervals.size() % 2, 0);
boost::icl::interval_set<Id, std::less, closed_interval<Id>> is;
closed_interval_set<Id> is;

auto add = [&](Id start, Id end) {
if (end >= finish()) {
Expand Down Expand Up @@ -74,9 +72,9 @@ std::vector<Id> Substitution::substIntervals(
return results;
}

boost::icl::interval_set<Id> Substitution::substIntervals(
const boost::icl::interval_set<Id>& intervals) const {
boost::icl::interval_set<Id> result;
closed_interval_set<Id> Substitution::substIntervals(
const closed_interval_set<Id>& intervals) const {
closed_interval_set<Id> result;
for (auto ival : intervals) {
if (ival.upper() < base) {
result.add(ival);
Expand Down
8 changes: 6 additions & 2 deletions glean/rts/substitution.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ namespace facebook {
namespace glean {
namespace rts {

template <typename T>
using closed_interval_set =
boost::icl::interval_set<T, std::less, boost::icl::closed_interval<T>>;

/**
* Substitutions for blocks of consecutive Ids.
*
Expand Down Expand Up @@ -51,8 +55,8 @@ struct Substitution {

// This is just like substIntervals but returns a boost::icl::interval_set<Id>
// instead of a std::vector<Id>.
boost::icl::interval_set<Id> substIntervals(
const boost::icl::interval_set<Id>& intervals) const;
closed_interval_set<Id> substIntervals(
const closed_interval_set<Id>& intervals) const;

Id start() const {
return base;
Expand Down

0 comments on commit c2337f7

Please sign in to comment.