1 unstable release
new 0.1.0 | Dec 16, 2024 |
---|
#650 in Data structures
28KB
598 lines
MuleMap<🫏,🗺>
MuleMap
is a hybrid between a HashMap
and a lookup table. Use MuleMap
when the majority of your map accesses use keys that are near a fixed point n
(by default we assume for keys near 0). MuleMap
tries to match the API of the standard library HashMap
(where possible) - making it mostly a drop in replacement for HashMap
.
Example
use MuleMap;
type Hash = fnv_rs::FnvBuildHasher; // Use whatever hash function you prefer
let mut mule_map = MuleMap::<u32, usize, Hash>::new();
assert_eq!(mule_map.get(5), None);
let entry = mule_map.entry(5);
entry.or_insert(10);
assert_eq!(mule_map.get(5), Some(&10));
Limitations
- Only supports keys that are primitive integer types (
u8
,u16
,u32
,u64
,u128
,,usize
i8
,i16
,i32
,i64
,i128
, and). Non-primitive keys could be added if demand is seen, otherwise not likely.isize
- Does not support automatically converting enum's with primitive representations. Likely to be added in the future.
- Currently the type of a const generic can't depend on another generic type argument, so
TABLE_MIN_VALUE
andTABLE_MAX_VALUE
can't use the same type as the key. Because of this, I am usingi128
, but that means we can't represent values nearu128::MAX
. Hopefully having frequent keys nearu128::MAX
is extremely rare. - Currently requires
std
, but if there is demand it would not be hard to makeno_std
.
Micro Benchmarks
Dependencies
~0.3–0.8MB
~19K SLoC