MCPcopy Create free account
hub / github.com/argumentcomputer/ix / put_univ

Function put_univ

crates/ixon/src/univ.rs:53–87  ·  view source on GitHub ↗

Serialize a universe to bytes (iterative to avoid stack overflow).

(u: &Univ, buf: &mut Vec<u8>)

Source from the content-addressed store, hash-verified

51
52/// Serialize a universe to bytes (iterative to avoid stack overflow).
53pub fn put_univ(u: &Univ, buf: &mut Vec<u8>) {
54 let mut stack: Vec<&Univ> = vec![u];
55
56 while let Some(curr) = stack.pop() {
57 match curr {
58 Univ::Zero => {
59 Tag2::new(Univ::FLAG_ZERO_SUCC, 0).put(buf);
60 },
61 Univ::Succ(inner) => {
62 // Count the number of successors for telescope compression
63 let mut count = 1u64;
64 let mut base = inner.as_ref();
65 while let Univ::Succ(next) = base {
66 count += 1;
67 base = next.as_ref();
68 }
69 Tag2::new(Univ::FLAG_ZERO_SUCC, count).put(buf);
70 stack.push(base);
71 },
72 Univ::Max(a, b) => {
73 Tag2::new(Univ::FLAG_MAX, 0).put(buf);
74 stack.push(b); // Process b after a
75 stack.push(a);
76 },
77 Univ::IMax(a, b) => {
78 Tag2::new(Univ::FLAG_IMAX, 0).put(buf);
79 stack.push(b); // Process b after a
80 stack.push(a);
81 },
82 Univ::Var(idx) => {
83 Tag2::new(Univ::FLAG_VAR, *idx).put(buf);
84 },
85 }
86 }
87}
88
89/// Frame for iterative universe deserialization.
90enum GetUnivFrame {

Callers 9

univ_sort_keyFunction · 0.85
rs_eq_univ_serializationFunction · 0.85
roundtripFunction · 0.85
univ_zeroFunction · 0.85
univ_succ_zeroFunction · 0.85
univ_var_1Function · 0.85
univ_max_zero_var1Function · 0.85
put_indexedMethod · 0.85
put_univsFunction · 0.85

Calls 2

pushMethod · 0.80
putMethod · 0.45

Tested by 4

univ_zeroFunction · 0.68
univ_succ_zeroFunction · 0.68
univ_var_1Function · 0.68
univ_max_zero_var1Function · 0.68