This crate provides the type SlabMap
.
SlabMap
is HashMap-like collection that automatically determines the key.
Add this to your Cargo.toml:
toml
[dependencies]
slabmap = "0.1"
```rust use slabmap::SlabMap;
let mut s = SlabMap::new(); let keya = s.insert("aaa"); let keyb = s.insert("bbb");
asserteq!(s[keya], "aaa"); asserteq!(s[keyb], "bbb");
for (key, value) in &s { println!("{} -> {}", key, value); }
asserteq!(s.remove(keya), Some("aaa")); asserteq!(s.remove(keya), 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 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.