pub struct CategoryCounter<T: Hash + Eq> { /* private fields */ }Expand description
Accumulator for categorical data (counts by category)
Memory: O(k) where k is the number of unique categories
Implementations§
Source§impl<T: Hash + Eq> CategoryCounter<T>
impl<T: Hash + Eq> CategoryCounter<T>
Sourcepub fn increment_by(&mut self, category: T, amount: usize)
pub fn increment_by(&mut self, category: T, amount: usize)
Increment count for a category by a specific amount
Sourcepub fn num_categories(&self) -> usize
pub fn num_categories(&self) -> usize
Get the number of unique categories
Sourcepub fn categories(&self) -> &HashMap<T, usize>
pub fn categories(&self) -> &HashMap<T, usize>
Get all categories and their counts
Source§impl CategoryCounter<String>
Specialized implementation for String to allow efficient &str increments
impl CategoryCounter<String>
Specialized implementation for String to allow efficient &str increments
Sourcepub fn increment_str(&mut self, category: &str)
pub fn increment_str(&mut self, category: &str)
Optimized increment for &str - only allocates when category is new
This is much more efficient than increment(category.to_string()) because it only allocates a String when inserting a new category, not on every call.
For existing categories, this does a HashMap lookup with &str (no allocation), and only allocates a new String when the category is seen for the first time.
Trait Implementations§
Source§impl<T: Clone + Hash + Eq> Clone for CategoryCounter<T>
impl<T: Clone + Hash + Eq> Clone for CategoryCounter<T>
Source§fn clone(&self) -> CategoryCounter<T>
fn clone(&self) -> CategoryCounter<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Default + Hash + Eq> Default for CategoryCounter<T>
impl<T: Default + Hash + Eq> Default for CategoryCounter<T>
Source§fn default() -> CategoryCounter<T>
fn default() -> CategoryCounter<T>
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<T> Freeze for CategoryCounter<T>
impl<T> RefUnwindSafe for CategoryCounter<T>where
T: RefUnwindSafe,
impl<T> Send for CategoryCounter<T>where
T: Send,
impl<T> Sync for CategoryCounter<T>where
T: Sync,
impl<T> Unpin for CategoryCounter<T>where
T: Unpin,
impl<T> UnsafeUnpin for CategoryCounter<T>
impl<T> UnwindSafe for CategoryCounter<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more