Struct stash::unique_stash::UniqueStash [] [src]

pub struct UniqueStash<V> { /* fields omitted */ }

An O(1) amortized table that does not reuse keys.

Guarantee: No two calls to put on the same UniqueStash will ever return the same Key.

An example use case is a file descriptor table.

An example use case is a session table where expired session IDs should never be re-used.

Methods

impl<V> UniqueStash<V>
[src]

Constructs a new, empty UniqueStash<T>.

The stash will not allocate until elements are put onto it.

Examples

use stash::UniqueStash;

let mut stash: UniqueStash<i32> = UniqueStash::new();

Constructs a new, empty UniqueStash<T> with the specified capacity.

The stash will be able to hold exactly capacity elements without reallocating. If capacity is 0, the stash will not allocate.

It is important to note that this function does not specify the length of the returned stash , but only the capacity. (For an explanation of the difference between length and capacity, see the main Vec<T> docs in the std::vec module, 'Capacity and reallocation'.)

Examples

use stash::UniqueStash;

let mut stash: UniqueStash<i32> = UniqueStash::with_capacity(10);

// The stash contains no items, even though it has capacity for more
assert_eq!(stash.len(), 0);

// These are all done without reallocating...
for i in 0i32..10 {
    let _ = stash.put(i);
}

// ...but this may make the stash reallocate
stash.put(11);

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

Examples

use stash::UniqueStash;

let stash: UniqueStash<i32> = UniqueStash::with_capacity(10);
assert_eq!(stash.capacity(), 10);

The number of items in the stash.

Examples

use stash::UniqueStash;

let mut stash = UniqueStash::new();
assert_eq!(stash.len(), 0);
stash.put("a");
assert_eq!(stash.len(), 1);

Reserves capacity for at least additional more elements to be put into the given UniqueStash<T>. The collection may reserve more space to avoid frequent reallocations.

Panics

Panics if the new capacity overflows usize.

Examples

use stash::UniqueStash;

let mut stash: UniqueStash<i32> = UniqueStash::new();
let t1 = stash.put(1);
stash.reserve(10);
assert!(stash.capacity() >= 11);

Reserves the minimum capacity for exactly additional more elements to be put into the given UniqueStash<T>. Does nothing if the capacity is already sufficient.

Note that the allocator may give the collection more space than it requests. Therefore capacity can not be relied upon to be precisely minimal. Prefer reserve if future puts are expected.

Panics

Panics if the new capacity overflows usize.

Examples

use stash::UniqueStash;

let mut stash: UniqueStash<i32> = UniqueStash::new();
let t1 = stash.put(1);
stash.reserve_exact(10);
assert!(stash.capacity() >= 11);

Put a value into the stash.

Returns the index at which this value was stored.

Put all items in the iterator into the stash.

Returns an iterator over the indices where the items were inserted. The items are actually inserted as the Iterator is read. If the returned Iterator is dropped, the rest of the items will be inserted all at once.

Iterate over the items in this UniqueStash<V>.

Returns an iterator that yields (index, &value) pairs.

Mutably iterate over the items in this UniqueStash<V>.

Returns an iterator that yields (index, &mut value) pairs.

Iterate over the values in this UniqueStash<V> by reference.

Mutably iterate over the values in this UniqueStash<V> by reference.

Iterate over the values in this UniqueStash<V> by value.

Check if this UniqueStash<V> is empty.

Returns true if this UniqueStash<V> is empty.

Take an item from a slot (if non empty).

Get a reference to the value at index.

Get a mutable reference to the value at index.

Clear the UniqueStash.

Note: This will not cause Tags to be reused.

Trait Implementations

impl<V: Clone> Clone for UniqueStash<V>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<V> IntoIterator for UniqueStash<V>
[src]

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

impl<'a, V> IntoIterator for &'a UniqueStash<V>
[src]

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

impl<'a, V> IntoIterator for &'a mut UniqueStash<V>
[src]

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

impl<V> Debug for UniqueStash<V> where V: Debug
[src]

Formats the value using the given formatter.

impl<'a, V> Index<Tag> for UniqueStash<V>
[src]

The returned type after indexing

The method for the indexing (container[index]) operation

impl<'a, V> IndexMut<Tag> for UniqueStash<V>
[src]

The method for the mutable indexing (container[index]) operation

impl<V> Default for UniqueStash<V>
[src]

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