stojkomilos opened a new pull request, #513:
URL: https://github.com/apache/datasketches-cpp/pull/513
## What
Adds a public `get_live_bytes()` accessor that reports, in O(1), the exact
heap a sketch's
mutable internal state is holding **right now**. The sketches already expose
`get_serialized_size_bytes()`, but that is an upper bound on the
*serialized* form; there is
currently no way to ask how much memory a live, mutable sketch is actually
retaining. This is
useful for memory accounting when many mutable sketches are held in memory
at once (e.g. one
sketch per group/window in a streaming aggregation).
## Where
- **theta / tuple** — the accessor lives on `theta_update_sketch_base`, the
hash table shared by
theta and tuple update sketches, unions and intersections. It returns
`(1 << lg_cur_size_) * sizeof(Entry)`, or `0` when the table is
unallocated (`lg_cur_size_ == 0`
leaves `entries_ == nullptr`). `update_theta_sketch`, `theta_union`,
`theta_intersection`, the
tuple update sketch, `tuple_union` and `tuple_intersection` forward to it.
Tuple's union and
intersection reuse the theta base as their `State`, so no separate
implementation is needed
there.
- **kll** — not a hash table, so `kll_sketch::get_live_bytes()` sums the
`items_` buffer
(`items_size_` elements) and the `levels_` vector, mirroring the sketch's
`allocate()` sites.
Unlike `get_serialized_size_bytes()`, this touches no data and does no
iteration; it just reports
the current allocation size.
## Tests
Adds Catch2 cases in `theta_sketch_test`, `theta_union_test`,
`theta_intersection_test`,
`tuple_sketch_test` and `kll_sketch_test` that:
- check the footprint is a power-of-two count of entries where applicable,
- confirm an unallocated intersection reports `0`,
- confirm the footprint only grows (never shrinks) as entries are inserted
and ends up larger than
the initial allocation.
All theta / tuple / kll suites pass locally.
## Notes
Scope is theta, tuple and kll. `hll` and `cpc` could get an equivalent
accessor in a follow-up if
maintainers want the whole family consistent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]