Skip to main content

CardinalityPointer

Struct CardinalityPointer 

Source
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>

Source

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

Source

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.

Source

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.

Source

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.

Source

pub const fn log2_cardinality(&self) -> u8

Encoded log2(cardinality) value (0..=255).

Source

pub fn cardinality(&self) -> u64

Reconstructed cardinality estimate. Caps at 2^63 (the max u64 representable in one 1 << k operation).

Source

pub const fn raw(&self) -> u64

Raw u64 packing - useful for serialization or direct compare.

Source

pub fn set_cardinality(&mut self, new_cardinality: u64)

Adjust the cardinality encoding in place; preserves the address bits.

Source

pub fn size_tier(&self) -> SizeTier

Cardinality bucket for query-planner branching. Three coarse tiers covering the typical decision points.

Trait Implementations§

Source§

impl<T> Clone for CardinalityPointer<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Copy for CardinalityPointer<T>

Source§

impl<T> Debug for CardinalityPointer<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Eq for CardinalityPointer<T>

Source§

impl<T> Hash for CardinalityPointer<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> PartialEq for CardinalityPointer<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: Send> Send for CardinalityPointer<T>

Source§

impl<T: Sync> Sync for CardinalityPointer<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.