pub struct OccupiedEntry<'h, K, V, H = RandomState>where
H: BuildHasher,{ /* private fields */ }Expand description
OccupiedEntry is a view into an occupied entry in a HashMap.
Implementations§
Source§impl<'h, K, V, H> OccupiedEntry<'h, K, V, H>
impl<'h, K, V, H> OccupiedEntry<'h, K, V, H>
Sourcepub fn key(&self) -> &K
pub fn key(&self) -> &K
Gets a reference to the key in the entry.
§Examples
use scc::HashMap;
let hashmap: HashMap<u64, u32> = HashMap::default();
assert_eq!(hashmap.entry_sync(29).or_default().key(), &29);Sourcepub fn remove_entry(self) -> (K, V)
pub fn remove_entry(self) -> (K, V)
Sourcepub fn get(&self) -> &V
pub fn get(&self) -> &V
Gets a reference to the value in the entry.
§Examples
use scc::HashMap;
use scc::hash_map::Entry;
let hashmap: HashMap<u64, u32> = HashMap::default();
hashmap.entry_sync(19).or_insert(11);
if let Entry::Occupied(o) = hashmap.entry_sync(19) {
assert_eq!(o.get(), &11);
};Sourcepub fn get_mut(&mut self) -> &mut V
pub fn get_mut(&mut self) -> &mut V
Gets a mutable reference to the value in the entry.
§Examples
use scc::HashMap;
use scc::hash_map::Entry;
let hashmap: HashMap<u64, u32> = HashMap::default();
hashmap.entry_sync(37).or_insert(11);
if let Entry::Occupied(mut o) = hashmap.entry_sync(37) {
*o.get_mut() += 18;
assert_eq!(*o.get(), 29);
}
assert_eq!(hashmap.read_sync(&37, |_, v| *v), Some(29));Sourcepub fn insert(&mut self, val: V) -> V
pub fn insert(&mut self, val: V) -> V
Sets the value of the entry, and returns the old value.
§Examples
use scc::HashMap;
use scc::hash_map::Entry;
let hashmap: HashMap<u64, u32> = HashMap::default();
hashmap.entry_sync(37).or_insert(11);
if let Entry::Occupied(mut o) = hashmap.entry_sync(37) {
assert_eq!(o.insert(17), 11);
}
assert_eq!(hashmap.read_sync(&37, |_, v| *v), Some(17));Sourcepub fn remove(self) -> V
pub fn remove(self) -> V
Takes the value out of the entry, and returns it.
§Examples
use scc::HashMap;
use scc::hash_map::Entry;
let hashmap: HashMap<u64, u32> = HashMap::default();
hashmap.entry_sync(11).or_insert(17);
if let Entry::Occupied(o) = hashmap.entry_sync(11) {
assert_eq!(o.remove(), 17);
};Sourcepub async fn remove_and_async(
self,
) -> ((K, V), Option<OccupiedEntry<'h, K, V, H>>)
pub async fn remove_and_async( self, ) -> ((K, V), Option<OccupiedEntry<'h, K, V, H>>)
Removes the entry and gets the next closest occupied entry.
HashMap::begin_async and this method together allow the OccupiedEntry to
effectively act as a mutable iterator over entries. This method never acquires more than one
lock, even when it searches other buckets for the next closest occupied entry.
§Examples
use scc::HashMap;
use scc::hash_map::Entry;
let hashmap: HashMap<u64, u32> = HashMap::default();
assert!(hashmap.insert_sync(1, 0).is_ok());
assert!(hashmap.insert_sync(2, 0).is_ok());
let second_entry_future = hashmap.begin_sync().unwrap().remove_and_async();Sourcepub fn remove_and_sync(self) -> ((K, V), Option<Self>)
pub fn remove_and_sync(self) -> ((K, V), Option<Self>)
Removes the entry and gets the next closest occupied entry.
HashMap::begin_sync and this method together allow the OccupiedEntry to effectively
act as a mutable iterator over entries. This method never acquires more than one lock, even
when it searches other buckets for the next closest occupied entry.
§Examples
use scc::HashMap;
use scc::hash_map::Entry;
let hashmap: HashMap<u64, u32> = HashMap::default();
assert!(hashmap.insert_sync(1, 0).is_ok());
assert!(hashmap.insert_sync(2, 0).is_ok());
let first_entry = hashmap.begin_sync().unwrap();
let first_key = *first_entry.key();
let (removed, second_entry) = first_entry.remove_and_sync();
assert_eq!(removed.1, 0);
assert_eq!(hashmap.len(), 1);
let second_entry = second_entry.unwrap();
let second_key = *second_entry.key();
assert!(second_entry.remove_and_sync().1.is_none());
assert_eq!(first_key + second_key, 3);Sourcepub async fn next_async(self) -> Option<OccupiedEntry<'h, K, V, H>>
pub async fn next_async(self) -> Option<OccupiedEntry<'h, K, V, H>>
Gets the next closest occupied entry.
HashMap::begin_async and this method together allow the OccupiedEntry to
effectively act as a mutable iterator over entries. This method never acquires more than one
lock, even when it searches other buckets for the next closest occupied entry.
§Examples
use scc::HashMap;
use scc::hash_map::Entry;
let hashmap: HashMap<u64, u32> = HashMap::default();
assert!(hashmap.insert_sync(1, 0).is_ok());
assert!(hashmap.insert_sync(2, 0).is_ok());
let second_entry_future = hashmap.begin_sync().unwrap().next_async();Sourcepub fn next_sync(self) -> Option<Self>
pub fn next_sync(self) -> Option<Self>
Gets the next closest occupied entry.
HashMap::begin_sync and this method together allow the OccupiedEntry to effectively
act as a mutable iterator over entries. This method never acquires more than one lock, even
when it searches other buckets for the next closest occupied entry.
§Examples
use scc::HashMap;
use scc::hash_map::Entry;
let hashmap: HashMap<u64, u32> = HashMap::default();
assert!(hashmap.insert_sync(1, 0).is_ok());
assert!(hashmap.insert_sync(2, 0).is_ok());
let first_entry = hashmap.begin_sync().unwrap();
let first_key = *first_entry.key();
let second_entry = first_entry.next_sync().unwrap();
let second_key = *second_entry.key();
assert!(second_entry.next_sync().is_none());
assert_eq!(first_key + second_key, 3);