Freelist
A contiguous, growable, first-fit freelist.
Freelist has O(1) indexing and push (to the first available free slot) and O(1) removal.
Installation
Add the following to your Cargo.toml file:
fffl = "1.2.0"
Examples
use Freelist;
let mut fl = new;
let idx1 = fl.push;
let idx2 = fl.push;
let idx3 = fl.push;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let first_free_idx = fl.push;
assert_eq!;
fl = 5;
assert_eq!;
Checkout the docs for more comprehensive examples.
Indexing
The Freelist type allows access to values by index.
use Freelist;
let fl = from;
println!; // displays '3'
Note: if you try to access an index which has been previously freed or isn't in the Freelist, the software will panic! Example:
use Freelist;
let mut fl = from;
fl.remove;
println!; // PANIC
Use get and get_mut if you want to check whether the index contains a value.
Slicing
Freelist cannot be sliced. Doing so would require internally building a slice that skips freed slots, meaning the returned slice may not be of the same length. Moreover the apparent indices would be unordered.
You may iterate over the entire Freelist via iter, iter_mut, or into_iter, all of which will skip over empty slots.
Guarantees
push and remove are always O(1), maintain index order, and offer similar performance to Vec