Struct HashIndexedVector

Source
pub struct HashIndexedVector<K, V> { /* private fields */ }
Expand description

A simple implementation of IndexedVector using HashMap.

Implementations§

Source§

impl<K: Eq + Hash, V> HashIndexedVector<K, V>

Source

pub fn new<F: Fn(&V) -> K + 'static, C: IntoIterator<Item = V>>( data: C, key_func: F, ) -> Self

Create a new HashIndexedVector from a vector of items. The key_func is used to extract the key from an item.

Examples found in repository?
examples/user.rs (line 26)
10fn main() {
11    let users = vec![
12        User {
13            name: "Tom".to_owned(),
14            age: 20,
15        },
16        User {
17            name: "Jane".to_owned(),
18            age: 20,
19        },
20        User {
21            name: "Ivan".to_owned(),
22            age: 30,
23        },
24    ];
25
26    let hash_vec = HashIndexedVector::new(users.clone(), |user: &User| user.age);
27    // Tom and Jane
28    dbg!(hash_vec.search(&20).collect::<Vec<_>>());
29    // Ivan
30    dbg!(hash_vec.search(&30).collect::<Vec<_>>());
31
32    let btree_vec = BTreeIndexedVector::new(users, |user: &User| user.age);
33    // Tom, Jane and Ivan
34    dbg!(btree_vec.search_range(10..40).collect::<Vec<_>>());
35}

Trait Implementations§

Source§

impl<K: Eq + Hash, V> IndexedVector<K, V> for HashIndexedVector<K, V>

Source§

fn search(&self, key: &K) -> Iter<'_, V>

Search for items with the given key.
Source§

fn insert(&mut self, item: V)

Insert an item into the vector.

Auto Trait Implementations§

§

impl<K, V> Freeze for HashIndexedVector<K, V>

§

impl<K, V> !RefUnwindSafe for HashIndexedVector<K, V>

§

impl<K, V> !Send for HashIndexedVector<K, V>

§

impl<K, V> !Sync for HashIndexedVector<K, V>

§

impl<K, V> Unpin for HashIndexedVector<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> !UnwindSafe for HashIndexedVector<K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.