pub struct SharedMemoryContents<K, V> { /* private fields */ }
Implementations§
Sourcepub fn try_insert(&mut self, key: K, value: V) -> Result<Option<V>, Error>
pub fn try_insert(&mut self, key: K, value: V) -> Result<Option<V>, Error>
Tries to insert a key-value pair into the shared hashmap. If the key already exists, it is removed before inserting the new value. If the size of the hashmap exceeds the maximum size, it will evict items until there is enough space to insert the new key-value pair. Returns a Result containing an Option of the removed value if the hashmap was full and an item had to be evicted, or an error if the hashmap is too large to insert the new key-value pair.
§Arguments
key
- A key of type K to insert into the hashmap.value
- A value of type V to insert into the hashmap.
Sourcepub fn get(&mut self, key: &K) -> Option<V>
pub fn get(&mut self, key: &K) -> Option<V>
Returns the value associated with the given key in the hashmap, or None
if the key is not present.
If the key is present, the last accessed time for the corresponding bucket is updated.
§Arguments
key
- A reference to the key to search for in the hashmap.
§Returns
Some(V)
- The value associated with the given key, if it exists in the hashmap.None
- If the key is not present in the hashmap.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Removes the entry with the specified key from the hashmap and returns the value of the removed entry.
If the key is not present in the hashmap, returns None
.
§Arguments
self
- A mutable reference to the hashmap.key
- The key of the entry to be removed.
§Returns
Some(V)
- The value of the removed entry, if it existed in the hashmap.None
- If the key was not present in the hashmap.
Sourcepub fn used(&self) -> usize
pub fn used(&self) -> usize
Returns the total size of the shared memory contents used by the hashmap.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true if the shared hashmap contains the specified key.
§Arguments
key
- A reference to the key to search for in the shared hashmap.