jmalkin commented on code in PR #281:
URL: https://github.com/apache/datasketches-cpp/pull/281#discussion_r888559309


##########
kll/include/kll_sketch_impl.hpp:
##########
@@ -147,6 +148,50 @@ kll_sketch<T, C, S, A>::~kll_sketch() {
   }
 }
 
+template<typename T, typename C, typename S, typename A>
+template<typename TT, typename CC, typename AA>
+kll_sketch<T, C, S, A>::kll_sketch(const kll_sketch<TT, CC, AA>& other, const 
A& allocator):
+allocator_(allocator),
+k_(other.get_k()),
+m_(DEFAULT_M),
+min_k_(other.get_min_k()),
+n_(other.get_n()),
+num_levels_(1),
+levels_(2, 0, allocator),
+items_(nullptr),
+items_size_(other.get_capacity()),
+min_value_(nullptr),
+max_value_(nullptr),
+is_level_zero_sorted_(false)
+{
+  static_assert(
+    std::is_constructible<T, TT>::value,
+    "Type converting constructor requires new type to be constructible from 
existing type"
+  );
+  items_ = allocator_.allocate(items_size_);
+  levels_[0] = items_size_ - other.get_num_retained();
+  levels_[1] = items_size_;
+
+  if (!other.is_empty()) {
+    min_value_ = new (allocator_.allocate(1)) T(other.get_min_value());
+    max_value_ = new (allocator_.allocate(1)) T(other.get_max_value());
+    size_t index = levels_[0];
+    for (auto pair: other) {
+      new (&items_[index]) T(pair.first);
+      const uint8_t level = count_trailing_zeros_in_u64(pair.second);
+      if (level == num_levels_) {

Review Comment:
   are you guaranteed that the iterator will never give level > num_levels_? I 
think this should probably be >=, but that may be a valid assumption here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to