#reference #slotmap #arena #key-storage #arena-allocator #invariants #storage

no-std slotmapd

orlp/slotmap fork where serialization cycle doesn't change observable behavior

6 stable releases

1.0.11 Jul 17, 2024
1.0.10 Aug 8, 2023
1.0.9 Aug 3, 2023

#58 in Memory management

Download history 510/week @ 2024-07-30 323/week @ 2024-08-06 393/week @ 2024-08-13 301/week @ 2024-08-20 488/week @ 2024-08-27 380/week @ 2024-09-03 284/week @ 2024-09-10 258/week @ 2024-09-17 408/week @ 2024-09-24 266/week @ 2024-10-01 241/week @ 2024-10-08 181/week @ 2024-10-15 433/week @ 2024-10-22 410/week @ 2024-10-29 395/week @ 2024-11-05 255/week @ 2024-11-12

1,574 downloads per month
Used in flat_spatial

Zlib license

285KB
4.5K SLoC

Fork

This is a fork of orlp/slotmap where going through a serialization cycle doesn't change observable behavior (such as new key values or iteration order).

Please use the original library if you do not need this invariant as this fork will not be as maintained.

slotmap_deterministic

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 slotmapd::{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