C++ std::multimap Rust analog
Published 442d ago
cooluser
See title.
use std::collections::BTreeMap;
fn main() {
let mut multimap: BTreeMap<i32, Vec<String>> = BTreeMap::new();
// Insert values into the multimap
multimap
.entry(1)
.or_insert(vec![])
.push("apple".to_string());
multimap
.entry(2)
.or_insert(vec![])
.push("banana".to_string());
multimap
.entry(1)
.or_insert(vec![])
.push("apricot".to_string());
// Retrieve values
if let Some(values) = multimap.get(&1) {
for value in values {
println!("{}", value);
}
}
}
Please login or sign up to comment and collaborate