Skip to main content

PertaroExpert243

Struct PertaroExpert243 

Source
#[repr(transparent)]
pub struct PertaroExpert243(pub Word256);
Expand description

Zero-cost view over Word256: the payload as a 5-tier micro-expert.

Tuple Fields§

§0: Word256

Implementations§

Source§

impl PertaroExpert243

Source

pub const fn seed(&self) -> u64

The seed: the word’s hash field.

Examples found in repository?
examples/quick_start.rs (line 30)
5fn main() {
6    // 1. A 256-byte word with a seed, a parent link, and in-band sentinels.
7    let mut raw = Word256 {
8        hash: 0xcbf2_9ce4_8422_2325,
9        parent: 0,
10        trits: [0u8; 244],
11    };
12
13    // Address leaf [1, 0, 2, 1, 2] in the 5-tier ternary trie (each tier in 0..3).
14    let target_leaf = PertaroExpert243::trie_index([1, 0, 2, 1, 2]);
15    raw.trits[target_leaf] = 42; // residual override: +42 mod 243
16
17    // Stamp a defeated branch with an in-band Tombstone (245).
18    let defeated_leaf = PertaroExpert243::trie_index([2, 2, 0, 1, 0]);
19    raw.trits[defeated_leaf] = Sentinel::Tombstone as u8;
20
21    // Mark the root horizon sentinel at trits[243].
22    raw.trits[ROOT_SENTINEL] = Sentinel::NullNode as u8;
23
24    // 2. Wrap in the zero-cost view and materialize.
25    let expert = PertaroExpert243(raw);
26    let materialized: Word256 = expert.materialize();
27
28    assert!(materialized.trits[target_leaf] < MAX_PACKED);
29    assert_eq!(materialized.trits[defeated_leaf], Sentinel::Tombstone as u8);
30    assert_eq!(materialized.hash, expert.seed());
31
32    // 3. Reground the winning Tier-5 leaf (0..243) into a fresh seed.
33    let next_seed = expert.reground_seed(target_leaf as u8, Sentinel::BusIndirect);
34    assert_ne!(next_seed, expert.seed());
35
36    println!("leaf {target_leaf} -> {}", materialized.trits[target_leaf]);
37    println!("next seed {next_seed:#018x}");
38}
Source

pub const fn parent(&self) -> u32

The lineage link.

Source

pub const fn root_sentinel_byte(&self) -> u8

The raw root sentinel byte at payload index 243.

Source

pub const fn root_sentinel(&self) -> Option<Sentinel>

The active phase, or None if the root byte is a coordinate.

Source

pub const fn leaves(&self) -> &[u8; 243]

The 243 raw leaf bytes: deltas 0..243 or in-band sentinels.

Source

pub const fn trie_index(path: [u8; 5]) -> usize

Leaf index 0..243 of a 5-tier ternary path. Every tier must be in 0..3; anything else is a panic, because the path is the address.

Examples found in repository?
examples/quick_start.rs (line 14)
5fn main() {
6    // 1. A 256-byte word with a seed, a parent link, and in-band sentinels.
7    let mut raw = Word256 {
8        hash: 0xcbf2_9ce4_8422_2325,
9        parent: 0,
10        trits: [0u8; 244],
11    };
12
13    // Address leaf [1, 0, 2, 1, 2] in the 5-tier ternary trie (each tier in 0..3).
14    let target_leaf = PertaroExpert243::trie_index([1, 0, 2, 1, 2]);
15    raw.trits[target_leaf] = 42; // residual override: +42 mod 243
16
17    // Stamp a defeated branch with an in-band Tombstone (245).
18    let defeated_leaf = PertaroExpert243::trie_index([2, 2, 0, 1, 0]);
19    raw.trits[defeated_leaf] = Sentinel::Tombstone as u8;
20
21    // Mark the root horizon sentinel at trits[243].
22    raw.trits[ROOT_SENTINEL] = Sentinel::NullNode as u8;
23
24    // 2. Wrap in the zero-cost view and materialize.
25    let expert = PertaroExpert243(raw);
26    let materialized: Word256 = expert.materialize();
27
28    assert!(materialized.trits[target_leaf] < MAX_PACKED);
29    assert_eq!(materialized.trits[defeated_leaf], Sentinel::Tombstone as u8);
30    assert_eq!(materialized.hash, expert.seed());
31
32    // 3. Reground the winning Tier-5 leaf (0..243) into a fresh seed.
33    let next_seed = expert.reground_seed(target_leaf as u8, Sentinel::BusIndirect);
34    assert_ne!(next_seed, expert.seed());
35
36    println!("leaf {target_leaf} -> {}", materialized.trits[target_leaf]);
37    println!("next seed {next_seed:#018x}");
38}
Source

