use std::num::NonZero;
use heap::{Live, indexed};
use crate::{alloc, depot::heap};
impl<'a, P: Ord, C: alloc::raw::Extent, T> Live<(&'a mut indexed::Min<P, C>, T), NonZero<u32>> {
pub fn entry(self) -> (indexed::Entry<'a, P, C>, T) {
let ((owner, context), position) = self.into_inner();
let index = position.get() as usize - 1;
let live = unsafe {
crate::depot::raw::Proof::new(((owner, context), heap::Direct::from_index(index)))
};
let (slot, context) = heap::Slot::from_source(live);
(indexed::Entry::from_slot(slot), context)
}
}
impl<'a, P: Ord, C: alloc::raw::Extent, T>
Live<(&'a mut indexed::Min<P, C>, T), NonZero<u32>, indexed::Empty>
{
pub fn entry(self) -> (indexed::Vacant<'a, P, C>, T) {
let ((owner, context), position) = self.into_inner();
let key = unsafe { heap::Direct::from_index(position.get() as usize - 1) };
let entry = unsafe { heap::Vacancy::new(owner, key) };
(indexed::Vacant { entry }, context)
}
}
impl<'a, P: Ord, C: alloc::raw::Extent, T>
Live<(&'a mut indexed::Min<P, C>, T), NonZero<u32>, indexed::Full>
{
pub fn entry(self) -> (indexed::Occupied<'a, P, C>, T) {
let ((owner, context), position) = self.into_inner();
let position = unsafe {
*owner
.storage
.tail()
.get_unchecked(position.get() as usize - 1)
};
let entry = unsafe { heap::Entry::new(owner, position as usize, ()) };
(indexed::Occupied { entry }, context)
}
}