#linked-list #list #constant-time #removal #links #r4l

no-std linked_list_r4l

Linked lists that supports arbitrary removal in constant time

2 releases

0.2.1 Oct 29, 2024
0.2.0 Oct 22, 2024
0.1.0 Oct 22, 2024

#503 in Rust patterns

Download history 243/week @ 2024-10-23 71/week @ 2024-10-30 23/week @ 2024-11-06 16/week @ 2024-11-13 46/week @ 2024-11-20 11/week @ 2024-11-27 19/week @ 2024-12-04 27/week @ 2024-12-11 6/week @ 2024-12-18 23/week @ 2024-12-25 10/week @ 2025-01-08 12/week @ 2025-01-22 15/week @ 2025-01-29 27/week @ 2025-02-05

55 downloads per month

GPL-2.0-or-later

38KB
729 lines

LinkedList

Crates.io Doc.rs CI

Linked lists that supports arbitrary removal in constant time.

It is based on the linked list implementation in Rust-for-Linux.

Examples

use linked_list_r4l::{GetLinks, Links, List};

type InnerType = usize;

pub struct ExampleNode {
    pub inner: InnerType,
    links: Links<Self>,
}

impl GetLinks for ExampleNode {
    type EntryType = Self;

    fn get_links(t: &Self) -> &Links<Self> {
        &t.links
    }
}

impl ExampleNode {
    fn new(inner: InnerType) -> Self {
        Self {
            inner,
            links: Links::new()
        }
    }

    fn inner(&self) -> &InnerType {
        &self.inner
    }
}

let node1 = Box::new(ExampleNode::new(0));
let node2 = Box::new(ExampleNode::new(1));
let mut list =  List::<Box<ExampleNode>>::new();

list.push_back(node1);
list.push_back(node2);

// Support Iter
for (i,e) in list.iter().enumerate() {
    assert!(*e.inner() == i);
}

// Pop drop
assert!(*list.pop_front().unwrap().inner() == 0);
assert!(*list.pop_front().unwrap().inner() == 1);

No runtime deps