20 #ifndef REQ_COMPACTOR_HPP_
21 #define REQ_COMPACTOR_HPP_
34 req_compactor(
bool hra, uint8_t lg_weight, uint32_t section_size,
const Comparator& comparator,
35 const Allocator& allocator,
bool sorted =
true);
37 req_compactor(
const req_compactor& other);
38 req_compactor(req_compactor&& other) noexcept;
39 req_compactor& operator=(
const req_compactor& other);
40 req_compactor& operator=(req_compactor&& other);
42 template<
typename TT,
typename CC,
typename AA>
43 req_compactor(
const req_compactor<TT, CC, AA>& other,
const Comparator& comparator,
const Allocator& allocator);
45 bool is_sorted()
const;
46 uint32_t get_num_items()
const;
47 uint32_t get_nom_capacity()
const;
48 uint8_t get_lg_weight()
const;
49 const T* begin()
const;
54 uint64_t compute_weight(
const T& item,
bool inclusive)
const;
56 template<
typename FwdT>
57 void append(FwdT&& item);
59 template<
typename FwdC>
60 void merge(FwdC&& other);
64 std::pair<uint32_t, uint32_t> compact(req_compactor& next);
71 template<typename S, typename TT = T, typename std::enable_if<std::is_arithmetic<TT>::value,
int>::type = 0>
72 size_t get_serialized_size_bytes(
const S& serde)
const;
79 template<typename S, typename TT = T, typename std::enable_if<!std::is_arithmetic<TT>::value,
int>::type = 0>
80 size_t get_serialized_size_bytes(
const S& serde)
const;
83 void serialize(std::ostream& os,
const S& serde)
const;
86 size_t serialize(
void* dst,
size_t capacity,
const S& serde)
const;
89 static req_compactor deserialize(std::istream& is,
const S& serde,
const Comparator& comparator,
90 const Allocator& allocator,
bool sorted,
bool hra);
93 static std::pair<req_compactor, size_t> deserialize(
const void* bytes,
size_t size,
const S& serde,
94 const Comparator& comparator,
const Allocator& allocator,
bool sorted,
bool hra);
97 static req_compactor deserialize(std::istream& is,
const S& serde,
const Comparator& comparator,
98 const Allocator& allocator,
bool sorted, uint16_t k, uint8_t num_items,
bool hra);
101 static std::pair<req_compactor, size_t> deserialize(
const void* bytes,
size_t size,
const S& serde,
102 const Comparator& comparator,
const Allocator& allocator,
bool sorted, uint16_t k, uint8_t num_items,
bool hra);
105 Comparator comparator_;
106 Allocator allocator_;
111 float section_size_raw_;
112 uint32_t section_size_;
113 uint8_t num_sections_;
119 bool ensure_enough_sections();
120 std::pair<uint32_t, uint32_t> compute_compaction_range(uint32_t secs_to_compact)
const;
121 void grow(uint32_t new_capacity);
122 void ensure_space(uint32_t num);
124 static uint32_t nearest_even(
float value);
126 template<
typename InIter,
typename OutIter>
127 static void promote_evens_or_odds(InIter from, InIter to,
bool flag, OutIter dst);
131 req_compactor(
bool hra, uint8_t lg_weight,
bool sorted,
float section_size_raw, uint8_t num_sections, uint64_t state,
132 std::unique_ptr<T, items_deleter> items, uint32_t num_items,
const Comparator& comparator,
const Allocator& allocator);
135 static std::unique_ptr<T, items_deleter> deserialize_items(std::istream& is,
const S& serde,
const Allocator& allocator, uint32_t num);
138 static std::pair<std::unique_ptr<T, items_deleter>,
size_t> deserialize_items(
const void* bytes,
size_t size,
const S& serde,
const Allocator& allocator, uint32_t num);
141 template<
typename TT,
typename CC,
typename AA>
142 friend class req_compactor;
147 #include "req_compactor_impl.hpp"
DataSketches namespace.
Definition: binomial_bounds.hpp:38