Struct abstutil::collections::Counter
source · pub struct Counter<T: Ord + PartialEq + Clone> {
map: BTreeMap<T, usize>,
sum: usize,
}
Expand description
A counter per key
Fields§
§map: BTreeMap<T, usize>
§sum: usize
Implementations§
source§impl<T: Ord + PartialEq + Clone> Counter<T>
impl<T: Ord + PartialEq + Clone> Counter<T>
pub fn new() -> Counter<T>
pub fn add(&mut self, val: T, amount: usize) -> usize
pub fn inc(&mut self, val: T) -> usize
sourcepub fn sorted_asc(&self) -> Vec<Vec<T>>
pub fn sorted_asc(&self) -> Vec<Vec<T>>
Values with the same count are grouped together
pub fn highest_n(&self, n: usize) -> Vec<(T, usize)>
sourcepub fn max_key(&self) -> T
pub fn max_key(&self) -> T
If two keys share the maximum, returns one of them arbitrarily (and deterministically)
pub fn max(&self) -> usize
pub fn sum(&self) -> usize
pub fn compare(self, other: Counter<T>) -> Vec<(T, usize, usize)>
pub fn borrow(&self) -> &BTreeMap<T, usize>
pub fn consume(self) -> BTreeMap<T, usize>
pub fn is_empty(&self) -> bool
pub fn extend(&mut self, other: Counter<T>)
Trait Implementations§
source§impl<'de, T> Deserialize<'de> for Counter<T>
impl<'de, T> Deserialize<'de> for Counter<T>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T: PartialEq + Ord + PartialEq + Clone> PartialEq for Counter<T>
impl<T: PartialEq + Ord + PartialEq + Clone> PartialEq for Counter<T>
impl<T: Ord + PartialEq + Clone> StructuralPartialEq for Counter<T>
Auto Trait Implementations§
impl<T> Freeze for Counter<T>
impl<T> RefUnwindSafe for Counter<T>where
T: RefUnwindSafe,
impl<T> Send for Counter<T>where
T: Send,
impl<T> Sync for Counter<T>where
T: Sync,
impl<T> Unpin for Counter<T>
impl<T> UnwindSafe for Counter<T>where
T: RefUnwindSafe,
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