Skip to main content

Mapping

Struct Mapping 

Source
pub struct Mapping;
Expand description

A helper struct that provided the O(1) calculations to find the coordinates of a block that suits exactly the requested buffer size, or the next available one that can fit the message as well.

Implementations§

Source§

impl Mapping

Source

pub fn find_indices(size: u32) -> (u32, u32)

Maps a block size to its corresponding (First-Level, Second-Level) indices.

This function implements a two-level mapping strategy used for O(1) free-block lookup, optimized for both high-velocity small allocations and logarithmic scaling of large blocks.

§Mapping Logic:
  • Linear (Small): For sizes < 128, it uses a fixed FL (0) and 16-byte SL subdivisions. This minimizes fragmentation for tiny objects.
  • Logarithmic (Large): For sizes >= 128, FL is the power of 2 (determined via leading_zeros), and SL is a 3-bit subdivider of the range between 2^n and 2^(n+1).
§Mathematical Transformation:
  • FL = log2(size)
  • SL = (size - 2^FL) / (2^(FL - 3))
§Bounds:

Indices are clamped to (31, 7) to prevent overflow in the matrix bitmask.

§Arguments
  • size - The total byte size of the memory block.
§Returns

A tuple of (fl, sl) indices.

Auto Trait Implementations§

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> 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<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, 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.