[−][src]Struct tinyset::u64set::Map64
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]
pub fn new() -> Map64<K, V>
[src]
Creates an empty Map64
.
pub fn with_capacity(cap: usize) -> Map64<K, V>
[src]
Creates an empty Map64
with the specified capacity.
pub 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.
pub 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.
pub fn contains_key(&self, k: &K) -> bool
[src]
Returns true if the key is in the map.
pub fn get(&self, k: &K) -> Option<&V>
[src]
Returns a reference to the value corresponding to the key.
pub fn len(&self) -> usize
[src]
len
ⓘImportant traits for Map64Iter<'a, K, V>pub 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: Fits64, V: Eq> Eq for Map64<K, V>
[src]
impl<K: Clone + Fits64, V: Clone> Clone for Map64<K, V>
[src]
fn clone(&self) -> Map64<K, V>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<K: Fits64, V> Drop for Map64<K, V>
[src]
impl<K: Fits64, V: PartialEq> PartialEq<Map64<K, V>> for Map64<K, V>
[src]
fn eq(&self, other: &Map64<K, V>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<K: Fits64 + Debug, V: Debug> Debug for Map64<K, V>
[src]
Auto Trait Implementations
impl<K, V> Send for Map64<K, V> where
K: Send,
V: Send,
K: Send,
V: Send,
impl<K, V> Sync for Map64<K, V> where
K: Sync,
V: Sync,
K: Sync,
V: Sync,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,