Struct incr::Map[][src]

pub struct Map<K: Eq + Hash>(_);

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]

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.

Returns the highest observed value at key, or, if key does not exist, returns 0.

Trait Implementations

impl<K: Default + Eq + Hash> Default for Map<K>
[src]

Returns the "default value" for a type. Read more

impl<K: Clone + Eq + Hash> Clone for Map<K>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<K: PartialEq + Eq + Hash> PartialEq for Map<K>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<K: Debug + Eq + Hash> Debug for Map<K>
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<K> Send for Map<K> where
    K: Send

impl<K> Sync for Map<K> where
    K: Sync