pub const fn default_field(seed: u64, out: &mut [u8; 243])

Fill out with 243 uniform Z_243 digits from the seed’s xorshift64 stream by radix-243 extraction with word rejection. A zero seed is replaced by FNV1A64_BASIS so the stream is never the zero fixed point.

Source

pub const fn materialize(&self) -> Word256

Materialize the expert: header and root byte copied verbatim, each leaf resolved as (base + delta) mod 243, or by its in-band sentinel (NullNode keeps the base; every other sentinel propagates as-is).

Examples found in repository?
examples/quick_start.rs (line 26)
5fn main() {
6    // 1. A 256-byte word with a seed, a parent link, and in-band sentinels.
7    let mut raw = Word256 {
8        hash: 0xcbf2_9ce4_8422_2325,
9        parent: 0,
10        trits: [0u8; 244],
11    };
12
13    // Address leaf [1, 0, 2, 1, 2] in the 5-tier ternary trie (each tier in 0..3).
14    let target_leaf = PertaroExpert243::trie_index([1, 0, 2, 1, 2]);
15    raw.trits[target_leaf] = 42; // residual override: +42 mod 243
16
17    // Stamp a defeated branch with an in-band Tombstone (245).
18    let defeated_leaf = PertaroExpert243::trie_index([2, 2, 0, 1, 0]);
19    raw.trits[defeated_leaf] = Sentinel::Tombstone as u8;
20
21    // Mark the root horizon sentinel at trits[243].
22    raw.trits[ROOT_SENTINEL] = Sentinel::NullNode as u8;
23
24    // 2. Wrap in the zero-cost view and materialize.
25    let expert = PertaroExpert243(raw);
26    let materialized: Word256 = expert.materialize();
27
28    assert!(materialized.trits[target_leaf] < MAX_PACKED);
29    assert_eq!(materialized.trits[defeated_leaf], Sentinel::Tombstone as u8);
30    assert_eq!(materialized.hash, expert.seed());
31
32    // 3. Reground the winning Tier-5 leaf (0..243) into a fresh seed.
33    let next_seed = expert.reground_seed(target_leaf as u8, Sentinel::BusIndirect);
34    assert_ne!(next_seed, expert.seed());
35
36    println!("leaf {target_leaf} -> {}", materialized.trits[target_leaf]);
37    println!("next seed {next_seed:#018x}");
38}
Source

pub const fn reground_seed(&self, winner: u8, next: Sentinel) -> u64

Reground at the Tier-5 boundary: fold the seed, the winning leaf (0..243) and the next phase through FNV-1a, then one xorshift64 step. A winner at or above 243 is a panic: sentinels are not leaves.

Examples found in repository?
examples/quick_start.rs (line 33)
5fn main() {
6    // 1. A 256-byte word with a seed, a parent link, and in-band sentinels.
7    let mut raw = Word256 {
8        hash: 0xcbf2_9ce4_8422_2325,
9        parent: 0,
10        trits: [0u8; 244],
11    };
12
13    // Address leaf [1, 0, 2, 1, 2] in the 5-tier ternary trie (each tier in 0..3).
14    let target_leaf = PertaroExpert243::trie_index([1, 0, 2, 1, 2]);
15    raw.trits[target_leaf] = 42; // residual override: +42 mod 243
16
17    // Stamp a defeated branch with an in-band Tombstone (245).
18    let defeated_leaf = PertaroExpert243::trie_index([2, 2, 0, 1, 0]);
19    raw.trits[defeated_leaf] = Sentinel::Tombstone as u8;
20
21    // Mark the root horizon sentinel at trits[243].
22    raw.trits[ROOT_SENTINEL] = Sentinel::NullNode as u8;
23
24    // 2. Wrap in the zero-cost view and materialize.
25    let expert = PertaroExpert243(raw);
26    let materialized: Word256 = expert.materialize();
27
28    assert!(materialized.trits[target_leaf] < MAX_PACKED);
29    assert_eq!(materialized.trits[defeated_leaf], Sentinel::Tombstone as u8);
30    assert_eq!(materialized.hash, expert.seed());
31
32    // 3. Reground the winning Tier-5 leaf (0..243) into a fresh seed.
33    let next_seed = expert.reground_seed(target_leaf as u8, Sentinel::BusIndirect);
34    assert_ne!(next_seed, expert.seed());
35
36    println!("leaf {target_leaf} -> {}", materialized.trits[target_leaf]);
37    println!("next seed {next_seed:#018x}");
38}

Trait Implementations§

Source§

impl Clone for PertaroExpert243

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

Source§

impl Debug for PertaroExpert243

Source§

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

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

impl Eq for PertaroExpert243

Source§

impl PartialEq for PertaroExpert243

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 StructuralPartialEq for PertaroExpert243

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.