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]

Constructs a new, empty Stack<T>.

Examples

use extended_collections::sync::Stack;

let s: Stack<u32> = Stack::new();

Pushes an item onto the stack.

Examples

use extended_collections::sync::Stack;

let mut s = Stack::new();
s.push(0);

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

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

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

Trait Implementations

impl<T> Default for Stack<T>
[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl<T> Send for Stack<T> where
    T: Send + Sync

impl<T> Sync for Stack<T> where
    T: Send + Sync