@@ -597,6 +597,24 @@ bool tdigest<T, A>::is_single_value() const {
597597 return get_total_weight () == 1 ;
598598}
599599
600+ template <typename T, typename A>
601+ tdigest<T, A>::tdigest(const tdigest<T, A>& other):
602+ reverse_merge_ (other.reverse_merge_),
603+ k_(other.k_),
604+ min_(other.min_),
605+ max_(other.max_),
606+ centroids_capacity_(other.centroids_capacity_),
607+ centroids_(other.centroids_, other.get_allocator()),
608+ centroids_weight_(other.centroids_weight_),
609+ buffer_(other.buffer_, other.get_allocator())
610+ {
611+ if (other.k_ < 10 ) throw std::invalid_argument (" k must be at least 10" );
612+ const size_t fudge = other.k_ < 30 ? 30 : 10 ;
613+ centroids_capacity_ = 2 * k_ + fudge;
614+ centroids_.reserve (centroids_capacity_);
615+ buffer_.reserve (centroids_capacity_ * BUFFER_MULTIPLIER);
616+ }
617+
600618template <typename T, typename A>
601619tdigest<T, A>::tdigest(bool reverse_merge, uint16_t k, T min, T max, vector_centroid&& centroids, uint64_t weight, vector_t && buffer):
602620reverse_merge_ (reverse_merge),
@@ -638,11 +656,11 @@ template <typename T, typename A>
638656}
639657
640658template <typename T, typename A>
641- tdigest<T, A>::const_iterator::const_iterator(const tdigest& tdigest_, const bool is_end):
642- centroids_ ()
659+ tdigest<T, A>::const_iterator::const_iterator(const tdigest<T, A> & tdigest_, const bool is_end):
660+ centroids_ (tdigest_.get_allocator() )
643661{
644662 // Create a copy of the tdigest to generate the centroids after processing the buffered values
645- tdigest tmp (tdigest_);
663+ tdigest<T, A> tmp (tdigest_);
646664 tmp.compress ();
647665 centroids_.insert (centroids_.end (), tmp.centroids_ .begin (), tmp.centroids_ .end ());
648666
0 commit comments