12个不稳定版本 (4个重大变更)
0.5.0 | 2024年1月21日 |
---|---|
0.4.0 | 2024年1月2日 |
0.3.0 | 2019年11月12日 |
0.2.6 | 2019年8月28日 |
0.1.1 | 2019年7月15日 |
#247 in 数据结构
每月80次下载
用于 2 crate
70KB
2K SLoC
map_vec
基于Vec的Map和Set API
map_vec::Map
是一个具有 HashMap
接口的数据结构。同样,map_vec::Set
是一个具有 HashSet
接口的数据结构。
基于向量的Map和Set主要用于关注常数因子或更倾向于确定性而非速度的场景。请参考HashMap和HashSet的文档以获取有关Map/Set API的详细信息和使用示例。
可选功能
使用支持 serde
的 map_vec
依赖项以在 Map
和 Set
上获得 Serialize
和 Deserialize
。但这需要 std
环境支持。
map_vec = { version = "0.3", features = ["serde"] }
Map示例
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示例
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);
}
依赖项
~0.4–1MB
~23K SLoC