Skip to main content

Arena

Struct Arena 

Source
pub struct Arena<K, V, const N: usize> { /* private fields */ }
Expand description

A lock-free static memory pool for Nodes using tagged indices to prevent ABA.

Implementations§

Source§

impl<K, V, const N: usize> Arena<K, V, N>

Source

pub const fn new() -> Self

Source

pub fn alloc( &self, key: K, value: V, node: *mut ThreadStateNode, ) -> Option<usize>

Allocates a node from the free list and initializes it. Returns the index of the allocated node.

§Safety

node must be a valid pointer.

Source

pub unsafe fn free(&self, index: usize)

Safely frees a node, running its drop logic, and returning it to the free list. MUST only be called when no threads are reading the node (e.g., via QSBR).

Source

pub unsafe fn drop_node(&self, index: usize)

Drops the inner item without pushing it to the free list.

Source

pub fn set_next_free(&self, index: u32, next: u32)

Source

pub unsafe fn free_batch(&self, head_idx: u32, tail_idx: u32)

Pushes a batch of nodes to the global free list without dropping it.

Source

pub unsafe fn free_raw(&self, index: usize)

Pushes a node index to the global free list without dropping it.

Source

pub unsafe fn get(&self, index: usize) -> &Node<K, V>

Get a reference to a node. Caller must ensure index is valid and the node is currently allocated.

Source

pub unsafe fn get_mut(&self, index: usize) -> &mut Node<K, V>

Trait Implementations§

Source§

impl<K, V, const N: usize> Default for Arena<K, V, N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K: Send, V: Send, const N: usize> Send for Arena<K, V, N>

Source§

impl<K: Sync, V: Sync, const N: usize> Sync for Arena<K, V, N>

Auto Trait Implementations§

§

impl<K, V, const N: usize> !Freeze for Arena<K, V, N>

§

impl<K, V, const N: usize> !RefUnwindSafe for Arena<K, V, N>

§

impl<K, V, const N: usize> Unpin for Arena<K, V, N>
where K: Unpin, V: Unpin,

§

impl<K, V, const N: usize> UnsafeUnpin for Arena<K, V, N>
where K: UnsafeUnpin, V: UnsafeUnpin,

§

impl<K, V, const N: usize> UnwindSafe for Arena<K, V, N>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.