#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

✓ Uses Rust 2018 edition

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

#34 in Value formatting

Download history 15/week @ 2020-03-14 90/week @ 2020-03-21 16/week @ 2020-04-04 90/week @ 2020-04-11 1/week @ 2020-04-25 1/week @ 2020-05-16 15/week @ 2020-05-23 57/week @ 2020-05-30 25/week @ 2020-06-06 17/week @ 2020-06-13 4/week @ 2020-06-20 17/week @ 2020-06-27

94 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

~170KB