HashTableAllocExt

Trait HashTableAllocExt 

Source
pub trait HashTableAllocExt {
    type T;

    // Required method
    fn insert_accounted(
        &mut self,
        x: Self::T,
        hasher: impl Fn(&Self::T) -> u64,
        accounting: &mut usize,
    );
}
Expand description

Extension trait for hash browns HashTable to account for allocations.

Required Associated Types§

Source

type T

Item type.

Required Methods§

Source

fn insert_accounted( &mut self, x: Self::T, hasher: impl Fn(&Self::T) -> u64, accounting: &mut usize, )

Insert new element into table and increase accounting by any newly allocated bytes.

Returns the bucket where the element was inserted. Note that allocation counts capacity, not size.

§Example:
let mut table = HashTable::new();
let mut allocated = 0;
let hash_fn = |x: &u32| (*x as u64) % 1000;
// pretend 0x3117 is the hash value for 1
table.insert_accounted(1, hash_fn, &mut allocated);
assert_eq!(allocated, 64);

// insert more values
for i in 0..100 {
    table.insert_accounted(i, hash_fn, &mut allocated);
}
assert_eq!(allocated, 400);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> HashTableAllocExt for HashTable<T>
where T: Eq,

Source§

type T = T