Struct incr::Map [−][src]
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);
Methods
impl<K> Map<K> where
K: Eq + Hash,
[src]
impl<K> Map<K> where
K: Eq + Hash,
pub fn is_new(&mut self, k: K, val: u64) -> bool
[src]
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
.
pub fn get<Q: ?Sized>(&self, key: &Q) -> u64 where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
pub fn get<Q: ?Sized>(&self, key: &Q) -> u64 where
K: Borrow<Q>,
Q: Hash + Eq,
Returns the highest observed value at key
, or, if key
does not exist,
returns 0
.
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq,
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Trait Implementations
impl<K: Default + Eq + Hash> Default for Map<K>
[src]
impl<K: Default + Eq + Hash> Default for Map<K>
impl<K: Clone + Eq + Hash> Clone for Map<K>
[src]
impl<K: Clone + Eq + Hash> Clone for Map<K>
fn clone(&self) -> Map<K>
[src]
fn clone(&self) -> Map<K>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0
[src]Performs copy-assignment from source
. Read more
impl<K: PartialEq + Eq + Hash> PartialEq for Map<K>
[src]
impl<K: PartialEq + Eq + Hash> PartialEq for Map<K>
fn eq(&self, other: &Map<K>) -> bool
[src]
fn eq(&self, other: &Map<K>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Map<K>) -> bool
[src]
fn ne(&self, other: &Map<K>) -> bool
This method tests for !=
.
impl<K: Debug + Eq + Hash> Debug for Map<K>
[src]
impl<K: Debug + Eq + Hash> Debug for Map<K>