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]
E: KeyComparator<T, K>,
K: Eq + Hash,
IndexableValue<T, K, E>: Borrow<K>,
fn new() -> HashIndexed<T, K, E>
Creates an empty HashIndexed collection.
fn with_capacity(capacity: usize) -> HashIndexed<T, K, E>
Creates an empty HashIndexed with space for at least capacity
elements in the hash table.
fn capacity(&self) -> usize
Returns the number of elements the collection can hold without reallocating.
fn reserve(&mut self, additional: usize)
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
.
```
fn shrink_to_fit(&mut self)
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. ```
fn iter(&self) -> Iter<T, K, E>
An iterator visiting all elements in arbitrary order.
fn into_iter(self) -> IntoIter<T, K, E>
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.
fn len(&self) -> usize
Returns the number of elements in the collection.
fn is_empty(&self) -> bool
Returns true if the collection contains no elements.
fn clear(&mut self)
Clears the collection, removing all values.
fn contains(&self, k: &K) -> bool
Returns true
if the collection contains a value matching the given
key.
fn get(&self, k: &K) -> Option<&T>
Returns a reference to the value corresponding to the key.
fn insert(&mut self, value: T) -> bool
Adds a value to the set. Returns true if the value was not already present in the collection.
fn replace(&mut self, value: T) -> Option<T>
Adds a value to the set, replacing the existing value, if any, that is equal to the given one. Returns the replaced value.
fn remove(&mut self, k: &K) -> Option<T>
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]
HashSet<IndexableValue<T, K, E>>: PartialEq,
fn eq(&self, other: &HashIndexed<T, K, E>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<T, K, E> Eq for HashIndexed<T, K, E> where
HashIndexed<T, K, E>: PartialEq,
[src]
HashIndexed<T, K, E>: PartialEq,
impl<T, K, E> Debug for HashIndexed<T, K, E> where
HashSet<IndexableValue<T, K, E>>: Debug,
[src]
HashSet<IndexableValue<T, K, E>>: Debug,
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]
K: Eq + Hash,
E: KeyComparator<T, K>,
IndexableValue<T, K, E>: Borrow<K>,
type Item = &'a T
The type of the elements being iterated over.
type IntoIter = Iter<'a, T, K, E>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Iter<'a, T, K, E>
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]
K: Eq + Hash,
E: KeyComparator<T, K>,