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:

  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]

[src]

Creates an empty Map64.

[src]

Returns the number of elements in the map.

[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.

[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.

[src]

Removes a key from the map, returning the value at the key if the key was previously in the map.

[src]

Returns a reference to the value corresponding to the key.

[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]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<K: Fits64, V: PartialEq> PartialEq for Map64<K, V>
[src]

[src]

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

1.0.0
[src]

This method tests for !=.

impl<K: Fits64, V: Eq> Eq for Map64<K, V>
[src]