Slabigator
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.
Features
Slabigator was designed to do a few things extremely well:
- Add to the head of the list in O(1) time - Returns a stable slot number for future reference
- Pop from the tail of the list in O(1) time
- Delete any element given its slot number in O(1) time
- Fixed memory allocation - No dynamic allocations after initialization
It's designed to be:
- Fast: O(1) operations with minimal overhead
- Predictable: No memory allocations during operations
- Simple: Small, focused API for specific use cases
- Maintainable: Small codebase with zero dependencies
Usage
use Slab;
// Create a new slab with a capacity of 3 elements
let mut slab = with_capacity.unwrap;
// Add elements to the front - each operation returns a slot number
let slot_a = slab.push_front.unwrap;
let slot_b = slab.push_front.unwrap;
let slot_c = slab.push_front.unwrap;
// Slab is now full (capacity = 3)
assert!;
assert_eq!;
// Access elements directly by their slots
assert_eq!;
assert_eq!;
assert_eq!;
// Remove an element by its slot
slab.remove.unwrap;
assert_eq!;
// Pop elements from the back (FIFO behavior)
assert_eq!;
assert_eq!;
assert!;
When to Use Slabigator
Slabigator is ideal for scenarios where:
- You need to maintain a list with stable references to elements
- Memory allocation predictability is critical
- You need fast (O(1)) operations for all common list operations
- You know the maximum size of the list in advance
- You need a simple FIFO queue with the ability to remove arbitrary elements
Common use cases include:
- Real-time systems where allocation jitter is problematic
- Memory-constrained environments
- High-performance queues for task management
- Cache implementations with fixed capacity
- Game development for object pools
Cargo Features
Slabigator comes with several feature flags to customize its behavior:
releasefast: Assumes thatremove()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: Usesu32as the slot type (default)slot_u64: Usesu64as the slot typeslot_usize: Usesusizeas the slot type
Installation
Add this to your Cargo.toml:
[]
= "0.9"
Trait Implementations
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>andIndexMut<Slot>: Allows direct indexing with[]syntaxIntoIteratorfor&Slab<T>: Enables iteration withforloops