1use crate::Nibbles;
4use alloy_primitives::map::HashMap;
5use alloy_trie::{nodes::TrieNode, TrieMask};
6
7#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
13pub struct BranchNodeMasks {
14 pub hash_mask: TrieMask,
16 pub tree_mask: TrieMask,
18}
19
20impl BranchNodeMasks {
21 pub fn from_optional(hash_mask: Option<TrieMask>, tree_mask: Option<TrieMask>) -> Option<Self> {
25 match (hash_mask, tree_mask) {
26 (Some(h), Some(t)) => Some(Self { hash_mask: h, tree_mask: t }),
27 (Some(h), None) => Some(Self { hash_mask: h, tree_mask: TrieMask::default() }),
28 (None, Some(t)) => Some(Self { hash_mask: TrieMask::default(), tree_mask: t }),
29 (None, None) => None,
30 }
31 }
32
33 pub const fn is_empty(&self) -> bool {
35 self.hash_mask.is_empty() && self.tree_mask.is_empty()
36 }
37
38 pub const fn set_child_bits(&mut self, nibble: u8, hash_mask_bit: bool, tree_mask_bit: bool) {
40 if hash_mask_bit {
41 self.hash_mask.set_bit(nibble);
42 } else {
43 self.hash_mask.unset_bit(nibble);
44 }
45 if tree_mask_bit {
46 self.tree_mask.set_bit(nibble);
47 } else {
48 self.tree_mask.unset_bit(nibble);
49 }
50 }
51}
52
53pub type BranchNodeMasksMap = HashMap<Nibbles, BranchNodeMasks>;
55
56#[derive(Debug, Clone, PartialEq, Eq)]
58pub struct ProofTrieNode {
59 pub path: Nibbles,
61 pub node: TrieNode,
63 pub masks: Option<BranchNodeMasks>,
66}
67
68impl ProofTrieNode {
69 pub fn empty() -> Self {
71 Self { path: Nibbles::default(), node: TrieNode::EmptyRoot, masks: None }
72 }
73}