enum-collections 0.1.0

Collections data structures optimized for Enum, initializable at runtime.
Documentation

Enum Collections for Rust

Rust

Enum Map is a special case of a Hash Map, with better computational complexity guarantees and overall performance.

Usage

EnumMap

Enum Map is a special case of a Hash Map, with better computational complexity guarantees and overall performance. Can differentiante between a missing (Option::None) and set (Option::Some) value.

use enum_collections::{enummap, EnumMap, Enumerated};
#[enum_collections]
enum Letter {
    A,
    B,
}

let mut map: EnumMap<Letter, u8> = EnumMap::new();
map.insert(Letter::A, 42);
assert_eq!(Some(&42u8), map.get(Letter::A))

EnumTable

Enum Map is a special case of a Hash Map, with better computational complexity guarantees and overall performance. Initialized with default values, can NOT differentiate between missing values and values actually set.

 use enum_collections::{enum_collections, EnumTable, Enumerated};
 #[enum_collections]
 enum Letter {
     A,
     B,
 }

 let mut map: EnumTable<Letter, u8> = EnumTable::new();
 map.insert(Letter::A, 42);
 assert_eq!(&42u8, map.get(Letter::A));
 assert_eq!(&u8::default(), map.get(Letter::B));

Benchmarks

There are single-threaded benchmarks for the get, insert and remove operations in enum-collections/benches. Invoke cargo bench to run them.

EnumMap

NAME                                     lower bound | est | upper bound
EnumMap get                      time:   [635.02 ps 635.52 ps 636.06 ps] est ~22x faster
std::collections::HashMap get    time:   [13.971 ns 13.986 ns 14.002 ns]

EnumMap insert                   time:   [947.20 ps 947.83 ps 948.52 ps] est ~14,7x faster
std::collections::HashMap insert time:   [13.938 ns 13.964 ns 13.994 ns]

EnumMap remove                   time:   [481.07 ps 481.79 ps 482.53 ps] est ~28,55x faster
std::collections::HashMap remove time:   [13.704 ns 13.737 ns 13.771 ns]

EnumTable

NAME                                     lower bound | est | upper bound
EnumTable get                            time:   [485.65 ps 488.63 ps 491.59 ps] est ~0.95x faster
Crate Enum-Map get                       time:   [465.44 ps 465.93 ps 466.43 ps]

EnumTable insert                         time:   [676.44 ps 677.17 ps 677.92 ps] est ~0.956x faster
Crate Enum-Map insert                    time:   [645.98 ps 647.60 ps 649.35 ps]