File indexing completed on 2025-08-28 08:27:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #pragma once
0024
0025 #include <cmath>
0026 #include <memory>
0027 #include <vector>
0028
0029 #include "arrow/util/logging.h"
0030 #include "arrow/util/macros.h"
0031 #include "arrow/util/visibility.h"
0032
0033 namespace arrow {
0034
0035 class Status;
0036
0037 namespace internal {
0038
0039 class ARROW_EXPORT TDigest {
0040 public:
0041 explicit TDigest(uint32_t delta = 100, uint32_t buffer_size = 500);
0042 ~TDigest();
0043 TDigest(TDigest&&);
0044 TDigest& operator=(TDigest&&);
0045
0046
0047 void Reset();
0048
0049
0050 Status Validate() const;
0051
0052
0053 void Dump() const;
0054
0055
0056
0057
0058 void Add(double value) {
0059 ARROW_DCHECK(!std::isnan(value)) << "cannot add NAN";
0060 if (ARROW_PREDICT_FALSE(input_.size() == input_.capacity())) {
0061 MergeInput();
0062 }
0063 input_.push_back(value);
0064 }
0065
0066
0067 template <typename T>
0068 typename std::enable_if<std::is_floating_point<T>::value>::type NanAdd(T value) {
0069 if (!std::isnan(value)) Add(value);
0070 }
0071
0072 template <typename T>
0073 typename std::enable_if<std::is_integral<T>::value>::type NanAdd(T value) {
0074 Add(static_cast<double>(value));
0075 }
0076
0077
0078 void Merge(const std::vector<TDigest>& others);
0079 void Merge(const TDigest& other);
0080
0081
0082 double Quantile(double q) const;
0083
0084 double Min() const { return Quantile(0); }
0085 double Max() const { return Quantile(1); }
0086 double Mean() const;
0087
0088
0089 bool is_empty() const;
0090
0091 private:
0092
0093 void MergeInput() const;
0094
0095
0096 mutable std::vector<double> input_;
0097
0098
0099 class TDigestImpl;
0100 std::unique_ptr<TDigestImpl> impl_;
0101 };
0102
0103 }
0104 }