Crate smallmap

source ·
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

  • Map entries.
  • Iterator types for Map
  • Contains Collapse impls for primitive types through a newtype shim.
  • Space-efficient small maps and sets

Macros

  • A helper macro for creating Map instances with or without pre-set entries.

Structs

  • A small hashtable-like map with byte sized key indecies.
  • A single page in a Map. Contains up to 256 key-value entries.

Traits

  • Trait for types that can be used as Map keys.

Functions

  • Collapse a slice of bytes with an XOR fold
  • Collapse an iterator of bytes with an XOR fold

Type Aliases

  • A smallmap set.