Skip to main content

BaseIndex

Struct BaseIndex 

Source
#[repr(transparent)]
pub struct BaseIndex(pub NonZeroU8);
Expand description

A “base index” as described in Hariguchi’s ART paper; a linearized address for a prefix/octet tuple when considering the hierarchy of possible prefixes for a given 8-bit address.

Note that this only covers up to /7, fringes (/8s) would require a ninth bit, which is encoded structurally in the trie as children (vs prefixes).

Tuple Fields§

§0: NonZeroU8

Implementations§

Source§

impl BaseIndex

Source

pub const fn new(val: u8) -> Self

Construct a new index value.

§Panics

If val is zero.

Source

pub const fn try_new(val: u8) -> Option<Self>

Construct a new index value. Fails if the value is zero.

Source

pub const fn get(&self) -> u8

Retrieve the value of this index in its u8 representation.

Source

pub const fn from_prefix(octet: u8, prefix_len: u8) -> Self

Maps 8-bit prefixes to numbers. The prefixes range from 0/0 to 255/7. Return values range from 1 to 255.

§Panics

If prefix_len >= 8.

Source

pub const fn from_pfx_7(octet: u8) -> Self

Maps octet/7 prefixes to indices in 128..255. Optimization over Self::from_prefix which saves a little bit of math if the prefix length is known to be /7.

Source

pub const fn prefix(self) -> (u8, u8)

Computes the octet and prefix len of this index. Inverse of Self::from_prefix.

Source

pub const fn prefix_bits(&self, depth: usize) -> u8

Compute the bit position of a prefix represented by this index at a given trie depth.

Source

pub const fn range(&self) -> RangeInclusive<u8>

Range of octets covered by this index.

This base index encodes a prefix of up to 8 bits inside a single stride (octet). This function computes the numerical start and end of the value range for that prefix.

Source

pub const fn len(&self) -> u8

Like go’s bits.Len8: compute the number of bits required to represent this index.

Source

pub fn cmp_rank(&self, other: &Self) -> Ordering

Sort indexes in prefix sort order.

Source

pub const fn fmt_prefix(&self) -> impl Debug + use<>

Return a formatter for prefix notation: addr/len.

Source

pub const fn parent(&self) -> Option<BaseIndex>

Return the direct parent of this index (if it’s not the 0/0 index).

§Examples
let idx = BaseIndex::from_prefix(0, 4);
assert_eq!(idx.parent(), Some(BaseIndex::from_prefix(0, 3)));
Source

pub const fn children(&self) -> Option<(BaseIndex, BaseIndex)>

Return the two direct children of this index (if it’s not a /7).

§Examples
let idx = BaseIndex::from_prefix(0, 0);
assert_eq!(
    idx.children(),
    Some((BaseIndex::from_prefix(0, 1), BaseIndex::from_prefix(128, 1)))
);

Trait Implementations§

Source§

impl Clone for BaseIndex

Source§

fn clone(&self) -> BaseIndex

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 Copy for BaseIndex

Source§

impl Debug for BaseIndex

Source§

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

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

impl Display for BaseIndex

Source§

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

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

impl Eq for BaseIndex

Source§

impl From<BaseIndex> for u8

Source§

fn from(value: BaseIndex) -> Self

Converts to this type from the input type.
Source§

impl From<BaseIndex> for NonZeroU8

Source§

fn from(value: BaseIndex) -> Self

Converts to this type from the input type.
Source§

impl From<NonZero<u8>> for BaseIndex

Source§

fn from(value: NonZeroU8) -> Self

Converts to this type from the input type.
Source§

impl Hash for BaseIndex

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 Ord for BaseIndex

Source§

fn cmp(&self, other: &BaseIndex) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for BaseIndex

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for BaseIndex

Source§

fn partial_cmp(&self, other: &BaseIndex) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for BaseIndex

Source§

impl TryFrom<u8> for BaseIndex

Source§

type Error = ()

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

fn try_from(value: u8) -> Result<Self, Self::Error>

Performs the conversion.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.