[][src]Struct tinyset::u64set::Map64

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:

  1. Map64 does not store K 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 a K and return a reference to it, which is awkward and ugly.

  2. 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: Clone + Fits64, V: Clone> Clone for 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: Eq> Eq for Map64<K, V>[src]

impl<K: Fits64, V: PartialEq> PartialEq<Map64<K, V>> for Map64<K, V>[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

impl<K, V> Sync for Map64<K, V> where
    K: Sync,
    V: Sync

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]