use std::cell;
use crate::{
base::num,
depot::{self, arena::slab::external, index, index::bitmap, queue::links},
mem,
};
unsafe impl<'a, T, M> depot::raw::Project<(), T> for &'a mem::raw::Storage<T, M> {
type Output = &'a T;
unsafe fn project(self, _: ()) -> Self::Output {
unsafe { mem::raw::Storage::project(self) }
}
}
unsafe impl<'a, T, M> depot::raw::Project<(), T> for &'a mut mem::raw::Storage<T, M> {
type Output = mem::raw::Occupied<'a, T>;
unsafe fn project(self, _: ()) -> Self::Output {
unsafe { mem::raw::Storage::occupy(self) }
}
}
unsafe impl<'a, T, M> depot::raw::Project<(), index::Vacant<T>>
for &'a mut mem::raw::Storage<T, M>
{
type Output = mem::raw::Vacant<'a, T>;
unsafe fn project(self, _: ()) -> Self::Output {
unsafe { mem::raw::Storage::vacancy(self) }
}
}
unsafe impl<'a, T, const N: usize> depot::raw::Project<usize> for &'a [T; N] {
type Output = &'a T;
unsafe fn project(self, index: usize) -> Self::Output {
unsafe { self.get_unchecked(index) }
}
}
unsafe impl<'a, T, const N: usize> depot::raw::Project<usize> for &'a mut [T; N] {
type Output = &'a mut T;
unsafe fn project(self, index: usize) -> Self::Output {
unsafe { self.get_unchecked_mut(index) }
}
}
unsafe impl<'a, T> depot::raw::Project<usize> for &'a mut [T] {
type Output = &'a mut T;
unsafe fn project(self, index: usize) -> Self::Output {
unsafe { self.get_unchecked_mut(index) }
}
}
unsafe impl<K: crate::depot::raw::Key> crate::depot::raw::Address for K {
fn index(self) -> usize {
crate::depot::raw::Key::index(self)
}
}
unsafe impl<I: Copy + Eq> crate::depot::raw::Link for Option<I> {
type Item = I;
const NONE: Self = None;
fn item(self) -> Option<I> {
self
}
unsafe fn some(item: I) -> Self {
Some(item)
}
}
unsafe impl crate::depot::raw::Link for u16 {
type Item = Self;
const NONE: Self = Self::MAX;
fn item(self) -> Option<Self> {
(self != Self::NONE).then_some(self)
}
unsafe fn some(item: Self) -> Self {
item
}
}
unsafe impl crate::depot::raw::Link for u32 {
type Item = Self;
const NONE: Self = Self::MAX;
fn item(self) -> Option<Self> {
(self != Self::NONE).then_some(self)
}
unsafe fn some(item: Self) -> Self {
item
}
}
unsafe impl crate::depot::raw::ChainCount for u32 {
const EMPTY: Self = 0;
fn storage(count: &cell::Cell<Self>) -> Option<&cell::Cell<u32>> {
Some(count)
}
}
unsafe impl crate::depot::raw::ChainCount for () {
const EMPTY: Self = ();
fn storage(_: &cell::Cell<Self>) -> Option<&cell::Cell<u32>> {
None
}
}
mod key;
mod word;
unsafe impl crate::depot::raw::Compact for u32 {
const MAX: u32 = u32::MAX;
fn into_raw(self) -> u32 {
self
}
unsafe fn from_raw(raw: u32) -> Self {
raw
}
}
mod exacts;
unsafe impl<G: num::Step, Tag> crate::depot::raw::Address for external::Key<G, Tag> {
fn index(self) -> usize {
self.index() as usize
}
}
unsafe impl crate::depot::raw::Address for links::Index {
fn index(self) -> usize {
self.get()
}
}
unsafe impl<W: bitmap::Width, S: depot::raw::Words<W>> depot::raw::Words<W> for &S {
type Plane = S::Plane;
type Size = S::Size;
fn shape(&self) -> bitmap::Shape<Self::Size, W> {
S::shape(self)
}
fn words(&self, plane: Self::Plane) -> &[bitmap::Word<W>] {
S::words(self, plane)
}
fn row(entry: bitmap::raw::Row<&Self, (), (), W>, plane: Self::Plane) -> &[bitmap::Word<W>] {
let source = unsafe { depot::raw::Proof::new((*entry.source, entry.position())) };
S::row(bitmap::raw::Row::from_source(source), plane)
}
}
unsafe impl<W: bitmap::Width, S: depot::raw::Words<W>> depot::raw::Words<W> for &mut S {
type Plane = S::Plane;
type Size = S::Size;
fn shape(&self) -> bitmap::Shape<Self::Size, W> {
S::shape(self)
}
fn words(&self, plane: Self::Plane) -> &[bitmap::Word<W>] {
S::words(self, plane)
}
fn row(entry: bitmap::raw::Row<&Self, (), (), W>, plane: Self::Plane) -> &[bitmap::Word<W>] {
let source = unsafe { depot::raw::Proof::new((&**entry.source, entry.position())) };
S::row(bitmap::raw::Row::from_source(source), plane)
}
}