Function lru_mem::entry_size

source ·
pub fn entry_size<K: MemSize, V: MemSize>(key: &K, value: &V) -> usize
Expand description

Gets the memory an entry with the given key and value would occupy in an LRU cache, in bytes. This is also the function used internally, thus if the returned number of bytes fits inside the cache (as can be determined using LruCache::current_size and LruCache::max_size), it is guaranteed not to eject an element.

Arguments

  • key: A reference to the key of the entry whose size to determine.
  • value: A reference to the value of the entry whose size to determine.

Example

let key_1 = 0u64;
let value_1 = vec![0u8; 10];
let size_1 = lru_mem::entry_size(&key_1, &value_1);

let key_2 = 1u64;
let value_2 = vec![0u8; 1000];
let size_2 = lru_mem::entry_size(&key_2, &value_2);

assert!(size_1 < size_2);