Struct hashindexed::HashIndexed [] [src]

pub struct HashIndexed<T, K, E> { /* fields omitted */ }

Stores a set of values indexed in a user-defined way.

Use like this:

use hashindexed::{HashIndexed, KeyComparator};
 
#[derive(Debug, Eq, PartialEq)]
struct MyType { num: i32, name: &'static str }
 
struct MyComparator;
impl KeyComparator<MyType, i32> for MyComparator {
    fn extract_key(v: &MyType) -> &i32 { &v.num }
}
 
let mut container: HashIndexed<MyType, i32, MyComparator> =
    HashIndexed::new();
 
container.insert(MyType { num: 1, name: "one" });
container.insert(MyType { num: 2, name: "two" });
container.insert(MyType { num: 3, name: "three" });
 
assert_eq!( container.remove(&1).unwrap().name, "one" );
assert_eq!( container.remove(&1), None );
assert!( container.contains(&2) );
assert_eq!( container.len(), 2 );
 
assert_eq!( container.get(&3).unwrap().name, "three" );
container.replace(MyType { num: 3, name: "THREE" });
assert_eq!( container.get(&3).unwrap().name, "THREE" );

Methods

impl<T, K, E> HashIndexed<T, K, E> where
    E: KeyComparator<T, K>,
    K: Eq + Hash,
    IndexableValue<T, K, E>: Borrow<K>, 
[src]

Creates an empty HashIndexed collection.

Creates an empty HashIndexed with space for at least capacity elements in the hash table.

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

Reserves capacity for at least additional more elements to be inserted in the collection. More spaces than this may be allocated to avoid frequent reallocations.

Panics

Panics if the new allocation size overflows usize. ```

Shrinks the capacity of the collection as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy. ```

An iterator visiting all elements in arbitrary order.

Creates a consuming iterator, that is, one that moves each value out of the set in arbitrary order. The set cannot be used after calling this.

Returns the number of elements in the collection.

Returns true if the collection contains no elements.

Clears the collection, removing all values.

Returns true if the collection contains a value matching the given key.

Returns a reference to the value corresponding to the key.

Adds a value to the set. Returns true if the value was not already present in the collection.

Adds a value to the set, replacing the existing value, if any, that is equal to the given one. Returns the replaced value.

Removes and returns the value in the collection, if any, that is equal to the given one.

Trait Implementations

impl<T, K, E> PartialEq for HashIndexed<T, K, E> where
    HashSet<IndexableValue<T, K, E>>: PartialEq
[src]

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

This method tests for !=.

impl<T, K, E> Eq for HashIndexed<T, K, E> where
    HashIndexed<T, K, E>: PartialEq
[src]

impl<T, K, E> Debug for HashIndexed<T, K, E> where
    HashSet<IndexableValue<T, K, E>>: Debug
[src]

Formats the value using the given formatter.

impl<'a, T, K, E> IntoIterator for &'a HashIndexed<T, K, E> where
    K: Eq + Hash,
    E: KeyComparator<T, K>,
    IndexableValue<T, K, E>: Borrow<K>, 
[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, T, K, E> IntoIterator for HashIndexed<T, K, E> where
    K: Eq + Hash,
    E: KeyComparator<T, K>, 
[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