#slotmap #arena-allocator #reference #arena #allocator #storage

no-std slotmap-fork-otter

Slotmap data structure - temporary fork for Otter

1 stable release

1.0.2 Apr 18, 2021

#1023 in Data structures

Download history 4/week @ 2023-12-17 3/week @ 2023-12-24 8/week @ 2024-02-04 8/week @ 2024-02-11 16/week @ 2024-02-18 30/week @ 2024-02-25 18/week @ 2024-03-03 18/week @ 2024-03-10 14/week @ 2024-03-17

82 downloads per month
Used in 7 crates (via otter-support)

Zlib license

265KB
4K SLoC

This is a fork

The original is here: https://github.com/orlp/slotmap

This fork exists only because https://github.com/orlp/slotmap/issues/55 and https://github.com/orlp/slotmap/pull/56 remain un-reviewed upstream.

The git source for this fork is here: https://github.com/ijackson/slotmap/tree/slotmap-fork-otter

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 SparseSlotMap 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

~180KB