pub struct HashMap<K, V> { priv k0: u64, priv k1: u64, priv resize_at: uint, priv size: uint, priv buckets: ~[Option<Bucket<K, V>>], }
A hash map implementation which uses linear probing along with the SipHash hash function for internal state. This means that the order of all hash maps is randomized by keying each hash map randomly on creation.
It is required that the keys implement the Eq
and Hash
traits, although
this can frequently be achieved by just implementing the Eq
and
IterBytes
traits as Hash
is automatically implemented for types that
implement IterBytes
.
impl<K: Hash + Eq, V> HashMap<K, V>
fn new() -> HashMap<K, V>
Create an empty HashMap
fn with_capacity(capacity: uint) -> HashMap<K, V>
Create an empty HashMap with space for at least capacity
elements in the hash table.
fn with_capacity_and_keys(k0: u64, k1: u64, capacity: uint) -> HashMap<K, V>
Create an empty HashMap with space for at least capacity
elements, using k0
and k1
as the keys.
Warning: k0
and k1
are normally randomly generated, and
are designed to allow HashMaps to be resistant to attacks that
cause many collisions and very poor performance. Setting them
manually using this function can expose a DoS attack vector.
fn reserve_at_least(&mut self, n: uint)
Reserve space for at least n
elements in the hash table.
fn mangle<'a, A>(&'a mut self, k: K, a: A, not_found: &fn(&K, A) -> V, found: &fn(&K, &mut V, A)) -> &'a mut V
Modify and return the value corresponding to the key in the map, or insert and return a new value if it doesn't exist.
fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a mut V
Return the value corresponding to the key in the map, or insert and return the value if it doesn't exist.
fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V) -> &'a mut V
Return the value corresponding to the key in the map, or create, insert, and return a new value if it doesn't exist.
fn insert_or_update_with<'a>(&'a mut self, k: K, v: V, f: &fn(&K, &mut V)) -> &'a mut V
Insert a key-value pair into the map if the key is not already present. Otherwise, modify the existing value for the key. Returns the new or modified value for the key.
fn get<'a>(&'a self, k: &K) -> &'a V
Retrieves a value for the given key, failing if the key is not present.
fn get_mut<'a>(&'a mut self, k: &K) -> &'a mut V
Retrieves a (mutable) value for the given key, failing if the key is not present.
fn contains_key_equiv<Q: Hash + Equiv<K>>(&self, key: &Q) -> bool
Return true if the map contains a value for the specified key, using equivalence
fn find_equiv<'a, Q: Hash + Equiv<K>>(&'a self, k: &Q) -> Option<&'a V>
Return the value corresponding to the key in the map, using equivalence
fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool
Visit all keys
fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool
Visit all values
fn iter<'a>(&'a self) -> HashMapIterator<'a, K, V>
An iterator visiting all key-value pairs in arbitrary order. Iterator element type is (&'a K, &'a V).
fn mut_iter<'a>(&'a mut self) -> HashMapMutIterator<'a, K, V>
An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values. Iterator element type is (&'a K, &'a mut V).
fn move_iter(self) -> HashMapMoveIterator<K, V>
Creates a consuming iterator, that is, one that moves each key-value pair out of the map in arbitrary order. The map cannot be used after calling this.
impl<K: Hash + Eq, V: Clone> HashMap<K, V>
fn find_copy(&self, k: &K) -> Option<V>
Like find
, but returns a copy of the value.
fn get_copy(&self, k: &K) -> V
Like get
, but returns a copy of the value.
impl<A: ToStr + Hash + Eq, B: ToStr> ToStr for HashMap<A, B>
fn to_str(&self) -> ~str
Converts the value of self
to an owned string
impl<K: Hash + Eq, V> Container for HashMap<K, V>
fn len(&self) -> uint
Return the number of elements in the map
impl<K: Hash + Eq, V> Mutable for HashMap<K, V>
fn clear(&mut self)
Clear the map, removing all key-value pairs.
impl<K: Hash + Eq, V> Map<K, V> for HashMap<K, V>
fn find<'a>(&'a self, k: &K) -> Option<&'a V>
Return a reference to the value corresponding to the key
impl<K: Hash + Eq, V> MutableMap<K, V> for HashMap<K, V>
fn find_mut<'a>(&'a mut self, k: &K) -> Option<&'a mut V>
Return a mutable reference to the value corresponding to the key
fn swap(&mut self, k: K, v: V) -> Option<V>
Insert a key-value pair from the map. If the key already had a value present in the map, that value is returned. Otherwise None is returned.
fn pop(&mut self, k: &K) -> Option<V>
Removes a key from the map, returning the value at the key if the key was previously in the map.
impl<K: Hash + Eq, V: Eq> Eq for HashMap<K, V>
impl<K: Hash + Eq + Clone, V: Clone> Clone for HashMap<K, V>
fn clone(&self) -> HashMap<K, V>
Returns a copy of the value. The contents of owned pointers are copied to maintain uniqueness, while the contents of managed pointers are not copied.
impl<K: Eq + Hash, V> FromIterator<(K, V)> for HashMap<K, V>
fn from_iterator<T: Iterator<(K, V)>>(iter: &mut T) -> HashMap<K, V>
Build a container with elements from an external iterator.
impl<K: Eq + Hash, V> Extendable<(K, V)> for HashMap<K, V>
fn extend<T: Iterator<(K, V)>>(&mut self, iter: &mut T)
Extend a container with the elements yielded by an iterator
impl<K: Eq + Hash, V> Default for HashMap<K, V>
fn default() -> HashMap<K, V>
Return the "default value" for a type.
Prefix searches with a type followed by a colon (e.g.
fn:
) to restrict the search to a given type.
Accepted types are: fn
, mod
,
struct
(or str
), enum
,
trait
, typedef
(or
tdef
).