Thunderation 🌩️
Thunderation is a generational arena forked from Thunderdome. It adds a few improvements like unique key type identifiers, improved methods, and the removal of all unsafe code.
It provides constant time insertion,
lookup, and removal via small (8 byte) keys returned from Arena.
Thunderation's key type, Key, is still 8 bytes when put inside of an
Option<T> thanks to Rust's NonZero* types.
Why use this over slotmap?
The main reason is when you need to get and set values by their slot index in addition to generational keys. If you do not need this, consider using slotmap instead.
Basic Examples
use ;
// Define a unique key type identifier. This prevents keys from
// being used in Arena's they don't belong to.
;
// Create an arena with the given key type and the storage type.
let mut arena = new;
let foo = arena.insert;
let bar = arena.insert;
assert_eq!;
assert_eq!;
// Methods to get/set items by slot index are also available.
let = arena.get_by_slot.unwrap;
assert_eq!;
assert_eq!;
arena = "Replaced";
assert_eq!;
let foo_value = arena.remove;
assert_eq!;
// The slot previously used by foo will be reused for baz
let baz = arena.insert;
assert_eq!;
// foo is no longer a valid key
assert_eq!;
Comparison With Similar Crates
| Feature | Thunderation | Thunderdome | generational-arena | typed-generational-arena | slotmap | slab |
|---|---|---|---|---|---|---|
| Generational¹ | Yes | Yes | Yes | Yes | Yes | No |
size_of::<Key>() |
8 | 8 | 16 | varies | 8 | 8 |
size_of::<Option<Key>>() |
8 | 8 | 24 | varies | 8 | 16 |
| Max elements | 2³² | 2³² | 2⁶⁴ | 2⁶⁴ | 2³² | 2⁶⁴ |
Non-Copy values |
Yes | Yes | Yes | Yes | Yes | Yes |
no_std support |
Yes | Yes | Yes | Yes | Yes | Yes |
| Uniquely typed keys | Yes | No | No | Yes | Yes | No |
| Get/set values by slot index | Yes | Yes | No | No | No | Yes |
| Zero unsafe used | Yes | No | Yes | Yes | No | No |
| Serde support | No | No | Yes | Yes | Yes | No |
- Generational indices help solve the ABA Problem, which can cause dangling keys to mistakenly access newly-inserted data.
Crate Features
std(default): Use the standard library. Disable to make this crateno-stdcompatible.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.