1# slotmap 2 3A Rust library providing three containers with persistent unique keys to access 4stored values, `SlotMap`, `HopSlotMap` and `DenseSlotMap`. Upon insertion a key 5is returned that can be used to later access or remove the values. Insertion, 6deletion and access all take O(1) time with low overhead. Great for storing 7collections of objects that need stable, safe references but have no clear 8ownership otherwise, such as game entities or graph nodes. Two secondary maps, 9`SecondaryMap` and `SparseSlotMap` are also provided that allow you to map 10further objects to the keys created by one of the slot maps. Please refer to the 11[**the documentation**](https://docs.rs/slotmap) for more information. 12 13To start using `slotmap` add the following to your `Cargo.toml`: 14 15```toml 16[dependencies] 17slotmap = "0.4" 18``` 19 20# Example 21 22A short example: 23 24```rust 25use slotmap::{SlotMap, SecondaryMap}; 26 27let mut sm = SlotMap::new(); 28let foo = sm.insert("foo"); // Key generated on insert. 29let bar = sm.insert("bar"); 30assert_eq!(sm[foo], "foo"); 31assert_eq!(sm[bar], "bar"); 32 33sm.remove(bar); 34let reuse = sm.insert("reuse"); // Space from bar reused. 35assert_eq!(sm.contains_key(bar), false); // After deletion a key stays invalid. 36 37let mut sec = SecondaryMap::new(); 38sec.insert(foo, "noun"); // We provide the key for secondary maps. 39sec.insert(reuse, "verb"); 40 41for (key, val) in sm { 42 println!("{} is a {}", val, sec[key]); 43} 44``` 45 46# License 47 48`slotmap` is released under the Zlib license, a permissive license. It is 49OSI and FSF approved and GPL compatible. 50