bugadani / listor

Doubly linked list in contiguous memory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Listor

Listor is both a list and a vector at the same time. It is a linked list implemented in contiguous memory, with constant-time1 operations. Listor is internally implemented with a slab allocator.

Unlike slab or stable_vec, Listor implements a doubly-linked list.

Examples

Unbounded listor

use listor::Listor;

// Create a new listor with unbounded capacity.
let mut listor = Listor::new();

listor.push_back(1).unwrap();
listor.push_back(2).unwrap();
listor.push_back(3).unwrap();

assert_eq!(3, listor.len());

Unbounded listor with initial capacity

use listor::Listor;

// Create a new listor with unbounded capacity with an initial capacity for 2 elements.
let mut listor = Listor::with_capacity(2);

listor.push_back(1).unwrap();
listor.push_back(2).unwrap();

// Pushing an element after the listor is full grows the listor.
listor.push_back(3).unwrap();

assert_eq!(3, listor.len());

Bounded listor

use listor::Listor;

// Create a new listor with capacity for 2 elements.
let mut listor = Listor::bounded(2);

listor.push_back(1).unwrap();
listor.push_back(2).unwrap();

// Pushing an element after the listor is full fails.
assert!(listor.push_back(3).is_none());

assert_eq!(2, listor.len());

Footnotes

  1. as long as the data structure does not have to reallocate.

About

Doubly linked list in contiguous memory


Languages

Language:Rust 100.0%