pub struct Map<K: Eq + Hash>(/* private fields */);
Expand description
A map interface allowing fast checks of whether a newly observed value is greater than any previously observed value for a given key.
The inner map is a HashMap<K, u64>
. The signature of Map
’s is_new
is
unique from the others in also requiring a key.
§Examples
use incr::Map;
let mut last: Map<&'static str> = Default::default();
assert_eq!(last.is_new("a", 1), true);
assert_eq!(last.is_new("b", 1), true);
assert_eq!(last.is_new("a", 1), false);
assert_eq!(last.is_new("b", 3), true);
assert_eq!(last.is_new("c", 1), true);
assert_eq!(last.is_new("c", 1), false);
assert_eq!(last.get(&"b"), 3);
assert_eq!(last.get(&"not a key"), 0);
Implementations§
Source§impl<K> Map<K>
impl<K> Map<K>
Sourcepub fn is_new(&mut self, k: K, val: u64) -> bool
pub fn is_new(&mut self, k: K, val: u64) -> bool
Returns true
if val
is greater than the highest observed value at
key
. If key
does not exist, inserts val
at key
and returns true
.
Sourcepub fn get<Q>(&self, key: &Q) -> u64
pub fn get<Q>(&self, key: &Q) -> u64
Returns the highest observed value at key
, or, if key
does not exist,
returns 0
.
pub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
impl<K: Eq + Hash> StructuralPartialEq for Map<K>
Auto Trait Implementations§
impl<K> Freeze for Map<K>
impl<K> RefUnwindSafe for Map<K>where
K: RefUnwindSafe,
impl<K> Send for Map<K>where
K: Send,
impl<K> Sync for Map<K>where
K: Sync,
impl<K> Unpin for Map<K>where
K: Unpin,
impl<K> UnwindSafe for Map<K>where
K: 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