slabmap

Crates.io Docs.rs Actions Status

This crate provides the type SlabMap. SlabMap is HashMap-like collection that automatically determines the key.

Install

Add this to your Cargo.toml:

toml [dependencies] slabmap = "0.1"

Examples

```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); ```

The difference between SlabMap and HashMap

The difference between 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().

Performance

The following chart shows the difference in performance between BTreeMap, HashMap, Slab(version 0.4.2), SlabMap(version 0.1.0) and, Vec,

Insert

insert performance

Remove random elements

remove random elements performance

Random access

random access performance

Sequential access

sequential access performance

Sequential access after removing elements from a 10,000-element collection

Sequential access after remove many elements performance

License

This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.

Contribution

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.