pub trait LruMap<Key, Value>: IntoIterator<Item = (Key, Value), IntoIter = IntoIter<Key, Value>> + EntryCache<Key, Value> + Sized {
fn new(capacity: usize) -> Self;
fn len(&self) -> usize;
fn head(&mut self) -> Option<EntryRef<'_, Self, Key, Value>>;
fn tail(&mut self) -> Option<EntryRef<'_, Self, Key, Value>>;
fn iter(&self) -> Iter<'_, Key, Value>ⓘNotable traits for Iter<'a, Key, Value>impl<'a, Key, Value> Iterator for Iter<'a, Key, Value> type Item = (&'a Key, &'a Value);
;
fn get<QueryKey>(&mut self, key: &QueryKey) -> Option<&Value>
where
QueryKey: Ord + Hash + Eq + ?Sized,
Key: Borrow<QueryKey> + Ord + Hash + Eq;
fn get_without_update<QueryKey>(&self, key: &QueryKey) -> Option<&Value>
where
QueryKey: Ord + Hash + Eq + ?Sized,
Key: Borrow<QueryKey> + Ord + Hash + Eq;
fn entry<QueryKey>(
&mut self,
key: &QueryKey
) -> Option<EntryRef<'_, Self, Key, Value>>
where
QueryKey: Ord + Hash + Eq + ?Sized,
Key: Borrow<QueryKey> + Ord + Hash + Eq;
fn push(&mut self, key: Key, value: Value) -> Option<Removed<Key, Value>>;
fn extend<IntoIter: IntoIterator<Item = (Key, Value)>>(
&mut self,
iterator: IntoIter
);
fn is_empty(&self) -> bool { ... }
}
Expand description
A Least Recently Used map interface that supports all map implementations exposed by this crate.
Required Methods
sourcefn head(&mut self) -> Option<EntryRef<'_, Self, Key, Value>>
fn head(&mut self) -> Option<EntryRef<'_, Self, Key, Value>>
Returns a reference to the most recently used key.
sourcefn tail(&mut self) -> Option<EntryRef<'_, Self, Key, Value>>
fn tail(&mut self) -> Option<EntryRef<'_, Self, Key, Value>>
Returns a reference to the least recently used key.
sourcefn iter(&self) -> Iter<'_, Key, Value>ⓘNotable traits for Iter<'a, Key, Value>impl<'a, Key, Value> Iterator for Iter<'a, Key, Value> type Item = (&'a Key, &'a Value);
fn iter(&self) -> Iter<'_, Key, Value>ⓘNotable traits for Iter<'a, Key, Value>impl<'a, Key, Value> Iterator for Iter<'a, Key, Value> type Item = (&'a Key, &'a Value);
Returns an iterator over the keys and values in order from most recently touched to least recently touched.
sourcefn get<QueryKey>(&mut self, key: &QueryKey) -> Option<&Value>where
QueryKey: Ord + Hash + Eq + ?Sized,
Key: Borrow<QueryKey> + Ord + Hash + Eq,
fn get<QueryKey>(&mut self, key: &QueryKey) -> Option<&Value>where
QueryKey: Ord + Hash + Eq + ?Sized,
Key: Borrow<QueryKey> + Ord + Hash + Eq,
Returns the stored value for key
, if present.
This function touches the key, making it the most recently used key.
sourcefn get_without_update<QueryKey>(&self, key: &QueryKey) -> Option<&Value>where
QueryKey: Ord + Hash + Eq + ?Sized,
Key: Borrow<QueryKey> + Ord + Hash + Eq,
fn get_without_update<QueryKey>(&self, key: &QueryKey) -> Option<&Value>where
QueryKey: Ord + Hash + Eq + ?Sized,
Key: Borrow<QueryKey> + Ord + Hash + Eq,
Returns the stored value for key
, if present.
This function does not touch the key, preserving its current position in the lru cache.
sourcefn entry<QueryKey>(
&mut self,
key: &QueryKey
) -> Option<EntryRef<'_, Self, Key, Value>>where
QueryKey: Ord + Hash + Eq + ?Sized,
Key: Borrow<QueryKey> + Ord + Hash + Eq,
fn entry<QueryKey>(
&mut self,
key: &QueryKey
) -> Option<EntryRef<'_, Self, Key, Value>>where
QueryKey: Ord + Hash + Eq + ?Sized,
Key: Borrow<QueryKey> + Ord + Hash + Eq,
sourcefn push(&mut self, key: Key, value: Value) -> Option<Removed<Key, Value>>
fn push(&mut self, key: Key, value: Value) -> Option<Removed<Key, Value>>
Inserts value
for key
into this map. If a value is already stored
for this key, Removed::PreviousValue
is returned with the previously
stored value. If no value is currently stored and the map is full, the
least recently used entry will be returned in Removed::Evicted
.
Otherwise, None
will be returned.
This function touches the key, making it the most recently used key.
sourcefn extend<IntoIter: IntoIterator<Item = (Key, Value)>>(
&mut self,
iterator: IntoIter
)
fn extend<IntoIter: IntoIterator<Item = (Key, Value)>>(
&mut self,
iterator: IntoIter
)
Pushes all items from iterator
into this map. If there are more
entries in the iterator than capacity remaining, keys will be evicted as
needed.
This function is equivalent to a for loop calling Self::push()
.