/// Caches all input/output pairs of a function in a hashmap
/// using the given key function to produce hashable keys.
///
/// `key_func` must be an isomorphism (at least as far as
/// `compute` is concerned). That is, if two inputs produce
/// the same key, then they must both `compute` to the same
/// output.
Caches all input/output pairs of a function in a hashmap
using the given key function to produce hashable keys.

`key_func` must be an isomorphism (at least as far as
`compute` is concerned). That is, if two inputs produce
the same key, then they must both `compute` to the same
output.
Caches all input / output pairs of a function in a hashmap using the given key function to produce hashable keys . ` key_func ` must be an isomorphism ( at least as far as ` compute ` is concerned ) . That is if two inputs produce the same key then they must both ` compute ` to the same output .
pub fn hash_memoize_by_key<'a, Key, In, Out, KeyFunc, F>(
    mut key_func: KeyFunc,
    mut compute: F,
) -> Box<dyn FnMut(In) -> Out + 'a>
where
    Out: Clone + 'a,
    Key: std::hash::Hash + Eq + 'a,
    KeyFunc: FnMut(&In) -> Key + 'a,
    F: FnMut(In) -> Out + 'a,
{
    let mut cache = std::collections::HashMap::new();
    Box::new(move |input|
        cache.entry(key_func(&input))
            .or_insert_with(|| compute(input))
            .clone())
}
pub fn hash_memoize_by_key < ' a , Key , In , Out , KeyFunc , F > ( mut key_func : KeyFunc , mut compute : F , ) -> Box < dyn FnMut ( In ) -> Out + ' a > where Out : Clone + ' a , Key : std :: hash :: Hash + Eq + ' a , KeyFunc : FnMut ( & In ) -> Key + ' a , F : FnMut ( In ) -> Out + ' a , { let mut cache = std :: collections :: HashMap :: new ( ) ; Box :: new ( move | input | cache . entry ( key_func ( & input ) ) . or_insert_with ( | | compute ( input ) ) . clone ( ) ) }
Caches all input/output pairs of a function in a hashmap
using the given key function to produce hashable keys.
Caches all input / output pairs of a function in a hashmap using the given key function to produce hashable keys .
key_func
KeyFunc
compute
F