* 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;
// 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) {
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;
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);