| Crates.io | slabigator |
| lib.rs | slabigator |
| version | 0.9.5 |
| created_at | 2022-06-22 17:46:53.978572+00 |
| updated_at | 2025-05-15 11:09:49.824144+00 |
| description | A fixed-capacity linked list with stable element addressing and no dynamic allocations |
| homepage | https://github.com/jedisct1/rust-slabigator |
| repository | https://github.com/jedisct1/rust-slabigator |
| max_upload_size | |
| id | 611031 |
| size | 63,738 |
A high-performance linked list that doesn't perform dynamic memory allocations after initialization. It allocates all necessary memory upfront with a fixed capacity, making it ideal for performance-critical applications where memory allocation patterns need to be predictable.
Slabigator was designed to do a few things extremely well:
It's designed to be:
use slabigator::Slab;
// Create a new slab with a capacity of 3 elements
let mut slab = Slab::with_capacity(3).unwrap();
// Add elements to the front - each operation returns a slot number
let slot_a = slab.push_front("a").unwrap();
let slot_b = slab.push_front("b").unwrap();
let slot_c = slab.push_front("c").unwrap();
// Slab is now full (capacity = 3)
assert!(slab.is_full());
assert_eq!(slab.len(), 3);
// Access elements directly by their slots
assert_eq!(slab.get(slot_a).unwrap(), &"a");
assert_eq!(slab.get(slot_b).unwrap(), &"b");
assert_eq!(slab.get(slot_c).unwrap(), &"c");
// Remove an element by its slot
slab.remove(slot_b).unwrap();
assert_eq!(slab.len(), 2);
// Pop elements from the back (FIFO behavior)
assert_eq!(slab.pop_back().unwrap(), "a");
assert_eq!(slab.pop_back().unwrap(), "c");
assert!(slab.is_empty());
Slabigator is ideal for scenarios where:
Common use cases include:
Slabigator comes with several feature flags to customize its behavior:
releasefast: Assumes that remove() will always be called with a valid index. This saves memory by removing validation checks, but must be used with extreme caution. Disabled by default.slot_u32: Uses u32 as the slot type (default)slot_u64: Uses u64 as the slot typeslot_usize: Uses usize as the slot typeAdd this to your Cargo.toml:
[dependencies]
slabigator = "0.9"
Slabigator implements several useful Rust traits:
Default: Creates a slab with a default capacity of 16FromIterator<T>: Creates a slab from any iteratorExtend<T>: Extends a slab with elements from an iteratorIndex<Slot> and IndexMut<Slot>: Allows direct indexing with [] syntaxIntoIterator for &Slab<T>: Enables iteration with for loops