mirror of
https://github.com/ceph/ceph
synced 2025-02-24 03:27:10 +00:00
Merge pull request #35933 from tchaikov/wip-interval-set
include/interval_set: use template as the 2nd template parameter Reviewed-by: Patrick Donnelly <pdonnell@redhat.com>
This commit is contained in:
commit
4d94935262
@ -30,9 +30,10 @@
|
||||
* flat_map and btree_map).
|
||||
*/
|
||||
|
||||
template<typename T, typename Map = std::map<T,T>>
|
||||
template<typename T, template<typename, typename, typename ...> class C = std::map>
|
||||
class interval_set {
|
||||
public:
|
||||
using Map = C<T, T>;
|
||||
using value_type = typename Map::value_type;
|
||||
using offset_type = T;
|
||||
using length_type = T;
|
||||
@ -730,40 +731,43 @@ private:
|
||||
|
||||
// declare traits explicitly because (1) it's templatized, and (2) we
|
||||
// want to include _nohead variants.
|
||||
template<typename T, typename Map>
|
||||
struct denc_traits<interval_set<T,Map>> {
|
||||
template<typename T, template<typename, typename, typename ...> class C>
|
||||
struct denc_traits<interval_set<T, C>> {
|
||||
private:
|
||||
using container_t = interval_set<T, C>;
|
||||
public:
|
||||
static constexpr bool supported = true;
|
||||
static constexpr bool bounded = false;
|
||||
static constexpr bool featured = false;
|
||||
static constexpr bool need_contiguous = denc_traits<T,Map>::need_contiguous;
|
||||
static void bound_encode(const interval_set<T,Map>& v, size_t& p) {
|
||||
static constexpr bool need_contiguous = denc_traits<T, C<T,T>>::need_contiguous;
|
||||
static void bound_encode(const container_t& v, size_t& p) {
|
||||
v.bound_encode(p);
|
||||
}
|
||||
static void encode(const interval_set<T,Map>& v,
|
||||
static void encode(const container_t& v,
|
||||
ceph::buffer::list::contiguous_appender& p) {
|
||||
v.encode(p);
|
||||
}
|
||||
static void decode(interval_set<T,Map>& v, ceph::buffer::ptr::const_iterator& p) {
|
||||
static void decode(container_t& v, ceph::buffer::ptr::const_iterator& p) {
|
||||
v.decode(p);
|
||||
}
|
||||
template<typename U=T>
|
||||
static typename std::enable_if<sizeof(U) && !need_contiguous>::type
|
||||
decode(interval_set<T,Map>& v, ceph::buffer::list::iterator& p) {
|
||||
decode(container_t& v, ceph::buffer::list::iterator& p) {
|
||||
v.decode(p);
|
||||
}
|
||||
static void encode_nohead(const interval_set<T,Map>& v,
|
||||
static void encode_nohead(const container_t& v,
|
||||
ceph::buffer::list::contiguous_appender& p) {
|
||||
v.encode_nohead(p);
|
||||
}
|
||||
static void decode_nohead(size_t n, interval_set<T,Map>& v,
|
||||
static void decode_nohead(size_t n, container_t& v,
|
||||
ceph::buffer::ptr::const_iterator& p) {
|
||||
v.decode_nohead(n, p);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<class T, typename Map>
|
||||
inline std::ostream& operator<<(std::ostream& out, const interval_set<T,Map> &s) {
|
||||
template<typename T, template<typename, typename, typename ...> class C>
|
||||
inline std::ostream& operator<<(std::ostream& out, const interval_set<T,C> &s) {
|
||||
out << "[";
|
||||
bool first = true;
|
||||
for (const auto& [start, len] : s) {
|
||||
|
@ -20,10 +20,11 @@ class StupidAllocator : public Allocator {
|
||||
int64_t num_free; ///< total bytes in freelist
|
||||
int64_t block_size;
|
||||
|
||||
typedef mempool::bluestore_alloc::pool_allocator<
|
||||
std::pair<const uint64_t,uint64_t>> allocator_t;
|
||||
typedef btree::btree_map<uint64_t,uint64_t,std::less<uint64_t>,allocator_t> interval_set_map_t;
|
||||
typedef interval_set<uint64_t,interval_set_map_t> interval_set_t;
|
||||
template <typename K, typename V> using allocator_t =
|
||||
mempool::bluestore_alloc::pool_allocator<std::pair<const K, V>>;
|
||||
template <typename K, typename V> using btree_map_t =
|
||||
btree::btree_map<K, V, std::less<K>, allocator_t<K, V>>;
|
||||
using interval_set_t = interval_set<uint64_t, btree_map_t>;
|
||||
std::vector<interval_set_t> free; ///< leading-edge copy
|
||||
|
||||
uint64_t last_alloc = 0;
|
||||
|
@ -142,7 +142,7 @@ void dump(ceph::Formatter* f, const osd_alerts_t& alerts);
|
||||
|
||||
typedef interval_set<
|
||||
snapid_t,
|
||||
mempool::osdmap::flat_map<snapid_t,snapid_t>> snap_interval_set_t;
|
||||
mempool::osdmap::flat_map> snap_interval_set_t;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -239,7 +239,7 @@ add_executable(unittest_interval_set
|
||||
test_interval_set.cc
|
||||
)
|
||||
add_ceph_unittest(unittest_interval_set)
|
||||
target_link_libraries(unittest_interval_set ceph-common)
|
||||
target_link_libraries(unittest_interval_set ceph-common GTest::Main)
|
||||
|
||||
# unittest_weighted_priority_queue
|
||||
add_executable(unittest_weighted_priority_queue
|
||||
|
@ -32,10 +32,8 @@ class IntervalSetTest : public ::testing::Test {
|
||||
|
||||
typedef ::testing::Types<
|
||||
interval_set<IntervalValueType>,
|
||||
interval_set<IntervalValueType,
|
||||
btree::btree_map<IntervalValueType,IntervalValueType>>,
|
||||
interval_set<IntervalValueType,
|
||||
boost::container::flat_map<IntervalValueType,IntervalValueType>>
|
||||
interval_set<IntervalValueType, btree::btree_map>,
|
||||
interval_set<IntervalValueType, boost::container::flat_map>
|
||||
> IntervalSetTypes;
|
||||
|
||||
TYPED_TEST_SUITE(IntervalSetTest, IntervalSetTypes);
|
||||
|
Loading…
Reference in New Issue
Block a user