pub struct Stack<T> { /* private fields */ }Expand description
A concurrent and lock-free stack using Treiber’s algorithm.
The Treiber Stack is a simple concurrent data structure that uses the fine-grained “compare-and-swap” concurrency primitive.
§Examples
use extended_collections::sync::Stack;
let mut s = Stack::new();
s.push(0);
s.push(1);
assert_eq!(s.len(), 2);
assert_eq!(s.try_pop(), Some(1));
assert_eq!(s.try_pop(), Some(0));
assert_eq!(s.len(), 0);Implementations§
Source§impl<T> Stack<T>
impl<T> Stack<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new, empty Stack<T>.
§Examples
use extended_collections::sync::Stack;
let s: Stack<u32> = Stack::new();Sourcepub fn push(&self, value: T)
pub fn push(&self, value: T)
Pushes an item onto the stack.
§Examples
use extended_collections::sync::Stack;
let mut s = Stack::new();
s.push(0);Sourcepub fn try_pop(&self) -> Option<T>
pub fn try_pop(&self) -> Option<T>
Attempts to pop the top element of the stack. Returns None if it was unable to pop the
top element.
§Examples
use extended_collections::sync::Stack;
let mut s = Stack::new();
s.push(0);
assert_eq!(s.try_pop(), Some(0));
assert_eq!(s.try_pop(), None);Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Stack<T>
impl<T> RefUnwindSafe for Stack<T>where
T: RefUnwindSafe,
impl<T> Send for Stack<T>
impl<T> Sync for Stack<T>
impl<T> Unpin for Stack<T>
impl<T> UnsafeUnpin for Stack<T>
impl<T> UnwindSafe for Stack<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more