pub struct CardinalityPointer<T> { /* private fields */ }Expand description
8-byte pointer with log2(cardinality) packed into the high byte.
T: Sized so the pointer stays thin.
Implementations§
Source§impl<T> CardinalityPointer<T>
impl<T> CardinalityPointer<T>
Sourcepub const SIGNATURE: AxisMask
pub const SIGNATURE: AxisMask
Direction signature of CardinalityPointer<T>. Engages the
K_content_prefix axis (log2-cardinality estimate stored at
slot for size-class branching before deref).
Sourcepub unsafe fn from_raw(target: *const T, cardinality_hint: u64) -> Self
pub unsafe fn from_raw(target: *const T, cardinality_hint: u64) -> Self
Construct from a raw pointer and a cardinality estimate.
cardinality_hint is bucketed to its log2; values from
0 (single element) to 2^255 are encodable.
Runtime-checks that the address fits in the 56-bit
envelope and panics on violation. For trusted hot paths
where the caller has already verified the address fits
(e.g. from a known-canonical allocator on x86-64 4-level
paging), use Self::from_raw_unchecked to skip the
check.
§Safety
target must be a valid pointer to a T AND must remain
valid for the lifetime of this pointer.
§Panics
Panics if the high byte of target as u64 is non-zero
(address exceeds the 56-bit envelope). The check runs in
both debug and release builds.
Sourcepub unsafe fn from_raw_unchecked(
target: *const T,
cardinality_hint: u64,
) -> Self
pub unsafe fn from_raw_unchecked( target: *const T, cardinality_hint: u64, ) -> Self
Construct from a raw pointer and a cardinality estimate
WITHOUT checking the address envelope. The high byte of the
address is silently masked off via ADDR_MASK; if the
caller violates the 56-bit envelope, the resulting pointer
dereferences to the WRONG address.
§Safety
In addition to the standard from_raw safety contract:
caller asserts that (target as u64) & !ADDR_MASK == 0.
On x86-64 with 4-level paging (the canonical configuration)
this holds for any user-space pointer; on 5-level paging
or with hardware MTE/TBI features that occupy the high byte
it does NOT hold and using this constructor is undefined
behaviour.
Sourcepub fn as_raw(&self) -> *const T
pub fn as_raw(&self) -> *const T
The address, with the cardinality byte masked off. This is the bit pattern that must be used for any deref or pointer comparison.
Sourcepub const fn log2_cardinality(&self) -> u8
pub const fn log2_cardinality(&self) -> u8
Encoded log2(cardinality) value (0..=255).
Sourcepub fn cardinality(&self) -> u64
pub fn cardinality(&self) -> u64
Reconstructed cardinality estimate. Caps at 2^63 (the max u64
representable in one 1 << k operation).
Sourcepub fn set_cardinality(&mut self, new_cardinality: u64)
pub fn set_cardinality(&mut self, new_cardinality: u64)
Adjust the cardinality encoding in place; preserves the address bits.