17 releases
0.5.1 | Jun 2, 2020 |
---|---|
0.5.0 | Jun 2, 2020 |
0.4.2 | Jun 15, 2019 |
0.3.4 | May 17, 2019 |
0.1.1 | Mar 30, 2019 |
#1509 in Algorithms
42 downloads per month
41KB
915 lines
nummap
Defines a wrapper around a HashMap
of number values which behaves as if ALL keys are mapped but 0
values are not stored.
lib.rs
:
Defines the [NumMap] struct which acts as if all unmapped keys have a value of 0.
let mut map = map![(1, 2), (3, 4)];
//We have set no mapping but we still get 0.
assert_eq!(map.get(&0,), 0,);
//We didn't set a mapping here either but we still get 0.
assert_eq!(map.set(0, 10,), 0,);
assert_eq!(map.get(&0,), 10,);
Since all keys are considered mapped arithmetic is implemented on values.
let map = map![(1, 2), (3, 4)] + map![(1, 4), (3, 2)];
assert_eq!(map, map![(1, 3), (3, 3)] * 2,);
Author --- daniel.bechaz@gmail.com
Last Moddified --- 2020-01-06
Dependencies
~0–365KB