Crate thincollections

source ·
Expand description

Thin Collections for Rust

Alternative implementations for vector, map and set that are faster/smaller for some use cases.

ThinVec is a general vector replacement that only uses a single usize. std::collections::Vec uses 3. This makes ThinVec a much better choice when it’s used inside another data structure, such as a vector of vectors or a map of vectors, etc.

ThinMap is a specialized map replacement for small key values. It uses less memory than HashMap if mem::size_of::<(K, V)>() < 18. It’s also 2x to 5x faster (see the benchmarks). It’s perfect for all the primitives, or your own keys, but for custom keys, you must implement the ThinSentinel trait.

ThinSet uses ThinMap underneath, so it’s great for elements up to 18 bytes.

V64 is a specialized vector replacement that uses a single 64bit value to represent itself. It can store up to 7 bytes in that, and then uses heap memory. It’s ideal for small vectors, especially if those vectors are used inside other data structures.

Usage

Add this to your Cargo.toml:

[dependencies]
thincollections = "0.5.0"

and this to your crate root:

#[macro_use] extern crate thincollections;

Modules

Implementations of Hasher that work well with ThinMap/ThinSet
ThinMap: a fast map with lower memory usage for small key values.
A special trait required for ThinMap and ThinSet
ThinSet: a fast, low memory set implementation for small elements.
V64 a general Vec replacement in a single 64 bit pointer.
ThinVec a general Vec replacement in a single usize-sized pointer.

Macros

Creates a [ThinVec] containing the arguments.
Creates a [V64] containing the arguments.