pi_append_vec

Crates.iopi_append_vec
lib.rspi_append_vec
version0.5.3
sourcesrc
created_at2023-10-09 04:27:34.218165
updated_at2024-06-13 05:27:22.036207
descriptionOnly supports append vectors, lock free
homepage
repositoryhttps://github.com/GaiaWorld/pi_slot.git
max_upload_size
id997627
size14,075
dev (github:gaiaworld:dev)

documentation

README

Thread-safe slotmap

slotmap

A Rust library providing three containers with persistent unique keys to access stored values. 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. Key maps, KeyMap 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.

[dependencies]
pi_slot = "0.1"

Example

A short example:

use slotmap::{SlotMap, SecondaryMap};

let 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 sec = KeyMap::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.

Commit count: 14

cargo fmt