return vector of values instead of pointers
diff --git a/req/include/req_sketch.hpp b/req/include/req_sketch.hpp
index 1e61ee8..c8b7856 100755
--- a/req/include/req_sketch.hpp
+++ b/req/include/req_sketch.hpp
@@ -37,8 +37,6 @@
public:
using Compactor = req_compactor<T, IsHighRank, Comparator, Allocator>;
using AllocCompactor = typename std::allocator_traits<Allocator>::template rebind_alloc<Compactor>;
- using AllocPtrT = typename std::allocator_traits<Allocator>::template rebind_alloc<const T*>;
- using vector_const_t_ptr = std::vector<const T*, AllocPtrT>;
using AllocDouble = typename std::allocator_traits<Allocator>::template rebind_alloc<double>;
using vector_double = std::vector<double, AllocDouble>;
@@ -175,7 +173,7 @@
* @return array of quantiles that correspond to the given array of normalized ranks
*/
template<bool inclusive = false>
- vector_const_t_ptr get_quantiles(const double* ranks, uint32_t size) const;
+ std::vector<T, Allocator> get_quantiles(const double* ranks, uint32_t size) const;
/**
* Returns an approximate lower bound of the given noramalized rank.
diff --git a/req/include/req_sketch_impl.hpp b/req/include/req_sketch_impl.hpp
index cf1acb3..9c9a31a 100755
--- a/req/include/req_sketch_impl.hpp
+++ b/req/include/req_sketch_impl.hpp
@@ -231,9 +231,8 @@
template<typename T, bool H, typename C, typename S, typename A>
template<bool inclusive>
-auto req_sketch<T, H, C, S, A>::get_quantiles(const double* ranks, uint32_t size) const
--> vector_const_t_ptr {
- vector_const_t_ptr quantiles;
+std::vector<T, A> req_sketch<T, H, C, S, A>::get_quantiles(const double* ranks, uint32_t size) const {
+ std::vector<T, A> quantiles(allocator_);
if (is_empty()) return quantiles;
QuantileCalculatorPtr quantile_calculator(nullptr, calculator_deleter(allocator_));
quantiles.reserve(size);
@@ -242,14 +241,14 @@
if ((rank < 0.0) || (rank > 1.0)) {
throw std::invalid_argument("rank cannot be less than zero or greater than 1.0");
}
- if (rank == 0.0) quantiles.push_back(min_value_);
- else if (rank == 1.0) quantiles.push_back(max_value_);
+ if (rank == 0.0) quantiles.push_back(*min_value_);
+ else if (rank == 1.0) quantiles.push_back(*max_value_);
else {
if (!quantile_calculator) {
// has side effect of sorting level zero if needed
quantile_calculator = const_cast<req_sketch*>(this)->get_quantile_calculator<inclusive>();
}
- quantiles.push_back(quantile_calculator->get_quantile(rank));
+ quantiles.push_back(*(quantile_calculator->get_quantile(rank)));
}
}
return quantiles;
diff --git a/req/test/req_sketch_test.cpp b/req/test/req_sketch_test.cpp
index 45de223..e62f08a 100755
--- a/req/test/req_sketch_test.cpp
+++ b/req/test/req_sketch_test.cpp
@@ -69,9 +69,9 @@
const double ranks[3] {0, 0.5, 1};
auto quantiles = sketch.get_quantiles(ranks, 3);
REQUIRE(quantiles.size() == 3);
- REQUIRE(*quantiles[0] == 1);
- REQUIRE(*quantiles[1] == 1);
- REQUIRE(*quantiles[2] == 1);
+ REQUIRE(quantiles[0] == 1);
+ REQUIRE(quantiles[1] == 1);
+ REQUIRE(quantiles[2] == 1);
}
TEST_CASE("req sketch: repeated values", "[req_sketch]") {
@@ -131,9 +131,9 @@
const double ranks[3] {0, 0.5, 1};
auto quantiles = sketch.get_quantiles(ranks, 3);
REQUIRE(quantiles.size() == 3);
- REQUIRE(*quantiles[0] == 1);
- REQUIRE(*quantiles[1] == 6);
- REQUIRE(*quantiles[2] == 10);
+ REQUIRE(quantiles[0] == 1);
+ REQUIRE(quantiles[1] == 6);
+ REQUIRE(quantiles[2] == 10);
const float splits[3] {2, 6, 9};
auto cdf = sketch.get_CDF(splits, 3);