fffl

Crates.iofffl
lib.rsfffl
version1.2.0
created_at2025-05-22 19:17:35.276528+00
updated_at2025-06-13 14:49:42.045197+00
descriptionA contiguous First-fit Freelist
homepage
repositoryhttps://github.com/stkterry/freelist
max_upload_size
id1685537
size68,422
stkterry (stkterry)

documentation

https://docs.rs/fffl

README

Coverage Status Miri

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:

[dependencies]
fffl = "1.2.0"

Examples

use fffl::Freelist;

let mut fl = Freelist::new();
let idx1 = fl.push(1);
let idx2 = fl.push(2);
let idx3 = fl.push(3);

assert_eq!(idx2, 1);

assert_eq!(fl.filled(), 3);
assert_eq!(fl[0], 1);

assert_eq!(fl.remove(1), Some(2));
assert_eq!(fl.remove(1), None);

assert_eq!(fl.filled(), 2);
assert_eq!(fl.free(), 1);
assert_eq!(fl.size(), 3);

let first_free_idx = fl.push(7);
assert_eq!(first_free_idx, 1);

fl[1] = 5;
assert_eq!(fl[1], 5);

Checkout the docs for more comprehensive examples.

Indexing

The Freelist type allows access to values by index.

use fffl::Freelist;

let fl = Freelist::from([1, 3, 5, 7]);
println!("{}", fl[1]); // 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 fffl::Freelist;

let mut fl = Freelist::from([1, 3, 5, 7]);
fl.remove(2);
println!("{}", fl[2]); // 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

Commit count: 24

cargo fmt