o3 0.62.0

shared-nothing primitives
Documentation
use crate::depot::{self, queue::links};

/// Stable one-to-one compact-index mapping.
/// # Safety
/// Hooks stay stable/non-aliasing; unchecked nodes are represented.
pub unsafe trait Hooks<const PLANE: usize = 0> {
    /// # Safety
    /// The hook is exclusively detached in this exact reciprocal chain and store.
    /// Implementations publish this exact hook once and preserve cardinality.
    unsafe fn chain_push<C: crate::depot::raw::ChainCount>(
        &self,
        chain: &links::raw::Chain<C>,
        index: links::Index,
    ) {
        unsafe { chain.link_back::<PLANE, _>(self, index, self.hook_raw(index)) };
    }
    /// # Safety
    /// The index is linked in this exact reciprocal chain and store.
    /// Implementations detach this exact hook and preserve cardinality.
    unsafe fn chain_unlink<'a, C: crate::depot::raw::ChainCount>(
        &'a self,
        chain: &'a links::raw::Chain<C>,
        index: links::Index,
    ) -> links::Detached<'a> {
        unsafe { chain.detach_hook::<false, PLANE, _>(self, index, self.hook_raw(index)) }.0
    }
    /// # Safety
    /// `index` remains the live reciprocal front of this exact chain and hook
    /// store through commit. Implementations detach it and preserve cardinality.
    unsafe fn chain_pop<'a, C: crate::depot::raw::ChainCount>(
        &'a self,
        chain: &'a links::raw::Chain<C>,
        index: links::Index,
    ) -> links::Detached<'a> {
        // SAFETY: the caller retains this exact front, chain, and hook store.
        unsafe { chain.detach_hook::<true, PLANE, _>(self, index, self.hook_raw(index)) }.0
    }

    /// # Safety
    /// The index is detached and absent from every list of this owner.
    /// Implementations return this exact hook to the owner's free list once.
    unsafe fn recycle(&self, free: &links::Free, index: links::Index) {
        // SAFETY: the caller retains this exact hook exclusively outside every list.
        free.recycle(unsafe { links::Detached::new(self.hook_raw(index), index) });
    }

    /// # Safety
    /// This detached hook and the chain's reciprocal endpoints belong to this exact store.
    unsafe fn push<C: crate::depot::raw::ChainCount>(
        &self,
        detached: links::Detached<'_>,
        chain: &links::raw::Chain<C>,
    ) {
        unsafe { chain.push::<PLANE, _>(self, detached) };
    }

    /// # Safety
    /// `index` names a node represented by this view.
    unsafe fn hook_raw(&self, index: links::Index) -> &links::Hook;
    /// # Safety
    /// `hook` is the exclusively detached slot at `index` in this exact list's plane.
    unsafe fn link_raw(&self, list: &links::raw::List, index: links::Index, hook: &links::Hook) {
        let adjacent = list.first().map(|next| {
            // SAFETY: this observed head belongs to the same retained hook plane.
            (next, unsafe { self.hook_raw(next) }.into())
        });
        // SAFETY: all original hooks are resolved before publishing this vacant node.
        unsafe {
            depot::raw::EndpointHook::from(hook).push::<true, _>(
                list,
                index,
                links::Index::END,
                adjacent,
            )
        };
    }

    /// # Safety
    /// `hook` stays exclusively linked in this exact list and reciprocal hook plane.
    /// The owner retains detached membership; this operation leaves the hook's words unchanged.
    unsafe fn unlink_raw(&self, list: &links::raw::List, hook: &links::Hook) {
        // SAFETY: the original neighbors retain this exact member until this commit.
        unsafe { depot::raw::EndpointHook::from(hook).unlink::<PLANE, _, _>(list, self) };
    }
}

// SAFETY: each in-bounds node owns one stable hook for this exact borrowed slice.
unsafe impl<T> Hooks for [depot::raw::Node<T>] {
    unsafe fn hook_raw(&self, index: links::Index) -> &links::Hook {
        unsafe { self.get_unchecked(index.get()) }.hook()
    }
}

// SAFETY: the original slice gives each represented index one stable, distinct hook.
unsafe impl<K, Q, P> Hooks for [depot::raw::StagedNode<K, Q, P>] {
    unsafe fn hook_raw(&self, index: links::Index) -> &links::Hook {
        &unsafe { self.get_unchecked(index.get()) }.hook
    }
}