Struct extended_collections::sync::Stack [−][src]
pub struct Stack<T> { /* fields omitted */ }
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);
Methods
impl<T> Stack<T>
[src]
impl<T> Stack<T>
pub fn new() -> Self
[src]
pub fn new() -> Self
Constructs a new, empty Stack<T>
.
Examples
use extended_collections::sync::Stack; let s: Stack<u32> = Stack::new();
pub fn push(&self, value: T)
[src]
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);
pub fn try_pop(&self) -> Option<T>
[src]
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);
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the approximate number of elements in the stack.
Examples
use extended_collections::sync::Stack; let mut s = Stack::new(); assert_eq!(s.len(), 0); s.push(0); assert_eq!(s.len(), 1);
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Returns true
if the approximate number of elements in the stack is zero.
Examples
use extended_collections::sync::Stack; let mut s = Stack::new(); assert!(s.is_empty()); s.push(0); assert!(!s.is_empty());