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
impl Mapping
Sourcepub fn find_indices(size: u32) -> (u32, u32)
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§
impl Freeze for Mapping
impl RefUnwindSafe for Mapping
impl Send for Mapping
impl Sync for Mapping
impl Unpin for Mapping
impl UnsafeUnpin for Mapping
impl UnwindSafe for Mapping
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more