Compute the base size of a node (Tag4 header size) for Ixon serialization.
(expr: &Expr)
| 148 | /// Compute the base size of a node (Tag4 header size) for Ixon serialization. |
| 149 | fn compute_base_size(expr: &Expr) -> usize { |
| 150 | match expr { |
| 151 | Expr::Sort(univ_idx) => { |
| 152 | Tag4::new(Expr::FLAG_SORT, *univ_idx).encoded_size() |
| 153 | }, |
| 154 | Expr::Var(idx) => Tag4::new(Expr::FLAG_VAR, *idx).encoded_size(), |
| 155 | Expr::Ref(ref_idx, univ_indices) => { |
| 156 | // tag + ref_idx + N univ indices |
| 157 | Tag4::new(Expr::FLAG_REF, univ_indices.len() as u64).encoded_size() |
| 158 | + Tag0::new(*ref_idx).encoded_size() |
| 159 | + univ_indices |
| 160 | .iter() |
| 161 | .map(|i| Tag0::new(*i).encoded_size()) |
| 162 | .sum::<usize>() |
| 163 | }, |
| 164 | Expr::Rec(rec_idx, univ_indices) => { |
| 165 | // tag + rec_idx + N univ indices |
| 166 | Tag4::new(Expr::FLAG_REC, univ_indices.len() as u64).encoded_size() |
| 167 | + Tag0::new(*rec_idx).encoded_size() |
| 168 | + univ_indices |
| 169 | .iter() |
| 170 | .map(|i| Tag0::new(*i).encoded_size()) |
| 171 | .sum::<usize>() |
| 172 | }, |
| 173 | Expr::Prj(type_ref_idx, field_idx, _) => { |
| 174 | // Tag (field_idx in payload) + type_ref_idx (variable length, estimate 2 bytes) |
| 175 | Tag4::new(Expr::FLAG_PRJ, *field_idx).encoded_size() |
| 176 | + Tag0::new(*type_ref_idx).encoded_size() |
| 177 | }, |
| 178 | Expr::Str(ref_idx) => Tag4::new(Expr::FLAG_STR, *ref_idx).encoded_size(), |
| 179 | Expr::Nat(ref_idx) => Tag4::new(Expr::FLAG_NAT, *ref_idx).encoded_size(), |
| 180 | Expr::App(..) => Tag4::new(Expr::FLAG_APP, 1).encoded_size(), // telescope count >= 1 |
| 181 | Expr::Lam(..) => Tag4::new(Expr::FLAG_LAM, 1).encoded_size(), |
| 182 | Expr::All(..) => Tag4::new(Expr::FLAG_ALL, 1).encoded_size(), |
| 183 | Expr::Let(non_dep, ..) => { |
| 184 | // size=0 for dep, size=1 for non_dep |
| 185 | Tag4::new(Expr::FLAG_LET, if *non_dep { 1 } else { 0 }).encoded_size() |
| 186 | }, |
| 187 | Expr::Share(idx) => Tag4::new(Expr::FLAG_SHARE, *idx).encoded_size(), |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /// Get child expressions for traversal. |
| 192 | fn get_children(expr: &Expr) -> Vec<&Arc<Expr>> { |
| 193 | match expr { |
no test coverage detected