linked_list_r4l

Crates.iolinked_list_r4l
lib.rslinked_list_r4l
version0.2.1
sourcesrc
created_at2024-10-22 03:26:41.250856
updated_at2024-10-29 01:57:14.436828
descriptionLinked lists that supports arbitrary removal in constant time
homepagehttps://github.com/arceos-org/arceos
repositoryhttps://github.com/arceos-org/linked_list_r4l
max_upload_size
id1418201
size39,236
core (github:arceos-org:core)

documentation

https://docs.rs/linked_list_r4l

README

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);

Commit count: 5

cargo fmt