array-linked-list 0.2.1

A data structure, which combines the advantages of dynamic arrays and linked lists
Documentation
  • Coverage
  • 100%
    36 out of 36 items documented10 out of 36 items with examples
  • Size
  • Source code size: 42.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.86 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • porky11/array-linked-list
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • porky11

ArrayLinkedList

Crates.io Docs.rs CI

A hybrid data structure combining the benefits of arrays and linked lists, with O(1) indexed access, insertions, and deletions.

Features

  • O(1) Operations: Insert/remove at ends, access by index, and replace elements
  • Stable Indices: Indices remain valid after insertions/deletions
  • Cache-Friendly: Contiguous memory layout for better performance
  • Space Efficient: Reuses empty slots automatically
  • Iterators: Bidirectional iteration with rev(), and partial iteration via iter_after()/iter_before()

Comparison

Operation ArrayLinkedList Vec LinkedList Vec<Option<T>>
Push/Pop Front O(1) O(n)* O(1) O(1)†
Push/Pop Back O(1) O(1) O(1) O(1)
Remove by Index O(1) O(n)* O(n) O(1)†
Cache Locality
Stable Indices

*Amortized | †Requires slot reuse logic

Example

use array_linked_list::ArrayLinkedList;

let mut list = ArrayLinkedList::new();

// Add elements
let idx1 = list.push_front(10); // Index 0
let idx2 = list.push_back(20); // Index 1
let idx3 = list.push_front(30); // Index 2

// Access by index
assert_eq!(list[idx1], Some(10));
assert_eq!(list[idx2], Some(20));
assert_eq!(list[idx3], Some(30));

// Iterate in logical order
let items: Vec<_> = list.iter().copied().collect();
assert_eq!(items, [30, 10, 20]);

// Replace elements while maintaining indices and moving the new element to the logical front
list.replace_front(idx2, 99).unwrap();
assert_eq!(list.iter().copied().collect::<Vec<_>>(), [99, 30, 10]);

// Iterate with indices
for (idx, val) in list.indexed() {
    println!("Index {idx}: {val}");
}

// Partial iteration
let after_30: Vec<_> = list.iter_before(idx1).copied().collect();
assert_eq!(after_30, vec![99, 30]);