#number #num #hashmap

nightly no-std nummap

Defines a wrapper around a HashMap of number values which behaves as if ALL keys are mapped but 0 values are not stored

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

#8 in #num

Download history 17/week @ 2021-08-05 17/week @ 2021-08-12 2/week @ 2021-09-02 1/week @ 2021-09-09 18/week @ 2021-09-30 18/week @ 2021-10-14 33/week @ 2021-11-04 2/week @ 2021-11-18

76 downloads per month

0BSD license

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.

# #[macro_use] extern crate nummap; fn main() {
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.

# #[macro_use] extern crate nummap; fn main() {
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

~185KB

‚vÖ^