2 releases
Uses new Rust 2024
| 0.1.1 | Jan 4, 2026 |
|---|---|
| 0.1.0 | Jan 4, 2026 |
#1292 in Data structures
14KB
344 lines
flatmap
Fast and efficient linear map and set for small collections.
Features
FlatMap<K, V>- Dynamic linear map with O(n) operationsFlatSet<K>- Dynamic linear set with O(n) operationsConstantFlatMap<K, V, N>- Fixed-size map with compile-time capacityConstantFlatSet<K, N>- Fixed-size set with compile-time capacity
Usage
use flatmap::{FlatMap, FlatSet, ConstantFlatMap, ConstantFlatSet};
// Dynamic map
let mut map = FlatMap::new();
map.insert("key", 42);
assert_eq!(map.get(&"key"), Some(&42));
// Dynamic set
let mut set = FlatSet::new();
set.insert("item");
assert!(set.has(&"item"));
// Fixed-size map
let const_map = ConstantFlatMap::from([("a", 1), ("b", 2)]);
assert_eq!(const_map.get(&"a"), Some(&1));
// Fixed-size set
let const_set = unsafe { ConstantFlatSet::from_entries_unchecked([1, 2, 3]) };
assert!(const_set.has(&2));
Performance
Optimized for small collections where linear search is faster than hash-based lookups due to better cache locality and lower overhead.
License
MIT