range.hh was deprecated in bd794629f9 (2020) since its names
conflict with the C++ library concept of an iterator range. The name
::range also mapped to the dangerous wrapping_interval rather than
nonwrapping_interval.
Complete the deprecation by removing range.hh and replacing all the
aliases by the names they point to from the interval library. Note
this now exposes uses of wrapping intervals as they are now explicit.
The unit tests are renamed and range.hh is deleted.
Closes scylladb/scylladb#17428
45 lines
1.0 KiB
C++
45 lines
1.0 KiB
C++
/*
|
|
* Copyright (C) 2017-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "interval.hh"
|
|
#include <seastar/core/print.hh>
|
|
|
|
#include "seastarx.hh"
|
|
|
|
using int_range = nonwrapping_interval<int>;
|
|
|
|
inline
|
|
unsigned cardinality(const int_range& r) {
|
|
assert(r.start());
|
|
assert(r.end());
|
|
return r.end()->value() - r.start()->value() + r.start()->is_inclusive() + r.end()->is_inclusive() - 1;
|
|
}
|
|
|
|
inline
|
|
unsigned cardinality(const std::optional<int_range>& ropt) {
|
|
return ropt ? cardinality(*ropt) : 0;
|
|
}
|
|
|
|
inline
|
|
std::optional<int_range> intersection(const int_range& a, const int_range& b) {
|
|
auto int_tri_cmp = [] (int x, int y) {
|
|
return x <=> y;
|
|
};
|
|
return a.intersection(b, int_tri_cmp);
|
|
}
|
|
|
|
inline
|
|
int_range make_int_range(int start_inclusive, int end_exclusive) {
|
|
if (end_exclusive <= start_inclusive) {
|
|
throw std::runtime_error(format("invalid range: [{:d}, {:d})", start_inclusive, end_exclusive));
|
|
}
|
|
return int_range({start_inclusive}, {end_exclusive - 1});
|
|
}
|