Struct fn_cache::HashCache

source ·
pub struct HashCache<'f, I, O, S = RandomState>where
    I: Eq + Hash,
{ /* private fields */ }
Expand description

A cache for a function which uses a HashMap.

The cache takes ownership of all inputs, but only passes a reference to the function, allowing it to store the input in the cache without any copies or clones.

The requirements for a HashMap must be met, specifically the keys must implement Eq and Hash, and the following propery must hold:

k1 == k2 -> hash(k1) == hash(k2)

Implementations§

Create a cache for the provided function. If the function stores references, the cache can only live as long as those references.

Create a cache for the provided recursive function. If the function stores references, the cache can only live as long as those references.

Create a HashCache which will use the given hash builder to hash keys.

See the documentation on HashMap::with_hasher for more details.

Create a recursive HashCache which will use the given hash builder to hash keys.

See the documentation on HashMap::with_hasher for more details.

Clears the cache, removing all key-value pairs. Keeps the allocated memory for reuse.

Returns the number of elements in the cache.

Reserves capacity for at least additional more elements to be inserted in the cache. The collection may reserve more space to avoid frequent reallocations.

Removes the input from the cache, returning any value if the input was previously in the cache.

Trait Implementations§

Retrieve a value stored in the cache. If the value does not yet exist in the cache, the function is called, and the result is added to the cache before returning it.

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 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.