leaklist

Crates.ioleaklist
lib.rsleaklist
version0.2.4
sourcesrc
created_at2024-01-01 14:12:35.087375
updated_at2024-01-09 02:32:03.278318
descriptionA simple, concurrent, lock-free, singly-linked list
homepagehttps://github.com/Coder-256/leaklist
repositoryhttps://github.com/Coder-256/leaklist
max_upload_size
id1085344
size27,728
Jacob Greenfield (Coder-256)

documentation

README

leaklist

GitHub License docs.rs

A simple, concurrent, lock-free, singly-linked list. Only supports prepending items, and will leak an allocation for each new element.

This type of list can be useful for setting up a chain of objects that only need to be initialized once and will live for the duration of the program.

Example

let list: LeakList<u32> = LeakList::new();
let node1 = list.push_front(1);
let node2 = list.push_front(2);
println!("node1: {:?}", node1);
println!("node2: {:?}", node2);

std::thread::scope(|s| {
    s.spawn(|| {
        let node3 = list.push_front(3);
        println!("node3: {:?}", node3);
    });
    s.spawn(|| {
        let node4 = list.push_front(4);
        println!("node4: {:?}", node4);
    });
});

println!("list: {:?}", list.iter().copied().collect::<Vec<_>>());

Output may be:

node1: Node { val: 1, next: None }
node2: Node { val: 2, next: Some(Node { val: 1, next: None }) }
node3: Node { val: 3, next: Some(Node { val: 2, next: Some(Node { val: 1, next: None }) }) }
node4: Node { val: 4, next: Some(Node { val: 3, next: Some(Node { val: 2, next: Some(Node { val: 1, next: None }) }) }) }
list: [4, 3, 2, 1]

Or:

node1: Node { val: 1, next: None }
node2: Node { val: 2, next: Some(Node { val: 1, next: None }) }
node4: Node { val: 4, next: Some(Node { val: 2, next: Some(Node { val: 1, next: None }) }) }
node3: Node { val: 3, next: Some(Node { val: 4, next: Some(Node { val: 2, next: Some(Node { val: 1, next: None }) }) }) }
list: [3, 4, 2, 1]

License

This project is dual-licensed under the MIT and Apache-2.0 licenses.

Commit count: 0

cargo fmt