use crate::{free_pointer::FreePointer, generation::Generation};
#[derive(Debug, Clone)]
pub(crate) enum Entry<V> {
Occupied(OccupiedEntry<V>),
Empty(EmptyEntry),
}
impl<V> Entry<V> {
pub(crate) fn into_value(self) -> Option<V> {
match self {
Entry::Occupied(occupied) => Some(occupied.value),
Entry::Empty(_) => None,
}
}
pub(crate) fn get_value_mut(&mut self, generation: Generation) -> Option<&mut V> {
match self {
Entry::Occupied(occupied) if occupied.generation == generation => {
Some(&mut occupied.value)
}
_ => None,
}
}
pub(crate) fn as_empty(&self) -> Option<&EmptyEntry> {
match self {
Entry::Empty(empty) => Some(empty),
Entry::Occupied(_) => None,
}
}
pub(crate) fn as_empty_mut(&mut self) -> Option<&mut EmptyEntry> {
match self {
Entry::Empty(empty) => Some(empty),
Entry::Occupied(_) => None,
}
}
}
#[derive(Debug, Clone)]
pub(crate) struct OccupiedEntry<V> {
pub(crate) generation: Generation,
pub(crate) value: V,
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct EmptyEntry {
pub(crate) generation: Generation,
pub(crate) next_free: Option<FreePointer>,
}