[−][src]Crate smallmap
smallmap
A small table map with a byte sized key index.
With a key type which all invariants can be represented as unique bytes, searching this map is a single index dereference. With only a few bytes it is still very efficient.
Usage
The API is a similar subset to HashMap
, containing the same insert
, get
, and entry
functions:
fn max_char(chars: &str) -> (char, usize) { let mut map = Map::new(); for x in chars.chars() { *map.entry(x).or_insert(0usize) += 1; } map.into_iter().max_by_key(|&(_, v)| v).unwrap_or_default() }
Use cases
Designed for instances where you want a small map with small key types. Performance greately outpaces complex hash-based maps in these cases.
When not to use
Generally don't use this if your key would have a lot of collisions being represents in 8 bits, otherwise it might be a faster alternative to hash-based maps. You should check yourself before sticking with this crate instead of std
's vectorised map implementations.
Re-exports
pub use entry::Entry; |
Modules
entry | Map entries. |
iter | Iterator types for |
Structs
Map | A small hashtable-like map with byte sized key indecies. |
Page | A single page in a |
Traits
Collapse | Trait for types that can be used as |
Functions
collapse | Collapse a slice of bytes with an XOR fold |
collapse_iter | Collapse an iterator of bytes with an XOR fold |