Struct tinyset::u64set::Map64
[−]
[src]
pub struct Map64<K: Fits64, V> { /* fields omitted */ }
A map type that can use any key that fits in a u64
(i.e. that
satisfies trait Fits64
). This map type is very space-efficient
for keys that are small integers, while not being bad at storing
large integers.
Major caveat The Map64<K,V>
defines an iterator that
iterates over (K, &V)
rather than (&K, &V)
. This is a break
with standard libray convention, and can be annoying if you are
translating code from HashMap
to Map64
. The motivation for
this is several-fold:
Map64
does not storeK
directly in its data structures (which would waste space), so there is no reference to the data to take. This does not make it impossible, but does mean we would have to fabricate aK
and return a reference to it, which is awkward and ugly.There is no inefficiency involved in returning
K
, since it is necessarily no larger than a pointer (except on a 32-bit system).
Examples
use tinyset::Map64; let mut a: Map64<char,&str> = Map64::new(); a.insert('a', "hello"); a.insert('b', "world"); assert_eq!(a.get('a'), Some(&"hello")); assert_eq!(a.get('b'), Some(&"world"));
Methods
impl<K: Fits64, V> Map64<K, V>
[src]
fn new() -> Self
[src]
Creates an empty Map64
.
fn len(&self) -> usize
[src]
Returns the number of elements in the map.
fn insert(&mut self, k: K, v: V) -> Option<V>
[src]
Inserts a key-value pair into the map.
If the map did not have this key present, None is returned.
If the map did have this key present, the value is updated, and the old value is returned.
fn reserve(&mut self, additional: usize)
[src]
Reserves capacity for at least additional
more elements to
be inserted in the Map64
. The collection may reserve more
space to avoid frequent reallocations.
fn remove(&mut self, k: K) -> Option<V>
[src]
Removes a key from the map, returning the value at the key if the key was previously in the map.
fn get(&self, k: K) -> Option<&V>
[src]
Returns a reference to the value corresponding to the key.
fn iter(&self) -> Map64Iter<K, V>
[src]
An iterator visiting all key-value pairs in arbitrary order. The iterator element type is (K, &V).
Trait Implementations
impl<K: Clone + Fits64, V: Clone> Clone for Map64<K, V>
[src]
fn clone(&self) -> Map64<K, V>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<K: Fits64, V: PartialEq> PartialEq for Map64<K, V>
[src]
fn eq(&self, other: &Map64<K, V>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.