MCPcopy Create free account
hub / github.com/apache/kvrocks / QuantileOf

Function QuantileOf

tests/cppunit/types/tdigest_test.cc:48–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46constexpr std::random_device::result_type kSeed = 14863; // fixed seed for reproducibility
47
48std::vector<double> QuantileOf(const std::vector<double> &samples, const std::vector<double> &qs) {
49 std::vector<double> result;
50 result.reserve(qs.size());
51 std::vector<double> sorted_samples = samples;
52 std::sort(sorted_samples.begin(), sorted_samples.end());
53 for (auto q : qs) {
54 auto index = q * static_cast<double>(sorted_samples.size());
55 if (index <= 1) {
56 result.push_back(sorted_samples.front());
57 } else if (index >= static_cast<double>(sorted_samples.size() - 1)) {
58 result.push_back(sorted_samples.back());
59 } else {
60 auto left = sorted_samples[static_cast<int>(index)];
61 auto right = sorted_samples[static_cast<int>(index) + 1];
62 auto diff = index - static_cast<int>(index);
63 result.push_back(left + (right - left) * diff);
64 }
65 }
66 return result;
67}
68
69std::vector<std::pair<double, double>> QuantileIntervalOf(const std::vector<double> &samples,
70 const std::vector<double> &qs) {

Callers 1

TEST_FFunction · 0.85

Calls 2

beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected