Struct stdlib_rs::collections::min_stack::MinStack[][src]

pub struct MinStack<T: Ord>(_);
Expand description

A Stack data type that supports accessing the minimum item in the stack in O(1) time.

Implementations

Moves all the elements of other into Self, leaving other empty.

Panics

Panics if the number of elements in the MinStack overflows a usize.

Examples
let mut left = min_stack![1];
let mut right = min_stack![2];
left.append(&mut right);
assert_eq!(left, min_stack![1, 2]);

Finds the minimum item of the stack in O(1) time. If the stack is empty, returns None.

Examples
let stack = min_stack![1, 2];
let empty: MinStack<i32> = min_stack![];
assert_eq!(stack.min(), Some(1));
assert_eq!(empty.min(), None);

Look at the top item of the stack in O(1) time. If the stack is empty, returns None.

Examples
let stack = min_stack![1, 2];
let empty: MinStack<i32> = min_stack![];
assert_eq!(stack.peek(), Some(2));
assert_eq!(empty.peek(), None);

Adds an item to the end of the stack in O(1) time.

Examples
let mut stack = min_stack![1];
stack.push(2);
assert_eq!(stack.len(), 2);

Creates a min_stack from a vector.

Examples
let v = vec![1, 2, 3];
let stack: MinStack<i32> = MinStack::from(v);
assert_eq!(stack, min_stack![1, 2, 3]);

Creates a new MinStack.

Extracts a slice containing the Min Stack. Equivalent to &s[..].

Returns a raw pointer to the min_stack.

Returns a mutable pointer to the min_stack.

Clears the MinStack, removing all values.

Examples
let mut stack = min_stack![1,2,3];
stack.clear();
assert_eq!(stack, min_stack![]);

Creates a new MinStack with the given capacity.

Examples
let stack: MinStack<i32> = MinStack::with_capacity(10);
assert!(stack.capacity() >= 10);

Reserves capacity for at least additional more elements to be inserted in the given MinStack<T>. The collection may reserve more space to avoid frequent reallocations. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

Examples
let mut stack = min_stack![1];
stack.reserve(10);
assert!(stack.capacity() >= 11);

Returns the number of elements the vector can hold without reallocating.

Examples
let stack: MinStack<i32> = MinStack::with_capacity(10);
assert!(stack.capacity() >= 10);

Removes the last element from a vector and returns it, or None if it is empty.

Examples
let mut stack = min_stack![1, 2, 3];
let mut empty: MinStack<i32> = min_stack![];
assert_eq!(stack.pop(), Some(3));
assert_eq!(empty.pop(), None);

Returns true if the MinStack has no elements.

Examples
let stack = min_stack![1, 2, 3];
let empty: MinStack<i32> = min_stack![];
assert_eq!(stack.is_empty(), false);
assert_eq!(empty.is_empty(), true);

Returns the number of elements in the stack.

Examples
let stack = min_stack![1, 2, 3];
assert_eq!(stack.len(), 3);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.