#set #vec #map

no-std map_vec

The Map and Set APIs backed by Vec

13 unstable releases (5 breaking)

0.6.0 Sep 7, 2024
0.5.1-beta.1 Sep 7, 2024
0.5.0 Jan 21, 2024
0.4.0 Jan 2, 2024
0.1.1 Jul 15, 2019

#169 in Data structures

Download history 19/week @ 2024-08-16 12/week @ 2024-08-23 75/week @ 2024-08-30 356/week @ 2024-09-06 70/week @ 2024-09-13 69/week @ 2024-09-20 42/week @ 2024-09-27 32/week @ 2024-10-04 485/week @ 2024-10-11 281/week @ 2024-10-18 123/week @ 2024-10-25 131/week @ 2024-11-01 179/week @ 2024-11-08 235/week @ 2024-11-15 81/week @ 2024-11-22 71/week @ 2024-11-29

662 downloads per month
Used in 2 crates

MIT/Apache

75KB
2K SLoC

map_vec

The Map and Set APIs backed by Vecs

map_vec::Map is a data structure with the interface of HashMap. Similarly map_vec::Set is a data structure with the interface of HashSet.

Vector-backed maps and sets are primarily useful when you care about constant factors or prefer determinism to speed. Please refer to the docs for HashMap and HashSet for details on and examples of using the Map/Set API.

Optional features

Declare the map_vec dependency with serde support to get Serialize and Deserialize on Map and Set.

map_vec = { version = "0.6", features = ["serde"] }

Map Example

let mut map = map_vec::Map::new();
map.insert("hello".to_string(), "world".to_string());
map.entry("hello".to_string()).and_modify(|mut v| v.push_str("!"));
assert_eq!(map.get("hello").map(String::as_str), Some("world!"))

Set Example

let mut set1 = map_vec::Set::new();
let mut set2 = map_vec::Set::new();
set1.insert(1);
set1.insert(2);
set2.insert(2);
set2.insert(3);
let mut set3 = map_vec::Set::with_capacity(1);
assert!(set3.insert(3));
assert_eq!(&set2 - &set1, set3);

Dependencies

~160KB