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>where
K: Eq + Hash,
impl<K> Map<K>where K: Eq + Hash,
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) -> u64where
K: Borrow<Q>,
Q: ?Sized + Hash + Eq,
pub fn get<Q>(&self, key: &Q) -> u64where K: Borrow<Q>, Q: ?Sized + Hash + Eq,
Returns the highest observed value at key
, or, if key
does not exist,
returns 0
.
pub fn contains_key<Q>(&self, key: &Q) -> boolwhere K: Borrow<Q>, Q: ?Sized + Hash + Eq,
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
source§impl<K: PartialEq + Eq + Hash> PartialEq<Map<K>> for Map<K>
impl<K: PartialEq + Eq + Hash> PartialEq<Map<K>> for Map<K>
impl<K: Eq + Hash> StructuralPartialEq for Map<K>
Auto Trait Implementations§
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