You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by GitBox <gi...@apache.org> on 2022/05/13 23:30:47 UTC
[GitHub] [datasketches-cpp] AlexanderSaydakov commented on a diff in pull request #278: Quantile type conversion
AlexanderSaydakov commented on code in PR #278:
URL: https://github.com/apache/datasketches-cpp/pull/278#discussion_r872890919
##########
quantiles/include/quantiles_sketch_impl.hpp:
##########
@@ -138,6 +138,66 @@ is_sorted_(is_sorted)
throw std::logic_error("Item count does not match value computed from k, n");
}
+template<typename T, typename C, typename A>
+template<typename From, typename FC, typename FA>
+quantiles_sketch<T, C, A>::quantiles_sketch(const quantiles_sketch<From, FC, FA>& other, const A& allocator) :
+allocator_(allocator),
+k_(other.get_k()),
+n_(other.get_n()),
+bit_pattern_(compute_bit_pattern(other.get_k(), other.get_n())),
+base_buffer_(allocator),
+levels_(allocator),
+min_value_(nullptr),
+max_value_(nullptr),
+is_sorted_(false)
+{
+ static_assert(std::is_convertible<From, T>::value
+ || std::is_constructible<From, T>::value,
+ "Copy constructor across types requires std::is_convertible or std::is_constructible");
+
+ base_buffer_.reserve(2 * std::min(quantiles_constants::MIN_K, k_));
+
+ 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());
+
+ // reserve space in levels
+ uint8_t num_levels = compute_levels_needed(k_, n_);
+ levels_.reserve(num_levels);
+ for (int i = 0; i < num_levels; ++i) {
+ Level level(allocator);
+ level.reserve(k_);
+ levels_.push_back(std::move(level));
+ }
+
+ // iterate through points, assigning to the correct level as needed
+ for (auto pair : other) {
+ uint64_t wt = pair.second;
Review Comment:
const
##########
quantiles/include/quantiles_sketch_impl.hpp:
##########
@@ -138,6 +138,66 @@ is_sorted_(is_sorted)
throw std::logic_error("Item count does not match value computed from k, n");
}
+template<typename T, typename C, typename A>
+template<typename From, typename FC, typename FA>
+quantiles_sketch<T, C, A>::quantiles_sketch(const quantiles_sketch<From, FC, FA>& other, const A& allocator) :
+allocator_(allocator),
+k_(other.get_k()),
+n_(other.get_n()),
+bit_pattern_(compute_bit_pattern(other.get_k(), other.get_n())),
+base_buffer_(allocator),
+levels_(allocator),
+min_value_(nullptr),
+max_value_(nullptr),
+is_sorted_(false)
+{
+ static_assert(std::is_convertible<From, T>::value
+ || std::is_constructible<From, T>::value,
+ "Copy constructor across types requires std::is_convertible or std::is_constructible");
+
+ base_buffer_.reserve(2 * std::min(quantiles_constants::MIN_K, k_));
+
+ 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());
+
+ // reserve space in levels
+ uint8_t num_levels = compute_levels_needed(k_, n_);
Review Comment:
should be const
--
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: commits-unsubscribe@datasketches.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org