pub fn hashmap_sample<K, V>(map: &HashMap<K, V>) -> usize
where
    K: DataSize,
    V: DataSize,
{
    if map.len() < SAMPLE_SIZE {
        map.estimate_heap_size()
    } else {
        let base_size =
            map.capacity() * (mem::size_of::<V>() + mem::size_of::<K>() + mem::size_of::<usize>());

        let mut rng = sampling_rng(map.len());

        let sampled = map
            .iter()
            .choose_multiple(&mut rng, SAMPLE_SIZE)
            .into_iter()
            .map(|(k, v)| k.estimate_heap_size() + v.estimate_heap_size())
            .sum();

        base_size + scale_sample(map.len(), sampled)
    }
}
/// Extrapolate memory usage of a `HashMap` by from a random subset of `SAMPLE_SIZE` items.
Extrapolate memory usage of a `HashMap` by from a random subset of `SAMPLE_SIZE` items.
Extrapolate memory usage of a ` HashMap ` by from a random subset of ` SAMPLE_SIZE ` items .
pub fn hashmap_sample<K, V>(map: &HashMap<K, V>) -> usize
where
    K: DataSize,
    V: DataSize,
{
    if map.len() < SAMPLE_SIZE {
        map.estimate_heap_size()
    } else {
        let base_size =
            map.capacity() * (mem::size_of::<V>() + mem::size_of::<K>() + mem::size_of::<usize>());
        let mut rng = sampling_rng(map.len());
        let sampled = map
            .iter()
            .choose_multiple(&mut rng, SAMPLE_SIZE)
            .into_iter()
            .map(|(k, v)| k.estimate_heap_size() + v.estimate_heap_size())
            .sum();
        base_size + scale_sample(map.len(), sampled)
    }
}
pub fn hashmap_sample < K , V > ( map : & HashMap < K , V > ) -> usize where K : DataSize , V : DataSize , { if map . len ( ) < SAMPLE_SIZE { map . estimate_heap_size ( ) } else { let base_size = map . capacity ( ) * ( mem :: size_of :: < V > ( ) + mem :: size_of :: < K > ( ) + mem :: size_of :: < usize > ( ) ) ; let mut rng = sampling_rng ( map . len ( ) ) ; let sampled = map . iter ( ) . choose_multiple ( & mut rng , SAMPLE_SIZE ) . into_iter ( ) . map ( | ( k , v ) | k . estimate_heap_size ( ) + v . estimate_heap_size ( ) ) . sum ( ) ; base_size + scale_sample ( map . len ( ) , sampled ) } }
Extrapolate memory usage of a `HashMap` by from a random subset of `SAMPLE_SIZE` items.
Extrapolate memory usage of a ` HashMap ` by from a random subset of ` SAMPLE_SIZE ` items .
map
&HashMap<K, V>
map
&HashMap<K, V>