Crates.io | slabmap |
lib.rs | slabmap |
version | 0.2.1 |
source | src |
created_at | 2020-07-01 04:13:45.626536 |
updated_at | 2024-05-23 03:28:39.737981 |
description | HashMap-like collection that automatically determines the key. |
homepage | |
repository | https://github.com/frozenlib/slabmap |
max_upload_size | |
id | 260157 |
size | 97,597 |
This crate provides the type SlabMap
.
SlabMap
is HashMap-like collection that automatically determines the key.
Add this to your Cargo.toml:
[dependencies]
slabmap = "0.2.0"
use slabmap::SlabMap;
let mut s = SlabMap::new();
let key_a = s.insert("aaa");
let key_b = s.insert("bbb");
assert_eq!(s[key_a], "aaa");
assert_eq!(s[key_b], "bbb");
for (key, value) in &s {
println!("{} -> {}", key, value);
}
assert_eq!(s.remove(key_a), Some("aaa"));
assert_eq!(s.remove(key_a), None);
SlabMap
and HashMap
SlabMap
can only use usize as a key.SlabMap
is determined automatically.SlabMap
runs faster than HashMap
.SlabMap
and Slab
Carl Lerche's slab
crate provides a slab implementation with a similar API.
For both Slab
and SlabMap
, after adding many elements to the collection, removing many element will reduce iterate performance.
However, unlike Slab
, SlabMap
can improve iterate performance by calling SlabMap::optimize()
.
The following chart shows the difference in performance between
BTreeMap
,
HashMap
,
Slab
(version 0.4.2),
SlabMap
(version 0.1.0) and,
Vec
,
This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.