pub struct SightingLog { /* private fields */ }Expand description
A bounded store for Sightings: at most cap per (format, shape,
kind) are kept, so the memory one scan spends on them is at most
groups x cap however hostile the input, while the count of each group
stays exact. Self::count gives the exact total pushed, and
Self::into_sightings folds the uncounted remainder into the last
stored sighting’s Sighting::more, so describe_sightings prints
the same sentence it would for every sighting stored.
Implementations§
Source§impl SightingLog
impl SightingLog
Sourcepub const DEFAULT_CAP: usize = 64
pub const DEFAULT_CAP: usize = 64
The default per-group cap.
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty log with Self::DEFAULT_CAP.
Sourcepub fn with_cap(cap: usize) -> Self
pub fn with_cap(cap: usize) -> Self
An empty log keeping at most cap sightings per group. A cap of 0
is raised to 1, so a group always has a sighting to carry its count.
A cap below 8 (SIGHTING_OFFSETS_SHOWN) CHANGES the sentence
describe_sightings prints: it lists only the stored offsets, so a
group holding more than cap would show fewer offsets and a larger
“and N more” than an uncapped list. The count stays exact either way.
Sourcepub fn push(&mut self, sighting: Sighting)
pub fn push(&mut self, sighting: Sighting)
Record sighting: stored while its group holds fewer than the cap,
and always counted. A sighting’s own Sighting::more is counted
too.
Sourcepub fn count(
&self,
format: FormatId,
shape: &'static str,
kind: SightingKind,
) -> u64
pub fn count( &self, format: FormatId, shape: &'static str, kind: SightingKind, ) -> u64
The exact number of sightings of this group pushed, stored or not.
Sourcepub fn into_sightings(self) -> Vec<Sighting>
pub fn into_sightings(self) -> Vec<Sighting>
The stored sightings, groups in first-seen order, each group’s last
one carrying the count of those not stored in Sighting::more.
The offsets kept are the first cap of each group in PUSH order, so
a scanner that wants the smallest listed must push each group in
ascending offset order.