Kagome
Polkadot Runtime Engine in C++17
trie_node.cpp
Go to the documentation of this file.
1 
7 
8 namespace kagome::storage::trie {
9 
10  int BranchNode::getType() const {
11  return static_cast<int>(value ? TrieNode::Type::BranchWithValue
13  }
14 
15  uint16_t BranchNode::childrenBitmap() const {
16  uint16_t bitmap = 0u;
17  for (auto i = 0u; i < kMaxChildren; i++) {
18  if (children.at(i)) {
19  bitmap = bitmap | 1u << i;
20  }
21  }
22  return bitmap;
23  }
24 
25  uint8_t BranchNode::childrenNum() const {
26  return std::count_if(children.begin(),
27  children.end(),
28  [](const auto &child) { return child; });
29  }
30 
31  int LeafNode::getType() const {
32  return static_cast<int>(TrieNode::Type::Leaf);
33  }
34 
36  return static_cast<int>(TrieNode::Type::BranchContainingHashes);
37  }
38 
40  uint16_t bitmap = 0u;
41  for (auto i = 0u; i < kMaxChildren; i++) {
42  if (children.at(i)) {
43  bitmap = bitmap | 1u << i;
44  }
45  }
46  return bitmap;
47  }
48 
50  return std::count_if(children.begin(),
51  children.end(),
52  [](const auto &child) { return child; });
53  }
54 
56  return static_cast<int>(TrieNode::Type::LeafContainingHashes);
57  }
58 
59 } // namespace kagome::storage::trie
uint16_t childrenBitmap() const
Definition: trie_node.cpp:15
std::array< std::shared_ptr< OpaqueTrieNode >, kMaxChildren > children
Definition: trie_node.hpp:141
static constexpr uint8_t kMaxChildren
Definition: trie_node.hpp:124
std::optional< common::Buffer > value
Definition: trie_node.hpp:120
int getType() const override
Definition: trie_node.cpp:31
int getType() const override
Definition: trie_node.cpp:10