Struct schnellru::LruMap

source ·
pub struct LruMap<K, V, L = ByLength, S = RandomState>where
    L: Limiter<K, V>,
{ /* private fields */ }
Expand description

An LRU hash map.

Implementations§

Creates a new empty map with a given limiter.

Creates a new empty map with a given limiter and a non-randomized hasher.

Creates a new empty map with a given memory_budget and hasher.

This will configure the limiter so that the map can use at most memory_budget bytes of memory.

This does not preallocate any memory.

Creates a new empty map with a given memory_budget.

This will configure the limiter so that the map can use at most memory_budget bytes of memory.

This does not preallocate any memory.

Creates a new map with a given limiter and hasher.

Ensures that at least additional items can be inserted into the table without reallocation.

Panics

Will panic if the total number of elements is too big or the memory couldn’t be allocated.

Returns the current guaranteed capacity of the map.

This specifies how many elements the map is guaranteed to be able to hold without allocating any memory. This is a lower bound; it’s possible that the map can hold more elements than this.

This value will change as elements are added and removed. In particular, in might go down when an element is removed from the map.

This is independent of the cap imposed by the limiter.

Returns an estimated memory usage this map will have with a given memory_budget.

Returns the current memory usage of the map, in bytes.

Returns the number of elements in the map.

Returns whether the map is empty or not.

Returns a reference to the value for a given key and promotes that element to be the most recently used.

Returns a reference to the value for a given hash and for which is_eq returns true. Promotes that element to be the most recently used.

Tries to get the value for a given key or insert a new value if there’s no element in the map which matches that key.

If present the element will be promoted to be the most recently used.

Same as Self::get_or_insert, just with a fallible callback.

Returns a reference to the value for a given key. Does not change the order of the elements.

Returns a mutable reference to the value for a given key. Does not change the order of the elements.

Returns a reference to the value for a given hash and for which is_eq returns true. Does not change the order of the elements.

Returns a mutable reference to the value for a given hash and for which is_eq returns true. Does not change the order of the elements.

Removes an element from the map.

Inserts a new element into the map.

Can fail if the element is rejected by the limiter or if we fail to grow an empty map.

Returns true if the element was inserted; false otherwise.

Clears the map.

Removes the least recently accessed element and returns it.

Removes the most recently accessed element and returns it.

Returns the most recently used (inserted or accessed) element of the map. Does not change the order of the elements.

Returns the least recently used (inserted or accessed) element of the map. Does not change the order of the elements.

An iterator over all of the elements in the most recently used order.

Drains the map of all of its elements in the most recently used order.

When the iterator is dropped the map will be automatically cleared.

Returns a reference to the map’s limiter.

Returns a mutable reference to the map’s limiter.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.