@@ -152,46 +152,27 @@ template<typename T, typename C, typename S, typename A>
152152template <typename TT , typename CC , typename SS , typename AA >
153153kll_sketch<T, C, S, A>::kll_sketch(const kll_sketch<TT , CC , SS , AA >& other, const A& allocator):
154154allocator_ (allocator),
155- k_(other.get_k() ),
156- m_(DEFAULT_M ),
157- min_k_(other.get_min_k() ),
158- n_(other.get_n() ),
159- num_levels_(1 ),
160- levels_(2 , 0 , allocator ),
155+ k_(other.k_ ),
156+ m_(other.m_ ),
157+ min_k_(other.min_k_ ),
158+ n_(other.n_ ),
159+ num_levels_(other.num_levels_ ),
160+ levels_(other.levels_, allocator_ ),
161161items_(nullptr ),
162- items_size_(other.get_capacity() ),
162+ items_size_(other.items_size_ ),
163163min_value_(nullptr ),
164164max_value_(nullptr ),
165- is_level_zero_sorted_(false )
165+ is_level_zero_sorted_(other.is_level_zero_sorted_ )
166166{
167167 static_assert (
168168 std::is_constructible<T, TT >::value,
169169 " Type converting constructor requires new type to be constructible from existing type"
170170 );
171171 items_ = allocator_.allocate (items_size_);
172- levels_[0 ] = items_size_ - other.get_num_retained ();
173- levels_[1 ] = items_size_;
174-
175- if (!other.is_empty ()) {
176- min_value_ = new (allocator_.allocate (1 )) T (other.get_min_value ());
177- max_value_ = new (allocator_.allocate (1 )) T (other.get_max_value ());
178- size_t index = levels_[0 ];
179- for (auto pair: other) {
180- new (&items_[index]) T (pair.first );
181- const uint8_t level = count_trailing_zeros_in_u64 (pair.second );
182- if (level == num_levels_) {
183- ++num_levels_;
184- levels_.resize (num_levels_ + 1 );
185- levels_[level] = index;
186- levels_[num_levels_] = items_size_;
187- } else if (level < num_levels_ - 1 || level > num_levels_) {
188- throw std::invalid_argument (" corrupt source sketch" );
189- }
190- ++index;
191- }
192- }
172+ for (auto i = levels_[0 ]; i < levels_[num_levels_]; ++i) new (&items_[i]) T (other.items_ [i]);
173+ if (other.min_value_ != nullptr ) min_value_ = new (allocator_.allocate (1 )) T (*other.min_value_ );
174+ if (other.max_value_ != nullptr ) max_value_ = new (allocator_.allocate (1 )) T (*other.max_value_ );
193175 check_sorting ();
194- assert_correct_total_weight ();
195176}
196177
197178template <typename T, typename C, typename S, typename A>
@@ -257,11 +238,6 @@ uint16_t kll_sketch<T, C, S, A>::get_k() const {
257238 return k_;
258239}
259240
260- template <typename T, typename C, typename S, typename A>
261- uint16_t kll_sketch<T, C, S, A>::get_min_k() const {
262- return min_k_;
263- }
264-
265241template <typename T, typename C, typename S, typename A>
266242uint64_t kll_sketch<T, C, S, A>::get_n() const {
267243 return n_;
@@ -272,11 +248,6 @@ uint32_t kll_sketch<T, C, S, A>::get_num_retained() const {
272248 return levels_[num_levels_] - levels_[0 ];
273249}
274250
275- template <typename T, typename C, typename S, typename A>
276- uint32_t kll_sketch<T, C, S, A>::get_capacity() const {
277- return items_size_;
278- }
279-
280251template <typename T, typename C, typename S, typename A>
281252bool kll_sketch<T, C, S, A>::is_estimation_mode() const {
282253 return num_levels_ > 1 ;
0 commit comments