slotmap
slotmap copied to clipboard
Remove a `SecondaryMap` slot regardless of the version of the key
Is it possible to remove a slot regardless of the version of the key, but only looking at its idx
? Currently, remove
is defined as:
pub fn remove(&mut self, key: K) -> Option<V> {
let kd = key.data();
if let Some(slot) = self.slots.get_mut(kd.idx as usize) {
if slot.version() == kd.version.get() {
self.num_elems -= 1;
return replace(slot, Slot::new_vacant()).into_option();
}
}
None
}
This function could look something like:
pub fn remove_index(&mut self, key: K) -> Option<V> {
let kd = key.data();
if let Some(slot) = self.slots.get_mut(kd.idx as usize) {
if slot.occupied() {
self.num_elems -= 1;
return replace(slot, Slot::new_vacant()).into_option();
}
}
None
}