Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/src/arrow/util/tdigest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ class TDigest::TDigestImpl {
if (total_weight != total_weight_) {
return Status::Invalid("tdigest total weight mismatch");
}
// check if buffer expanded
if (tdigests_[0].capacity() > delta_ || tdigests_[1].capacity() > delta_) {
// check if buffer size exceeded delta

@cyb70289 cyb70289 Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is at line 104
td.push_back(centroid); // should never exceed capacity and trigger reallocation

A correctly implemented algorithm shall not write above pre-allocated capacity. I don't add check code there for performance, and write above capacity is not a disaster (the algorithm still works).

tdigests_[n] may be cleared during usage, size() doesn't guarantee the vector was not expanded.

I think we can record the actual buffer size at construction time, and check against that.

Note this is a loose check. As this PR points out, real capacity is often bigger than required.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can just delete this check for simplicity. Looks to me I was overly cautious.

if (tdigests_[0].size() > delta_ || tdigests_[1].size() > delta_) {
return Status::Invalid("oversized tdigest buffer");
}
// check k-size
Expand Down
Loading