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/02/04 20:06:51 UTC
[GitHub] [datasketches-cpp] AlexanderSaydakov commented on a change in pull request #259: Quantile sketch sorted view
AlexanderSaydakov commented on a change in pull request #259:
URL: https://github.com/apache/datasketches-cpp/pull/259#discussion_r799777460
##########
File path: common/include/quantile_sketch_sorted_view.hpp
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef QUANTILE_SKETCH_SORTED_VIEW_HPP_
+#define QUANTILE_SKETCH_SORTED_VIEW_HPP_
+
+#include <functional>
+
+namespace datasketches {
+
+template<
+ typename T,
+ typename Comparator, // strict weak ordering function (see C++ named requirements: Compare)
+ typename Allocator
+>
+class quantile_sketch_sorted_view {
+public:
+ using Entry = typename std::conditional<std::is_integral<T>::value, std::pair<T, uint64_t>, std::pair<const T*, uint64_t>>::type;
+ using AllocEntry = typename std::allocator_traits<Allocator>::template rebind_alloc<Entry>;
+ using Container = std::vector<Entry, AllocEntry>;
+
+ quantile_sketch_sorted_view(const Allocator& allocator);
+
+ template<typename Iterator>
+ void add(Iterator begin, Iterator end, uint64_t weight);
+
+ template<bool inclusive>
+ void convert_to_cummulative();
+
+ class const_iterator;
+ const_iterator begin() const;
+ const_iterator end() const;
+
+ size_t size() const;
+
+ // makes sense only with cumulative weight
+ const T& get_quantile(double rank) const;
+
+private:
+ template<typename TT = T>
+ static inline const TT& deref_helper(const TT* t) { return *t; }
+
+ template<typename TT = T>
+ static inline const TT& deref_helper(const TT& t) { return t; }
+
+ template<typename C>
+ struct compare_pairs_by_first_ptr {
+ bool operator()(const Entry& a, const Entry& b) {
+ return C()(deref_helper(a.first), deref_helper(b.first));
+ }
+ };
+
+ struct compare_pairs_by_second {
+ bool operator()(const Entry& a, const Entry& b) {
+ return a.second < b.second;
+ }
+ };
+
+ template<typename TT = T, typename std::enable_if<std::is_integral<TT>::value, int>::type = 0>
Review comment:
Yes, arithmetic
##########
File path: common/include/quantile_sketch_sorted_view.hpp
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef QUANTILE_SKETCH_SORTED_VIEW_HPP_
+#define QUANTILE_SKETCH_SORTED_VIEW_HPP_
+
+#include <functional>
+
+namespace datasketches {
+
+template<
+ typename T,
+ typename Comparator, // strict weak ordering function (see C++ named requirements: Compare)
+ typename Allocator
+>
+class quantile_sketch_sorted_view {
+public:
+ using Entry = typename std::conditional<std::is_integral<T>::value, std::pair<T, uint64_t>, std::pair<const T*, uint64_t>>::type;
Review comment:
yes
##########
File path: kll/include/kll_sketch.hpp
##########
@@ -584,7 +591,7 @@ class kll_sketch {
// implementations for all other types
template<typename TT = T, typename std::enable_if<!std::is_floating_point<TT>::value, int>::type = 0>
- static TT get_invalid_value() {
+ static const TT& get_invalid_value() {
throw std::runtime_error("getting quantiles from empty sketch is not supported for this type of values");
Review comment:
OK
--
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