Expand description
§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§
Modules§
- entry
- Map entries.
- iter
- Iterator types for
Map
- primitive
- Contains
Collapse
impls for primitive types through a newtype shim. - space
- Space-efficient small maps and sets
Macros§
- smallmap
- A helper macro for creating
Map
instances with or without pre-set entries.
Structs§
- Map
- A small hashtable-like map with byte sized key indecies.
- Page
- A single page in a
Map
. Contains up to 256 key-value entries.
Traits§
- Collapse
- Trait for types that can be used as
Map
keys.
Functions§
- collapse
- Collapse a slice of bytes with an XOR fold
- collapse_
iter - Collapse an iterator of bytes with an XOR fold
Type Aliases§
- Set
- A smallmap set.