[−][src]Struct ahtable::ArrayHash
An implementation of ArrayHash in pure Rust.
ArrayHash is a data structure where the index is determined by hash and
each entry in array is a Vec
that store data and all it collision.
Oritinal paper can be found [here](Askitis, N. & Zobel, J. (2005), Cache-conscious collision resolution for string hash tables, in ‘Proc. SPIRE String Processing and Information Retrieval Symp.’, Springer-Verlag, pp. 92–104)
In this implementation, user can supplied their own choice of hasher but it need to implement Clone
.
The data can be anything that implement Hash
and Clone
. This is due to nature of
Vec
that the first allocation need to be cloneable. Otherwise, it cann't be pre-allocate.
The default Hasher
, if not provided, will be XxHash64
.
Implementations
impl<H, K, V> ArrayHash<H, K, V> where
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
[src]
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
pub fn put(&mut self, key: K, value: V) -> Option<(K, V)>
[src]
Add or replace entry into this HashMap
.
If entry is replaced, it will be return in Option
.
Otherwise, it return None
Parameter
entry
- A tuple to be add to this.
Return
Option that contains tuple of (key, value) that got replaced or None
if it is
new entry
pub fn try_put(&mut self, key: K, value: V) -> Option<&V>
[src]
Try to put value into this ArrayHash
.
If the given key is already in used, leave old entry as is and return current value associated with the key.
Otherwise, add entry to this ArrayHash
and return None.
Parameter
entry
- A tuple of (key, value) to be add to this.
Return
It return reference to existing value associated with given key, otherwise, it put the value
into this ArrayHash
and return None.
pub fn get(&self, key: &K) -> Option<&V>
[src]
Get a value of given key from this ArrayHash
Parameter
key
- A key to look for. It can be anything that can be deref into K
Return
An Option
contains a value or None
if it is not found.
pub fn smart_get<T: ?Sized, Q>(&self, key: Q) -> Option<&V> where
Q: Deref<Target = T>,
K: Deref<Target = T>,
T: Hash + PartialEq,
[src]
Q: Deref<Target = T>,
K: Deref<Target = T>,
T: Hash + PartialEq,
Get a value using deref type.
This is usable only if the key is a type of smart pointer that can be deref into another type
which implement Hash
and PartialEq
.
For example, if K is Box<[u8]>
, you can use &[u8]
to query for a value
Parameter
key
- Any type that implement Deref
where type after Deref
is that same type
as actual type of key
beneath type K
.
Return
Some(&V)
if key exist in this table. Otherwise None.
pub fn remove(&mut self, key: &K) -> Option<(K, V)>
[src]
Attempt to remove entry with given key from this ArrayHash
.
Parameter
key
- A key of entry to be remove. It can be anything that can deref intoK
Return
Option that contain tuple of (key, value) or None
of key is not found
pub fn len(&self) -> usize
[src]
Current number of entry in this ArrayHash
pub fn iter(&self) -> ArrayHashIterator<K, V>
[src]
Get an iterator over this ArrayHash
.
Return
ArrayHashIterator that return reference
to each entry in this ArrayHash
pub fn iter_mut(&mut self) -> ArrayHashIterMut<K, V>
[src]
Get a mutable iterator over this ArrayHash
.
Warning, you shall not modify the key part of entry. If you do, it might end up accessible only by iterator but not with get.
Return
ArrayHashIterMut that return mutably reference
to each entry in this ArrayHash
pub fn drain(&mut self) -> DrainIter<K, V>
[src]
Return an iterator that drain all entry out of this ArrayHash.
After the iterator is done, this ArrayHash will become empty.
This method will immediately set size to 0.
Return
DrainIter - An iterator that will drain all element out of this ArrayHash.
pub fn drain_with<F>(&mut self, pred: F) -> DrainWithIter<F, K, V> where
F: Fn(&(K, V)) -> bool,
[src]
F: Fn(&(K, V)) -> bool,
Return an iterator that drain some entry out of this ArrayHash.
After the iterator is done, this ArrayHash size will be shrink.
This method will return an iterator where each element it drain will cause a size deduction on this ArrayHash.
Return
DrainWithIter - An iterator that will drain all element out of this ArrayHash.
pub fn split_by<F>(&mut self, pred: F) -> ArrayHash<H, K, V> where
F: Fn(&(K, V)) -> bool,
[src]
F: Fn(&(K, V)) -> bool,
Split this ArrayHash by given predicate closure. Every element that closure evaluate to true will be remove from this ArrayHash and return in new instance of ArrayHash.
This is different from using drain_with to drain some element into another ArrayHash by this method will return ArrayHash with exactly identical property, i.e. Hasher, buckets_size, and max_load_factor, whereas drain_with let caller instantiate ArrayHash yourself.
Since the instant it returns, use the same Hasher. It is safe to assume that all elements shall reside in the same bucket number thus this method speed up the split by ignore hashing altogether and store the entry directly into the same bucket number as in this ArrayHash
Parameter
pred
- A closure that evaluate an entry. If it return true, the entry shall be moved into a new
ArrayHash.
Return
An ArrayHash that contains all entry that pred
evaluate to true.
Trait Implementations
impl<H: Clone, K: Clone, V: Clone> Clone for ArrayHash<H, K, V> where
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
[src]
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
impl<H: Debug, K: Debug, V: Debug> Debug for ArrayHash<H, K, V> where
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
[src]
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
impl<H, K, V> IntoIterator for ArrayHash<H, K, V> where
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
[src]
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
type Item = (K, V)
The type of the elements being iterated over.
type IntoIter = ArrayHashIntoIter<K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, H, K, V> IntoIterator for &'a ArrayHash<H, K, V> where
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
[src]
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
type Item = &'a (K, V)
The type of the elements being iterated over.
type IntoIter = ArrayHashIterator<'a, K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, H, K, V> IntoIterator for &'a mut ArrayHash<H, K, V> where
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
[src]
H: Hasher + Clone,
K: Hash + PartialEq + Clone,
V: Clone,
Auto Trait Implementations
impl<H, K, V> RefUnwindSafe for ArrayHash<H, K, V> where
H: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
H: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<H, K, V> Send for ArrayHash<H, K, V> where
H: Send,
K: Send,
V: Send,
H: Send,
K: Send,
V: Send,
impl<H, K, V> Sync for ArrayHash<H, K, V> where
H: Sync,
K: Sync,
V: Sync,
H: Sync,
K: Sync,
V: Sync,
impl<H, K, V> Unpin for ArrayHash<H, K, V> where
H: Unpin,
H: Unpin,
impl<H, K, V> UnwindSafe for ArrayHash<H, K, V> where
H: UnwindSafe,
K: UnwindSafe,
V: UnwindSafe,
H: UnwindSafe,
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,