persistent_stack

Crates.iopersistent_stack
lib.rspersistent_stack
version0.1.1
sourcesrc
created_at2021-01-26 10:36:34.744142
updated_at2021-01-27 14:33:57.429545
descriptionConcurrent persistent stack
homepage
repositoryhttps://github.com/timcryt/persistent_stack
max_upload_size
id346824
size8,156
(timcryt)

documentation

README

Concurrent persistent stack

Fast, concurrent and easy to use implementation of persistent stack.

Operations cost

  • push - O(1)
  • pop - O(1)
  • clone - O(1)
  • iter next - O(1)

Example

use persistent_stack::PersistentStack;

let mut s1 = PersistentStack::new();
s1.push(1);

let mut s2 = s1.clone(); // O(1) operation

std::thread::spawn(move || {
    s2.push(2); // PersistentStack values can be shared safely
    assert_eq!(s2.iter().copied().collect::<Vec<_>>(), vec![2, 1]);

    std::thread::sleep(std::time::Duration::from_millis(20));

    s2.push(4);
    assert_eq!(s2.iter().copied().collect::<Vec<_>>(), vec![4, 2, 1]);

    assert_eq!(s2.pop(), Ok(4)); // We can also pop values from stack
});

s1.push(3);
assert_eq!(s1.iter().copied().collect::<Vec<_>>(), vec![3, 1]);

std::thread::sleep(std::time::Duration::from_millis(20));

s1.push(5);
assert_eq!(s1.iter().copied().collect::<Vec<_>>(), vec![5, 3, 1]);
Commit count: 13

cargo fmt