@@ -627,6 +627,65 @@ void tdigest<T, A>::check_split_points(const T* values, uint32_t size) {
627627 }
628628}
629629
630+ template <typename T, typename A>
631+ typename tdigest<T, A>::const_iterator tdigest<T, A>::begin() const {
632+ return tdigest<T, A>::const_iterator (*this , false );
633+ }
634+
635+ template <typename T, typename A>
636+ typename tdigest<T, A>::const_iterator tdigest<T, A>::end() const {
637+ return tdigest::const_iterator (*this , true );
638+ }
639+
640+ template <typename T, typename A>
641+ tdigest<T, A>::const_iterator::const_iterator(const tdigest& tdigest_, const bool is_end):
642+ centroids_ (tdigest_.get_allocator())
643+ {
644+ // Create a copy of the tdigest to generate the centroids after processing the buffered values
645+ tdigest tmp (tdigest_);
646+ tmp.compress ();
647+ centroids_.insert (centroids_.end (), tmp.centroids_ .begin (), tmp.centroids_ .end ());
648+
649+ if (is_end) {
650+ index_ = centroids_.size ();
651+ } else {
652+ index_ = 0 ;
653+ }
654+ }
655+
656+ template <typename T, typename A>
657+ typename tdigest<T, A>::const_iterator& tdigest<T, A>::const_iterator::operator ++() {
658+ ++index_;
659+ return *this ;
660+ }
661+
662+ template <typename T, typename A>
663+ typename tdigest<T, A>::const_iterator& tdigest<T, A>::const_iterator::operator ++(int ) {
664+ const_iterator tmp (*this );
665+ operator ++();
666+ return tmp;
667+ }
668+
669+ template <typename T, typename A>
670+ bool tdigest<T, A>::const_iterator::operator ==(const const_iterator& other) const {
671+ return index_ == other.index_ ;
672+ }
673+
674+ template <typename T, typename A>
675+ bool tdigest<T, A>::const_iterator::operator !=(const const_iterator& other) const {
676+ return !operator ==(other);
677+ }
678+
679+ template <typename T, typename A>
680+ auto tdigest<T, A>::const_iterator::operator *() const -> reference {
681+ return value_type (centroids_[index_].get_mean (), centroids_[index_].get_weight ());
682+ }
683+
684+ template <typename T, typename A>
685+ auto tdigest<T, A>::const_iterator::operator ->() const -> pointer {
686+ return **this ;
687+ }
688+
630689} /* namespace datasketches */
631690
632691#endif // _TDIGEST_IMPL_HPP_
0 commit comments