Expand description
HybridMap is a Rust™ hybrid map implementation that uses a vector for small maps and a hash map overwise.
As with most hybrid technologies, including two components instead of one is one too many. However, the hybrid solution can provide some value for specific use cases.
HybridMap can be slightly faster for tiny maps, especially short-lived ones living on the memory stack, usually up to 16 entries and without too many lookups.
§Example
HybridMap can be used like most other maps.
use hybridmap::HybridMap;
let mut map = HybridMap::<i32, &str, 8>::new();
map.insert(1, "one");
map.insert(2, "two");
assert_eq!(map.get(&1), Some(&"one"));
assert_eq!(map.len(), 2);
§Why ?
I started benchmarking tiny maps to check whether I should switch from HashMap to BTreeMap for my use case. I also had a naive Vec implementation that was surprisingly faster for my use case. Thus, I made this crate for fun.
The energy savings this crate may bring probably do not compensate for the energy I used to boil water for my tea while implementing this crate. But it was fun.
Structs§
- A map that uses a
Vec
for small numbers of elements and aHashMap
for larger numbers of elements.
Enums§
- A consuming iterator over the entries of a
HybridMap
. - An iterator over the entries of a
HybridMap
. - A mutable iterator over the entries of a
HybridMap
.