#[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: Word256Implementations§
Source§impl PertaroExpert243
impl PertaroExpert243
Sourcepub const fn seed(&self) -> u64
pub const fn seed(&self) -> u64
The seed: the word’s hash field.
Examples found in repository?
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}Sourcepub const fn root_sentinel_byte(&self) -> u8
pub const fn root_sentinel_byte(&self) -> u8
The raw root sentinel byte at payload index 243.
Sourcepub const fn root_sentinel(&self) -> Option<Sentinel>
pub const fn root_sentinel(&self) -> Option<Sentinel>
The active phase, or None if the root byte is a coordinate.
Sourcepub const fn leaves(&self) -> &[u8; 243]
pub const fn leaves(&self) -> &[u8; 243]
The 243 raw leaf bytes: deltas 0..243 or in-band sentinels.
Sourcepub const fn trie_index(path: [u8; 5]) -> usize
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?
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}Sourcepub const fn default_field(seed: u64, out: &mut [u8; 243])
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.
Sourcepub const fn materialize(&self) -> Word256
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?
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}Sourcepub const fn reground_seed(&self, winner: u8, next: Sentinel) -> u64
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?
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}