use std::collections::hash_map::Entry;
use std::hash::Hash;
use std::sync::Arc;
use rustc_hash::FxHashMap;
pub(crate) fn update_arc_lookup_for_keys<K, T>(
lookup: &mut FxHashMap<K, Arc<T>>,
keys: impl IntoIterator<Item = K>,
node: &Arc<T>,
) -> usize
where
K: Eq + Hash,
{
let mut changed = 0;
for key in keys {
match lookup.entry(key) {
Entry::Occupied(mut entry) if !Arc::ptr_eq(entry.get(), node) => {
entry.insert(Arc::clone(node));
changed += 1;
}
Entry::Occupied(_) => {}
Entry::Vacant(entry) => {
entry.insert(Arc::clone(node));
changed += 1;
}
}
}
changed
}