#vec #map #set

no-std map_vec

The Map and Set APIs backed by Vec

12 unstable releases (4 breaking)

0.5.0 Jan 21, 2024
0.4.0 Jan 2, 2024
0.3.0 Nov 12, 2019
0.2.6 Aug 28, 2019
0.1.1 Jul 15, 2019

#173 in Data structures

Download history 210/week @ 2023-12-18 219/week @ 2023-12-25 214/week @ 2024-01-01 228/week @ 2024-01-08 85/week @ 2024-01-15 24/week @ 2024-01-22 33/week @ 2024-01-29 25/week @ 2024-02-05 58/week @ 2024-02-12 53/week @ 2024-02-19 83/week @ 2024-02-26 59/week @ 2024-03-04 56/week @ 2024-03-11 45/week @ 2024-03-18 32/week @ 2024-03-25 68/week @ 2024-04-01

210 downloads per month
Used in 4 crates (3 directly)

MIT/Apache

70KB
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. This requires a std environment, though.

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

Map Example

fn main() {
  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

fn main() {
  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

~0.4–1MB
~24K SLoC