#[non_exhaustive]pub struct GroupStats {
pub count: u64,
pub sum: f64,
pub min: Option<IndexValue>,
pub max: Option<IndexValue>,
}Expand description
One group’s live statistics.
use kevy_index::{GroupStats, IndexValue};
let mut total = GroupStats::default();
let mut part = GroupStats::default();
(part.count, part.sum, part.min, part.max) = (2, 10.0, Some(IndexValue::I64(3)), Some(IndexValue::I64(7)));
total.merge(&part);
assert_eq!(total.avg(), Some(5.0));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.count: u64Rows in the group.
s.apply(b"o:1", row(b"eu", 30));
s.apply(b"o:2", row(b"eu", 12));
assert_eq!(s.group(b"eu").count, 2);
s.apply(b"o:2", AggRow::Removed);
assert_eq!(s.group(b"eu").count, 1);sum: f64Sum of the aggregated field (f64 accumulation — the i64 overflow guard; precision bounds documented).
s.apply(b"o:1", row(b"eu", 30));
s.apply(b"o:2", row(b"eu", 12));
assert_eq!(s.group(b"eu").sum, 42.0);min: Option<IndexValue>Exact minimum (None only when count == 0).
s.apply(b"o:1", row(b"eu", 30));
s.apply(b"o:2", row(b"eu", 12));
assert_eq!(s.group(b"eu").min, Some(IndexValue::I64(12)));
// exact under deletion: the next-smallest value takes over
s.apply(b"o:2", AggRow::Removed);
assert_eq!(s.group(b"eu").min, Some(IndexValue::I64(30)));
assert_eq!(s.group(b"us").min, None, "an unknown group has no rows");max: Option<IndexValue>Exact maximum.
s.apply(b"o:1", row(b"eu", 30));
s.apply(b"o:2", row(b"eu", 12));
assert_eq!(s.group(b"eu").max, Some(IndexValue::I64(30)));
s.apply(b"o:1", row(b"eu", 5));
assert_eq!(s.group(b"eu").max, Some(IndexValue::I64(12)));Implementations§
Source§impl GroupStats
impl GroupStats
Sourcepub fn avg(&self) -> Option<f64>
pub fn avg(&self) -> Option<f64>
Derived average.
assert_eq!(kevy_index::GroupStats::default().avg(), None);Sourcepub fn rank_score(&self, by: AggBy) -> f64
pub fn rank_score(&self, by: AggBy) -> f64
This group’s standing under by, oriented so a larger score ranks
higher for every metric — the order sort_groups puts groups in
(a smaller minimum ranks higher; a group without one ranks last).
use kevy_index::{AggBy, GroupStats, IndexValue};
let mut g = GroupStats::default();
(g.count, g.min) = (3, Some(IndexValue::I64(2)));
assert_eq!((g.rank_score(AggBy::Count), g.rank_score(AggBy::Min)), (3.0, -2.0));
assert_eq!(g.rank_score(AggBy::Max), f64::NEG_INFINITY);Sourcepub fn merge(&mut self, part: &GroupStats)
pub fn merge(&mut self, part: &GroupStats)
Fold one shard’s partial for the same group into this one (reduce side): counts and sums add, min and max take the extremes.
use kevy_index::{GroupStats, IndexValue};
let mut a = GroupStats::default();
a.count = 1;
a.min = Some(IndexValue::I64(5));
let mut b = GroupStats::default();
b.count = 1;
b.min = Some(IndexValue::I64(2));
a.merge(&b);
assert_eq!((a.count, a.min), (2, Some(IndexValue::I64(2))));Trait Implementations§
Source§impl Clone for GroupStats
impl Clone for GroupStats
Source§fn clone(&self) -> GroupStats
fn clone(&self) -> GroupStats
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for GroupStats
impl Debug for GroupStats
Source§impl Default for GroupStats
impl Default for GroupStats
Source§fn default() -> GroupStats
fn default() -> GroupStats
Returns the “default value” for a type. Read more
Source§impl PartialEq for GroupStats
impl PartialEq for GroupStats
impl StructuralPartialEq for GroupStats
Auto Trait Implementations§
impl Freeze for GroupStats
impl RefUnwindSafe for GroupStats
impl Send for GroupStats
impl Sync for GroupStats
impl Unpin for GroupStats
impl UnsafeUnpin for GroupStats
impl UnwindSafe for GroupStats
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more