slotmap icon indicating copy to clipboard operation
slotmap copied to clipboard

Remove a `SecondaryMap` slot regardless of the version of the key

Open vitreo12 opened this issue 7 months ago • 0 comments

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
    }

vitreo12 avatar Nov 11 '23 10:11 vitreo12