#slotmap #slab #pi #graph-node #low-overhead

nightly no-std pi_slotmap

Slotmap data structure

17 releases

0.2.0 Aug 16, 2023
0.1.17 May 29, 2024
0.1.16 Feb 28, 2024
0.1.15 Oct 10, 2023
0.1.0 Mar 4, 2022

#177 in Data structures

Download history 66/week @ 2024-07-14 49/week @ 2024-07-21 43/week @ 2024-07-28 45/week @ 2024-08-04 42/week @ 2024-08-11 40/week @ 2024-08-18 42/week @ 2024-08-25 33/week @ 2024-09-01 41/week @ 2024-09-08 43/week @ 2024-09-15 86/week @ 2024-09-22 40/week @ 2024-09-29 18/week @ 2024-10-06 29/week @ 2024-10-13 30/week @ 2024-10-20 37/week @ 2024-10-27

114 downloads per month
Used in 21 crates (14 directly)

MIT/Apache

320KB
5K SLoC

该库slotmap的一份拷贝,另外添加了一些新的功能

slotmap

A Rust library providing three containers with persistent unique keys to access stored values, SlotMap, HopSlotMap and DenseSlotMap. Upon insertion a key is returned that can be used to later access or remove the values. Insertion, deletion and access all take O(1) time with low overhead. Great for storing collections of objects that need stable, safe references but have no clear ownership otherwise, such as game entities or graph nodes. Two secondary maps, SecondaryMap and SparseSecondaryMap are also provided that allow you to map further objects to the keys created by one of the slot maps. Please refer to the the documentation for more information.

The minimum required stable Rust version for slotmap is 1.49. To start using slotmap add the following to your Cargo.toml:

[dependencies]
slotmap = "1.0"

Example

A short example:

use slotmap::{SlotMap, SecondaryMap};

let mut sm = SlotMap::new();
let foo = sm.insert("foo");  // Key generated on insert.
let bar = sm.insert("bar");
assert_eq!(sm[foo], "foo");
assert_eq!(sm[bar], "bar");

sm.remove(bar);
let reuse = sm.insert("reuse");  // Space from bar reused.
assert_eq!(sm.contains_key(bar), false);  // After deletion a key stays invalid.

let mut sec = SecondaryMap::new();
sec.insert(foo, "noun");  // We provide the key for secondary maps.
sec.insert(reuse, "verb");

for (key, val) in sm {
    println!("{} is a {}", val, sec[key]);
}

License

slotmap is released under the Zlib license, a permissive license. It is OSI and FSF approved and GPL compatible.

Dependencies

~0.7–1.3MB
~27K SLoC