Skip to content

Remove a SecondaryMap slot regardless of the version of the key #112

Open

Description

@vitreo12

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
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions