/__w/smoldot/smoldot/repo/lib/src/trie/trie_structure.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Smoldot |
2 | | // Copyright (C) 2019-2022 Parity Technologies (UK) Ltd. |
3 | | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 |
4 | | |
5 | | // This program is free software: you can redistribute it and/or modify |
6 | | // it under the terms of the GNU General Public License as published by |
7 | | // the Free Software Foundation, either version 3 of the License, or |
8 | | // (at your option) any later version. |
9 | | |
10 | | // This program is distributed in the hope that it will be useful, |
11 | | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | // GNU General Public License for more details. |
14 | | |
15 | | // You should have received a copy of the GNU General Public License |
16 | | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | | |
18 | | //! Manages the structure of a trie. Allows inserting and removing nodes, but does not store any |
19 | | //! value. Only the structure is stored. |
20 | | //! |
21 | | //! See the [`TrieStructure`] struct. |
22 | | |
23 | | // TODO: the API of `TrieStructure` is rather wonky and could be simplified |
24 | | |
25 | | use super::nibble::{bytes_to_nibbles, Nibble}; |
26 | | |
27 | | use alloc::{borrow::ToOwned as _, vec, vec::Vec}; |
28 | | use core::{cmp, fmt, iter, mem, ops}; |
29 | | use either::Either; |
30 | | use slab::Slab; |
31 | | |
32 | | mod tests; |
33 | | |
34 | | /// Stores the structure of a trie, including branch nodes that have no storage value. |
35 | | /// |
36 | | /// The `TUd` parameter is a user data stored in each node. |
37 | | /// |
38 | | /// This struct doesn't represent a complete trie. It only manages the structure of the trie, and |
39 | | /// the storage values have to be maintained in parallel of this. |
40 | | #[derive(Clone)] |
41 | | pub struct TrieStructure<TUd> { |
42 | | /// List of nodes. Using a [`Slab`] guarantees that the node indices never change. |
43 | | nodes: Slab<Node<TUd>>, |
44 | | /// Index of the root node within [`TrieStructure::nodes`]. `None` if the trie is empty. |
45 | | root_index: Option<usize>, |
46 | | } |
47 | | |
48 | | /// Entry in the structure. |
49 | | #[derive(Debug, Clone)] |
50 | | struct Node<TUd> { |
51 | | /// Index of the parent within [`TrieStructure::nodes`]. `None` if this is the root. |
52 | | parent: Option<(usize, Nibble)>, |
53 | | /// Partial key of the node. Portion to add to the values in `parent` to obtain the full key. |
54 | | partial_key: Vec<Nibble>, |
55 | | /// Indices of the children within [`TrieStructure::nodes`]. |
56 | | children: [Option<usize>; 16], |
57 | | /// If true, this node is a so-called "storage node" with a storage value associated to it. If |
58 | | /// false, then it is a so-called "branch node". Branch nodes are automatically removed from |
59 | | /// the trie if their number of children is inferior to 2. |
60 | | has_storage_value: bool, |
61 | | /// User data associated to the node. |
62 | | user_data: TUd, |
63 | | } |
64 | | |
65 | | impl<TUd> TrieStructure<TUd> { |
66 | | /// Builds a new empty trie. |
67 | | /// |
68 | | /// Equivalent to calling [`TrieStructure::with_capacity`] with a capacity of 0. |
69 | | /// |
70 | | /// # Examples |
71 | | /// |
72 | | /// ``` |
73 | | /// use smoldot::trie::trie_structure; |
74 | | /// |
75 | | /// let trie = trie_structure::TrieStructure::<()>::new(); |
76 | | /// assert!(trie.is_empty()); |
77 | | /// assert_eq!(trie.capacity(), 0); |
78 | | /// ``` |
79 | 45.5k | pub fn new() -> Self { |
80 | 45.5k | TrieStructure { |
81 | 45.5k | nodes: Slab::new(), |
82 | 45.5k | root_index: None, |
83 | 45.5k | } |
84 | 45.5k | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE3newB6_ Line | Count | Source | 79 | 1.02k | pub fn new() -> Self { | 80 | 1.02k | TrieStructure { | 81 | 1.02k | nodes: Slab::new(), | 82 | 1.02k | root_index: None, | 83 | 1.02k | } | 84 | 1.02k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE3newB6_ Line | Count | Source | 79 | 11.7k | pub fn new() -> Self { | 80 | 11.7k | TrieStructure { | 81 | 11.7k | nodes: Slab::new(), | 82 | 11.7k | root_index: None, | 83 | 11.7k | } | 84 | 11.7k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE3newB6_ Line | Count | Source | 79 | 32.7k | pub fn new() -> Self { | 80 | 32.7k | TrieStructure { | 81 | 32.7k | nodes: Slab::new(), | 82 | 32.7k | root_index: None, | 83 | 32.7k | } | 84 | 32.7k | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructurepE3newB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE3newCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 79 | 2 | pub fn new() -> Self { | 80 | 2 | TrieStructure { | 81 | 2 | nodes: Slab::new(), | 82 | 2 | root_index: None, | 83 | 2 | } | 84 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE3newCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE3newCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 79 | 19 | pub fn new() -> Self { | 80 | 19 | TrieStructure { | 81 | 19 | nodes: Slab::new(), | 82 | 19 | root_index: None, | 83 | 19 | } | 84 | 19 | } |
|
85 | | |
86 | | /// Builds a new empty trie with a capacity for the given number of nodes. |
87 | | /// |
88 | | /// # Examples |
89 | | /// |
90 | | /// ``` |
91 | | /// use smoldot::trie::trie_structure; |
92 | | /// |
93 | | /// let trie = trie_structure::TrieStructure::<()>::with_capacity(12); |
94 | | /// assert!(trie.is_empty()); |
95 | | /// assert_eq!(trie.capacity(), 12); |
96 | | /// ``` |
97 | 1.50k | pub fn with_capacity(capacity: usize) -> Self { |
98 | 1.50k | TrieStructure { |
99 | 1.50k | nodes: Slab::with_capacity(capacity), |
100 | 1.50k | root_index: None, |
101 | 1.50k | } |
102 | 1.50k | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE13with_capacityB6_ Line | Count | Source | 97 | 1.50k | pub fn with_capacity(capacity: usize) -> Self { | 98 | 1.50k | TrieStructure { | 99 | 1.50k | nodes: Slab::with_capacity(capacity), | 100 | 1.50k | root_index: None, | 101 | 1.50k | } | 102 | 1.50k | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE13with_capacityB6_ |
103 | | |
104 | | /// Returns the number of nodes (storage or branch nodes) the trie can hold without |
105 | | /// reallocating. |
106 | | /// |
107 | | /// # Examples |
108 | | /// |
109 | | /// ``` |
110 | | /// use smoldot::trie::trie_structure; |
111 | | /// |
112 | | /// let trie = trie_structure::TrieStructure::<()>::with_capacity(7); |
113 | | /// assert_eq!(trie.capacity(), 7); |
114 | | /// ``` |
115 | 0 | pub fn capacity(&self) -> usize { |
116 | 0 | self.nodes.capacity() |
117 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructurepE8capacityB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructurepE8capacityB6_ |
118 | | |
119 | | /// Returns `true` if the trie doesn't contain any node. |
120 | | /// |
121 | | /// Equivalent to [`TrieStructure::len`] returning 0. |
122 | | /// |
123 | | /// # Examples |
124 | | /// |
125 | | /// ``` |
126 | | /// use smoldot::trie::{self, trie_structure}; |
127 | | /// |
128 | | /// let mut trie = trie_structure::TrieStructure::new(); |
129 | | /// assert!(trie.is_empty()); |
130 | | /// |
131 | | /// // Insert a node. |
132 | | /// trie |
133 | | /// .node(trie::bytes_to_nibbles(b"foo".iter().cloned())) |
134 | | /// .into_vacant() |
135 | | /// .unwrap() |
136 | | /// .insert_storage_value() |
137 | | /// .insert((), ()); |
138 | | /// assert!(!trie.is_empty()); |
139 | | /// |
140 | | /// // Remove the newly-inserted node. |
141 | | /// trie |
142 | | /// .node(trie::bytes_to_nibbles(b"foo".iter().cloned())) |
143 | | /// .into_occupied() |
144 | | /// .unwrap() |
145 | | /// .into_storage() |
146 | | /// .unwrap() |
147 | | /// .remove(); |
148 | | /// assert!(trie.is_empty()); |
149 | | /// ``` |
150 | 1 | pub fn is_empty(&self) -> bool { |
151 | 1 | self.nodes.is_empty() |
152 | 1 | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE8is_emptyB6_ Line | Count | Source | 150 | 1 | pub fn is_empty(&self) -> bool { | 151 | 1 | self.nodes.is_empty() | 152 | 1 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructurepE8is_emptyB6_ |
153 | | |
154 | | /// Returns the number of nodes, both branch and storage nodes, in the trie structure. |
155 | 4 | pub fn len(&self) -> usize { |
156 | 4 | self.nodes.len() |
157 | 4 | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE3lenB6_ Line | Count | Source | 155 | 4 | pub fn len(&self) -> usize { | 156 | 4 | self.nodes.len() | 157 | 4 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructurepE3lenB6_ |
158 | | |
159 | | /// Reduces the capacity of the trie as much as possible. |
160 | | /// |
161 | | /// See [`Vec::shrink_to_fit`]. |
162 | 0 | pub fn shrink_to_fit(&mut self) { |
163 | 0 | self.nodes.shrink_to_fit(); |
164 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructurepE13shrink_to_fitB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructurepE13shrink_to_fitB6_ |
165 | | |
166 | | /// Returns a list of all nodes in the structure, without any specific order. |
167 | 8.14k | pub fn iter_unordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { |
168 | 320k | self.nodes.iter().map(|(k, _)| NodeIndex(k)) _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB6_12proof_encode4NodeEE14iter_unordered0B8_ Line | Count | Source | 168 | 28.8k | self.nodes.iter().map(|(k, _)| NodeIndex(k)) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1b_NtNtB6_9trie_node17MerkleValueOutputEEE14iter_unordered0B8_ Line | Count | Source | 168 | 2.58k | self.nodes.iter().map(|(k, _)| NodeIndex(k)) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureuE14iter_unordered0B8_ Line | Count | Source | 168 | 287k | self.nodes.iter().map(|(k, _)| NodeIndex(k)) |
Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB6_12proof_encode4NodeEE14iter_unordered0B8_ _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE14iter_unordered0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 168 | 96 | self.nodes.iter().map(|(k, _)| NodeIndex(k)) |
Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE14iter_unordered0CscDgN54JpMGG_6author _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE14iter_unordered0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 168 | 912 | self.nodes.iter().map(|(k, _)| NodeIndex(k)) |
|
169 | 8.14k | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE14iter_unorderedB6_ Line | Count | Source | 167 | 1.02k | pub fn iter_unordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { | 168 | 1.02k | self.nodes.iter().map(|(k, _)| NodeIndex(k)) | 169 | 1.02k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE14iter_unorderedB6_ Line | Count | Source | 167 | 5.59k | pub fn iter_unordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { | 168 | 5.59k | self.nodes.iter().map(|(k, _)| NodeIndex(k)) | 169 | 5.59k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE14iter_unorderedB6_ Line | Count | Source | 167 | 1.50k | pub fn iter_unordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { | 168 | 1.50k | self.nodes.iter().map(|(k, _)| NodeIndex(k)) | 169 | 1.50k | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE14iter_unorderedB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE14iter_unorderedCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 167 | 2 | pub fn iter_unordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { | 168 | 2 | self.nodes.iter().map(|(k, _)| NodeIndex(k)) | 169 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE14iter_unorderedCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE14iter_unorderedCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 167 | 19 | pub fn iter_unordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { | 168 | 19 | self.nodes.iter().map(|(k, _)| NodeIndex(k)) | 169 | 19 | } |
|
170 | | |
171 | | /// Returns a list of all nodes in the structure in lexicographic order of keys. |
172 | 3.32M | pub fn iter_ordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { |
173 | 3.32M | self.all_node_lexicographic_ordered().map(NodeIndex) |
174 | 3.32M | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE12iter_orderedB6_ Line | Count | Source | 172 | 2.09M | pub fn iter_ordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { | 173 | 2.09M | self.all_node_lexicographic_ordered().map(NodeIndex) | 174 | 2.09M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE12iter_orderedB6_ Line | Count | Source | 172 | 1.09M | pub fn iter_ordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { | 173 | 1.09M | self.all_node_lexicographic_ordered().map(NodeIndex) | 174 | 1.09M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE12iter_orderedB6_ Line | Count | Source | 172 | 131k | pub fn iter_ordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { | 173 | 131k | self.all_node_lexicographic_ordered().map(NodeIndex) | 174 | 131k | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructurepE12iter_orderedB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE12iter_orderedCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 172 | 2 | pub fn iter_ordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { | 173 | 2 | self.all_node_lexicographic_ordered().map(NodeIndex) | 174 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE12iter_orderedCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE12iter_orderedCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 172 | 19 | pub fn iter_ordered(&'_ self) -> impl Iterator<Item = NodeIndex> + '_ { | 173 | 19 | self.all_node_lexicographic_ordered().map(NodeIndex) | 174 | 19 | } |
|
175 | | |
176 | | /// Returns the root node of the trie, or `None` if the trie is empty. |
177 | | /// |
178 | | /// # Examples |
179 | | /// |
180 | | /// ``` |
181 | | /// use smoldot::trie::{self, trie_structure}; |
182 | | /// |
183 | | /// let mut trie = trie_structure::TrieStructure::new(); |
184 | | /// assert!(trie.root_node().is_none()); |
185 | | /// |
186 | | /// // Insert a node. It becomes the root. |
187 | | /// trie |
188 | | /// .node(trie::bytes_to_nibbles(b"foo".iter().cloned())) |
189 | | /// .into_vacant() |
190 | | /// .unwrap() |
191 | | /// .insert_storage_value() |
192 | | /// .insert((), ()); |
193 | | /// |
194 | | /// assert!(trie.root_node().is_some()); |
195 | | /// assert!(trie.root_node().unwrap().parent().is_none()); |
196 | | /// ``` |
197 | 3.00k | pub fn root_node(&mut self) -> Option<NodeAccess<TUd>> { |
198 | 3.00k | Some(self.node_by_index_inner(self.root_index?1 ).unwrap()3.00k ) |
199 | 3.00k | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE9root_nodeB6_ Line | Count | Source | 197 | 3.00k | pub fn root_node(&mut self) -> Option<NodeAccess<TUd>> { | 198 | 3.00k | Some(self.node_by_index_inner(self.root_index?1 ).unwrap()3.00k ) | 199 | 3.00k | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE9root_nodeB6_ |
200 | | |
201 | | /// Returns the user data associated with the root node of the trie, or `None` if the trie |
202 | | /// is empty. |
203 | | // TODO: this function exists only because `root_node` mutably borrows |
204 | 35.2k | pub fn root_user_data(&self) -> Option<&TUd> { |
205 | 35.2k | Some(&self.nodes[self.root_index?2 ].user_data) |
206 | 35.2k | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE14root_user_dataB6_ Line | Count | Source | 204 | 1.50k | pub fn root_user_data(&self) -> Option<&TUd> { | 205 | 1.50k | Some(&self.nodes[self.root_index?0 ].user_data) | 206 | 1.50k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE14root_user_dataB6_ Line | Count | Source | 204 | 1.02k | pub fn root_user_data(&self) -> Option<&TUd> { | 205 | 1.02k | Some(&self.nodes[self.root_index?0 ].user_data) | 206 | 1.02k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE14root_user_dataB6_ Line | Count | Source | 204 | 32.7k | pub fn root_user_data(&self) -> Option<&TUd> { | 205 | 32.7k | Some(&self.nodes[self.root_index?2 ].user_data) | 206 | 32.7k | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE14root_user_dataB6_ |
207 | | |
208 | | /// Returns an [`Entry`] corresponding to the node whose key is the concatenation of the list |
209 | | /// of nibbles passed as parameter. |
210 | | /// |
211 | | /// # Examples |
212 | | /// |
213 | | /// ``` |
214 | | /// use smoldot::trie::{self, trie_structure}; |
215 | | /// |
216 | | /// let mut trie = trie_structure::TrieStructure::new(); |
217 | | /// |
218 | | /// let node: trie_structure::Entry<_, _> = trie |
219 | | /// .node(trie::bytes_to_nibbles(b"ful".iter().cloned())); |
220 | | /// |
221 | | /// match node { |
222 | | /// // `Occupied` is returned if a node with this key exists. |
223 | | /// trie_structure::Entry::Occupied(_) => unreachable!(), |
224 | | /// |
225 | | /// // `Vacant` is returned if no node with this key exists yet. |
226 | | /// // In this example, a node is inserted. |
227 | | /// trie_structure::Entry::Vacant(entry) => { |
228 | | /// entry.insert_storage_value().insert((), ()) |
229 | | /// }, |
230 | | /// }; |
231 | | /// |
232 | | /// // The same node can for example be queried again. |
233 | | /// // This time, it will be in the `Occupied` state. |
234 | | /// match trie.node(trie::bytes_to_nibbles(b"ful".iter().cloned())) { |
235 | | /// // `NodeAccess::Storage` is used if the node has been explicitly inserted. |
236 | | /// trie_structure::Entry::Occupied(trie_structure::NodeAccess::Storage(_)) => {}, |
237 | | /// |
238 | | /// // `Branch` would be returned if this was a branch node. See below. |
239 | | /// trie_structure::Entry::Occupied(trie_structure::NodeAccess::Branch(_)) => { |
240 | | /// unreachable!() |
241 | | /// }, |
242 | | /// trie_structure::Entry::Vacant(e) => unreachable!(), |
243 | | /// }; |
244 | | /// |
245 | | /// // In order to demonstrate branch nodes, let's insert a node at the key `fez`. |
246 | | /// trie |
247 | | /// .node(trie::bytes_to_nibbles(b"fez".iter().cloned())) |
248 | | /// .into_vacant() |
249 | | /// .unwrap() |
250 | | /// .insert_storage_value() |
251 | | /// .insert((), ()); |
252 | | /// |
253 | | /// // The trie now contains not two but three nodes. A branch node whose key is `f` has |
254 | | /// // automatically been inserted as the parent of both `ful` and `fez`. |
255 | | /// assert_eq!(trie.len(), 3); |
256 | | /// match trie.node(trie::bytes_to_nibbles(b"f".iter().cloned())) { |
257 | | /// trie_structure::Entry::Occupied(trie_structure::NodeAccess::Branch(_)) => {}, |
258 | | /// _ => unreachable!(), |
259 | | /// }; |
260 | | /// ``` |
261 | 2.16M | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> |
262 | 2.16M | where |
263 | 2.16M | TKIter: Iterator<Item = Nibble> + Clone, |
264 | 2.16M | { |
265 | 2.16M | match self.existing_node_inner(key.clone()) { |
266 | | ExistingNodeInnerResult::Found { |
267 | 331k | node_index, |
268 | 331k | has_storage_value: true, |
269 | 331k | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { |
270 | 331k | trie: self, |
271 | 331k | node_index, |
272 | 331k | })), |
273 | | ExistingNodeInnerResult::Found { |
274 | 168k | node_index, |
275 | 168k | has_storage_value: false, |
276 | 168k | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { |
277 | 168k | trie: self, |
278 | 168k | node_index, |
279 | 168k | })), |
280 | 1.66M | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { |
281 | 1.66M | trie: self, |
282 | 1.66M | key, |
283 | 1.66M | closest_ancestor: closest_ancestor.map(|(i, _)| i1.58M ), _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE4nodeINtNtNtNtB1f_4iter8adapters6copied6CopiedINtNtNtB1f_5slice4iter4IterNtNtB7_6nibble6NibbleEEE0B9_ Line | Count | Source | 283 | 25.3k | closest_ancestor: closest_ancestor.map(|(i, _)| i), |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEE4nodeINtNtB7_6nibble14BytesToNibblesINtNtNtNtB1g_4iter8adapters6copied6CopiedINtNtNtB1g_5slice4iter4IterhEEEE0B9_ Line | Count | Source | 283 | 1.49k | closest_ancestor: closest_ancestor.map(|(i, _)| i), |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEE4nodeINtNtB1R_9into_iter8IntoIterNtNtB7_6nibble6NibbleEE0B9_ Line | Count | Source | 283 | 299k | closest_ancestor: closest_ancestor.map(|(i, _)| i), |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEE4nodeINtNtB7_6nibble14BytesToNibblesINtNtNtNtB1g_4iter8adapters6copied6CopiedINtNtNtB1g_5slice4iter4IterhEEEE0B9_ Line | Count | Source | 283 | 283k | closest_ancestor: closest_ancestor.map(|(i, _)| i), |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE4nodeINtNtB7_6nibble14BytesToNibblesINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1V_5slice4iter4IterhEEEE0B9_ Line | Count | Source | 283 | 3.18k | closest_ancestor: closest_ancestor.map(|(i, _)| i), |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE4nodeINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB7_6nibble6NibbleEE0B9_ Line | Count | Source | 283 | 731k | closest_ancestor: closest_ancestor.map(|(i, _)| i), |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE4nodeINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1q_5slice4iter4IterNtNtB7_6nibble6NibbleEEE0B9_ Line | Count | Source | 283 | 14 | closest_ancestor: closest_ancestor.map(|(i, _)| i), |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE4nodeINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1q_5slice4iter4IterNtNtB7_6nibble6NibbleEEE0B9_ Line | Count | Source | 283 | 240k | closest_ancestor: closest_ancestor.map(|(i, _)| i), |
Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE4nodeINtNtNtNtB1g_4iter8adapters6copied6CopiedINtNtNtB1g_5slice4iter4IterNtNtB7_6nibble6NibbleEEE0B9_ _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1d_NtNtB7_9trie_node17MerkleValueOutputEEE4nodeINtNtB7_6nibble14BytesToNibblesINtNtNtNtB1h_4iter8adapters6copied6CopiedINtNtNtB1h_5slice4iter4IterhEEEE0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 283 | 66 | closest_ancestor: closest_ancestor.map(|(i, _)| i), |
Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1d_NtNtB7_9trie_node17MerkleValueOutputEEE4nodeINtNtB7_6nibble14BytesToNibblesINtNtNtNtB1h_4iter8adapters6copied6CopiedINtNtNtB1h_5slice4iter4IterhEEEE0CscDgN54JpMGG_6author _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1d_NtNtB7_9trie_node17MerkleValueOutputEEE4nodeINtNtB7_6nibble14BytesToNibblesINtNtNtNtB1h_4iter8adapters6copied6CopiedINtNtNtB1h_5slice4iter4IterhEEEE0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 283 | 627 | closest_ancestor: closest_ancestor.map(|(i, _)| i), |
|
284 | 1.66M | }), |
285 | | } |
286 | 2.16M | } _RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB5_12proof_encode4NodeEE4nodeINtNtNtNtB1d_4iter8adapters6copied6CopiedINtNtNtB1d_5slice4iter4IterNtNtB5_6nibble6NibbleEEEB7_ Line | Count | Source | 261 | 56.1k | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> | 262 | 56.1k | where | 263 | 56.1k | TKIter: Iterator<Item = Nibble> + Clone, | 264 | 56.1k | { | 265 | 56.1k | match self.existing_node_inner(key.clone()) { | 266 | | ExistingNodeInnerResult::Found { | 267 | 27.3k | node_index, | 268 | 27.3k | has_storage_value: true, | 269 | 27.3k | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { | 270 | 27.3k | trie: self, | 271 | 27.3k | node_index, | 272 | 27.3k | })), | 273 | | ExistingNodeInnerResult::Found { | 274 | 0 | node_index, | 275 | 0 | has_storage_value: false, | 276 | 0 | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { | 277 | 0 | trie: self, | 278 | 0 | node_index, | 279 | 0 | })), | 280 | 28.8k | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { | 281 | 28.8k | trie: self, | 282 | 28.8k | key, | 283 | 28.8k | closest_ancestor: closest_ancestor.map(|(i, _)| i), | 284 | 28.8k | }), | 285 | | } | 286 | 56.1k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1a_NtNtB5_9trie_node17MerkleValueOutputEEE4nodeINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1e_4iter8adapters6copied6CopiedINtNtNtB1e_5slice4iter4IterhEEEEB7_ Line | Count | Source | 261 | 3.01k | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> | 262 | 3.01k | where | 263 | 3.01k | TKIter: Iterator<Item = Nibble> + Clone, | 264 | 3.01k | { | 265 | 3.01k | match self.existing_node_inner(key.clone()) { | 266 | | ExistingNodeInnerResult::Found { | 267 | 496 | node_index, | 268 | 496 | has_storage_value: true, | 269 | 496 | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { | 270 | 496 | trie: self, | 271 | 496 | node_index, | 272 | 496 | })), | 273 | | ExistingNodeInnerResult::Found { | 274 | 0 | node_index, | 275 | 0 | has_storage_value: false, | 276 | 0 | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { | 277 | 0 | trie: self, | 278 | 0 | node_index, | 279 | 0 | })), | 280 | 2.51k | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { | 281 | 2.51k | trie: self, | 282 | 2.51k | key, | 283 | 2.51k | closest_ancestor: closest_ancestor.map(|(i, _)| i), | 284 | 2.51k | }), | 285 | | } | 286 | 3.01k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB5_16TrieEntryVersionEEIB1a_NtNtB5_9trie_node17MerkleValueOutputEEE4nodeINtNtB1P_9into_iter8IntoIterNtNtB5_6nibble6NibbleEEB7_ Line | Count | Source | 261 | 366k | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> | 262 | 366k | where | 263 | 366k | TKIter: Iterator<Item = Nibble> + Clone, | 264 | 366k | { | 265 | 366k | match self.existing_node_inner(key.clone()) { | 266 | | ExistingNodeInnerResult::Found { | 267 | 65.2k | node_index, | 268 | 65.2k | has_storage_value: true, | 269 | 65.2k | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { | 270 | 65.2k | trie: self, | 271 | 65.2k | node_index, | 272 | 65.2k | })), | 273 | | ExistingNodeInnerResult::Found { | 274 | 1.45k | node_index, | 275 | 1.45k | has_storage_value: false, | 276 | 1.45k | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { | 277 | 1.45k | trie: self, | 278 | 1.45k | node_index, | 279 | 1.45k | })), | 280 | 299k | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { | 281 | 299k | trie: self, | 282 | 299k | key, | 283 | 299k | closest_ancestor: closest_ancestor.map(|(i, _)| i), | 284 | 299k | }), | 285 | | } | 286 | 366k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB5_16TrieEntryVersionEEIB1a_NtNtB5_9trie_node17MerkleValueOutputEEE4nodeINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1e_4iter8adapters6copied6CopiedINtNtNtB1e_5slice4iter4IterhEEEEB7_ Line | Count | Source | 261 | 589k | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> | 262 | 589k | where | 263 | 589k | TKIter: Iterator<Item = Nibble> + Clone, | 264 | 589k | { | 265 | 589k | match self.existing_node_inner(key.clone()) { | 266 | | ExistingNodeInnerResult::Found { | 267 | 187k | node_index, | 268 | 187k | has_storage_value: true, | 269 | 187k | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { | 270 | 187k | trie: self, | 271 | 187k | node_index, | 272 | 187k | })), | 273 | | ExistingNodeInnerResult::Found { | 274 | 66.5k | node_index, | 275 | 66.5k | has_storage_value: false, | 276 | 66.5k | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { | 277 | 66.5k | trie: self, | 278 | 66.5k | node_index, | 279 | 66.5k | })), | 280 | 335k | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { | 281 | 335k | trie: self, | 282 | 335k | key, | 283 | 335k | closest_ancestor: closest_ancestor.map(|(i, _)| i), | 284 | 335k | }), | 285 | | } | 286 | 589k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE4nodeINtNtB5_6nibble14BytesToNibblesINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1T_5slice4iter4IterhEEEEB7_ Line | Count | Source | 261 | 6.20k | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> | 262 | 6.20k | where | 263 | 6.20k | TKIter: Iterator<Item = Nibble> + Clone, | 264 | 6.20k | { | 265 | 6.20k | match self.existing_node_inner(key.clone()) { | 266 | | ExistingNodeInnerResult::Found { | 267 | 972 | node_index, | 268 | 972 | has_storage_value: true, | 269 | 972 | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { | 270 | 972 | trie: self, | 271 | 972 | node_index, | 272 | 972 | })), | 273 | | ExistingNodeInnerResult::Found { | 274 | 0 | node_index, | 275 | 0 | has_storage_value: false, | 276 | 0 | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { | 277 | 0 | trie: self, | 278 | 0 | node_index, | 279 | 0 | })), | 280 | 5.23k | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { | 281 | 5.23k | trie: self, | 282 | 5.23k | key, | 283 | 5.23k | closest_ancestor: closest_ancestor.map(|(i, _)| i), | 284 | 5.23k | }), | 285 | | } | 286 | 6.20k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE4nodeINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB5_6nibble6NibbleEEB7_ Line | Count | Source | 261 | 896k | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> | 262 | 896k | where | 263 | 896k | TKIter: Iterator<Item = Nibble> + Clone, | 264 | 896k | { | 265 | 896k | match self.existing_node_inner(key.clone()) { | 266 | | ExistingNodeInnerResult::Found { | 267 | 50.1k | node_index, | 268 | 50.1k | has_storage_value: true, | 269 | 50.1k | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { | 270 | 50.1k | trie: self, | 271 | 50.1k | node_index, | 272 | 50.1k | })), | 273 | | ExistingNodeInnerResult::Found { | 274 | 99.9k | node_index, | 275 | 99.9k | has_storage_value: false, | 276 | 99.9k | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { | 277 | 99.9k | trie: self, | 278 | 99.9k | node_index, | 279 | 99.9k | })), | 280 | 746k | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { | 281 | 746k | trie: self, | 282 | 746k | key, | 283 | 746k | closest_ancestor: closest_ancestor.map(|(i, _)| i), | 284 | 746k | }), | 285 | | } | 286 | 896k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE4nodeINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1o_5slice4iter4IterNtNtB5_6nibble6NibbleEEEB7_ Line | Count | Source | 261 | 36 | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> | 262 | 36 | where | 263 | 36 | TKIter: Iterator<Item = Nibble> + Clone, | 264 | 36 | { | 265 | 36 | match self.existing_node_inner(key.clone()) { | 266 | | ExistingNodeInnerResult::Found { | 267 | 5 | node_index, | 268 | 5 | has_storage_value: true, | 269 | 5 | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { | 270 | 5 | trie: self, | 271 | 5 | node_index, | 272 | 5 | })), | 273 | | ExistingNodeInnerResult::Found { | 274 | 1 | node_index, | 275 | 1 | has_storage_value: false, | 276 | 1 | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { | 277 | 1 | trie: self, | 278 | 1 | node_index, | 279 | 1 | })), | 280 | 30 | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { | 281 | 30 | trie: self, | 282 | 30 | key, | 283 | 30 | closest_ancestor: closest_ancestor.map(|(i, _)| i), | 284 | 30 | }), | 285 | | } | 286 | 36 | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE4nodeINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1o_5slice4iter4IterNtNtB5_6nibble6NibbleEEEB7_ Line | Count | Source | 261 | 245k | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> | 262 | 245k | where | 263 | 245k | TKIter: Iterator<Item = Nibble> + Clone, | 264 | 245k | { | 265 | 245k | match self.existing_node_inner(key.clone()) { | 266 | | ExistingNodeInnerResult::Found { | 267 | 0 | node_index, | 268 | 0 | has_storage_value: true, | 269 | 0 | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { | 270 | 0 | trie: self, | 271 | 0 | node_index, | 272 | 0 | })), | 273 | | ExistingNodeInnerResult::Found { | 274 | 0 | node_index, | 275 | 0 | has_storage_value: false, | 276 | 0 | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { | 277 | 0 | trie: self, | 278 | 0 | node_index, | 279 | 0 | })), | 280 | 245k | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { | 281 | 245k | trie: self, | 282 | 245k | key, | 283 | 245k | closest_ancestor: closest_ancestor.map(|(i, _)| i), | 284 | 245k | }), | 285 | | } | 286 | 245k | } |
Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB5_12proof_encode4NodeEE4nodeINtNtNtNtB1e_4iter8adapters6copied6CopiedINtNtNtB1e_5slice4iter4IterNtNtB5_6nibble6NibbleEEEB7_ _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1b_NtNtB5_9trie_node17MerkleValueOutputEEE4nodeINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1f_4iter8adapters6copied6CopiedINtNtNtB1f_5slice4iter4IterhEEEECsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 261 | 70 | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> | 262 | 70 | where | 263 | 70 | TKIter: Iterator<Item = Nibble> + Clone, | 264 | 70 | { | 265 | 70 | match self.existing_node_inner(key.clone()) { | 266 | | ExistingNodeInnerResult::Found { | 267 | 0 | node_index, | 268 | 0 | has_storage_value: true, | 269 | 0 | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { | 270 | 0 | trie: self, | 271 | 0 | node_index, | 272 | 0 | })), | 273 | | ExistingNodeInnerResult::Found { | 274 | 0 | node_index, | 275 | 0 | has_storage_value: false, | 276 | 0 | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { | 277 | 0 | trie: self, | 278 | 0 | node_index, | 279 | 0 | })), | 280 | 70 | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { | 281 | 70 | trie: self, | 282 | 70 | key, | 283 | 70 | closest_ancestor: closest_ancestor.map(|(i, _)| i), | 284 | 70 | }), | 285 | | } | 286 | 70 | } |
Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1b_NtNtB5_9trie_node17MerkleValueOutputEEE4nodeINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1f_4iter8adapters6copied6CopiedINtNtNtB1f_5slice4iter4IterhEEEECscDgN54JpMGG_6author _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1b_NtNtB5_9trie_node17MerkleValueOutputEEE4nodeINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1f_4iter8adapters6copied6CopiedINtNtNtB1f_5slice4iter4IterhEEEECsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 261 | 665 | pub fn node<TKIter>(&mut self, key: TKIter) -> Entry<TUd, TKIter> | 262 | 665 | where | 263 | 665 | TKIter: Iterator<Item = Nibble> + Clone, | 264 | 665 | { | 265 | 665 | match self.existing_node_inner(key.clone()) { | 266 | | ExistingNodeInnerResult::Found { | 267 | 0 | node_index, | 268 | 0 | has_storage_value: true, | 269 | 0 | } => Entry::Occupied(NodeAccess::Storage(StorageNodeAccess { | 270 | 0 | trie: self, | 271 | 0 | node_index, | 272 | 0 | })), | 273 | | ExistingNodeInnerResult::Found { | 274 | 0 | node_index, | 275 | 0 | has_storage_value: false, | 276 | 0 | } => Entry::Occupied(NodeAccess::Branch(BranchNodeAccess { | 277 | 0 | trie: self, | 278 | 0 | node_index, | 279 | 0 | })), | 280 | 665 | ExistingNodeInnerResult::NotFound { closest_ancestor } => Entry::Vacant(Vacant { | 281 | 665 | trie: self, | 282 | 665 | key, | 283 | 665 | closest_ancestor: closest_ancestor.map(|(i, _)| i), | 284 | 665 | }), | 285 | | } | 286 | 665 | } |
|
287 | | |
288 | | /// Returns the [`NodeIndex`] of the node with the given full key, if any is found. |
289 | 1.04M | pub fn node_by_full_key<TKIter>(&self, key: TKIter) -> Option<NodeIndex> |
290 | 1.04M | where |
291 | 1.04M | TKIter: Iterator<Item = Nibble> + Clone, |
292 | 1.04M | { |
293 | 1.04M | match self.existing_node_inner(key) { |
294 | 209k | ExistingNodeInnerResult::Found { node_index, .. } => Some(NodeIndex(node_index)), |
295 | 838k | ExistingNodeInnerResult::NotFound { .. } => None, |
296 | | } |
297 | 1.04M | } _RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1a_NtNtB5_9trie_node17MerkleValueOutputEEE16node_by_full_keyINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1e_4iter8adapters6copied6CopiedINtNtNtB1e_5slice4iter4IterhEEEEB7_ Line | Count | Source | 289 | 1.04M | pub fn node_by_full_key<TKIter>(&self, key: TKIter) -> Option<NodeIndex> | 290 | 1.04M | where | 291 | 1.04M | TKIter: Iterator<Item = Nibble> + Clone, | 292 | 1.04M | { | 293 | 1.04M | match self.existing_node_inner(key) { | 294 | 209k | ExistingNodeInnerResult::Found { node_index, .. } => Some(NodeIndex(node_index)), | 295 | 838k | ExistingNodeInnerResult::NotFound { .. } => None, | 296 | | } | 297 | 1.04M | } |
Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructurepE16node_by_full_keypEB7_ |
298 | | |
299 | | /// Returns `true` if the node with the given index is a storage node. Returns `false` if it |
300 | | /// is a branch node. |
301 | | /// |
302 | | /// # Panic |
303 | | /// |
304 | | /// Panics if the [`NodeIndex`] is invalid. |
305 | | /// |
306 | 2.61M | pub fn is_storage(&self, node: NodeIndex) -> bool { |
307 | 2.61M | self.nodes[node.0].has_storage_value |
308 | 2.61M | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE10is_storageB6_ Line | Count | Source | 306 | 2.61M | pub fn is_storage(&self, node: NodeIndex) -> bool { | 307 | 2.61M | self.nodes[node.0].has_storage_value | 308 | 2.61M | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructurepE10is_storageB6_ |
309 | | |
310 | | /// Returns the node with the given key, or `None` if no such node exists. |
311 | | /// |
312 | | /// This method is a shortcut for calling [`TrieStructure::node`] followed with |
313 | | /// [`Entry::into_occupied`]. |
314 | 0 | pub fn existing_node( |
315 | 0 | &mut self, |
316 | 0 | key: impl Iterator<Item = Nibble> + Clone, |
317 | 0 | ) -> Option<NodeAccess<TUd>> { |
318 | | if let ExistingNodeInnerResult::Found { |
319 | 0 | node_index, |
320 | 0 | has_storage_value, |
321 | 0 | } = self.existing_node_inner(key) |
322 | | { |
323 | 0 | Some(if has_storage_value { |
324 | 0 | NodeAccess::Storage(StorageNodeAccess { |
325 | 0 | trie: self, |
326 | 0 | node_index, |
327 | 0 | }) |
328 | | } else { |
329 | 0 | NodeAccess::Branch(BranchNodeAccess { |
330 | 0 | trie: self, |
331 | 0 | node_index, |
332 | 0 | }) |
333 | | }) |
334 | | } else { |
335 | 0 | None |
336 | | } |
337 | 0 | } Unexecuted instantiation: _RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructurepE13existing_nodepEB7_ Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructurepE13existing_nodepEB7_ |
338 | | |
339 | | /// Inner implementation of [`TrieStructure::existing_node`]. Traverses the tree, trying to |
340 | | /// find a node whose key is `key`. |
341 | 3.22M | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( |
342 | 3.22M | &self, |
343 | 3.22M | mut key: I, |
344 | 3.22M | ) -> ExistingNodeInnerResult<I> { |
345 | 3.22M | let mut current_index3.16M = match self.root_index { |
346 | 3.16M | Some(ri) => ri, |
347 | | None => { |
348 | 53.7k | return ExistingNodeInnerResult::NotFound { |
349 | 53.7k | closest_ancestor: None, |
350 | 53.7k | } |
351 | | } |
352 | | }; |
353 | 3.16M | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); |
354 | | |
355 | 3.16M | let mut closest_ancestor = None; |
356 | | |
357 | 6.03M | loop { |
358 | 6.03M | let current = self.nodes.get(current_index).unwrap(); |
359 | | |
360 | | // First, we must remove `current`'s partial key from `key`, making sure that they |
361 | | // match. |
362 | 6.03M | for nibble2.14M in current.partial_key.iter().cloned() { |
363 | 2.14M | if key.next() != Some(nibble) { |
364 | 450k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; |
365 | 1.69M | } |
366 | | } |
367 | | |
368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches |
369 | | // `current`. |
370 | 5.58M | closest_ancestor = Some((current_index, key.clone())); |
371 | | |
372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. |
373 | 5.58M | let child_index4.86M = match key.next() { |
374 | 4.86M | Some(n) => n, |
375 | | None => { |
376 | 716k | return ExistingNodeInnerResult::Found { |
377 | 716k | node_index: current_index, |
378 | 716k | has_storage_value: current.has_storage_value, |
379 | 716k | } |
380 | | } |
381 | | }; |
382 | | |
383 | 4.86M | if let Some(next_index2.86M ) = current.children[usize::from(u8::from(child_index))] { |
384 | 2.86M | current_index = next_index; |
385 | 2.86M | } else { |
386 | 1.99M | return ExistingNodeInnerResult::NotFound { closest_ancestor }; |
387 | | } |
388 | | } |
389 | 3.22M | } _RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB5_12proof_encode4NodeEE19existing_node_innerINtNtNtNtB1d_4iter8adapters6copied6CopiedINtNtNtB1d_5slice4iter4IterNtNtB5_6nibble6NibbleEEEB7_ Line | Count | Source | 341 | 56.1k | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( | 342 | 56.1k | &self, | 343 | 56.1k | mut key: I, | 344 | 56.1k | ) -> ExistingNodeInnerResult<I> { | 345 | 56.1k | let mut current_index54.6k = match self.root_index { | 346 | 54.6k | Some(ri) => ri, | 347 | | None => { | 348 | 1.50k | return ExistingNodeInnerResult::NotFound { | 349 | 1.50k | closest_ancestor: None, | 350 | 1.50k | } | 351 | | } | 352 | | }; | 353 | 54.6k | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); | 354 | | | 355 | 54.6k | let mut closest_ancestor = None; | 356 | | | 357 | 83.2k | loop { | 358 | 83.2k | let current = self.nodes.get(current_index).unwrap(); | 359 | | | 360 | | // First, we must remove `current`'s partial key from `key`, making sure that they | 361 | | // match. | 362 | 83.2k | for nibble9.05k in current.partial_key.iter().cloned() { | 363 | 9.05k | if key.next() != Some(nibble) { | 364 | 7.15k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 365 | 1.90k | } | 366 | | } | 367 | | | 368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches | 369 | | // `current`. | 370 | 76.1k | closest_ancestor = Some((current_index, key.clone())); | 371 | | | 372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. | 373 | 76.1k | let child_index48.7k = match key.next() { | 374 | 48.7k | Some(n) => n, | 375 | | None => { | 376 | 27.3k | return ExistingNodeInnerResult::Found { | 377 | 27.3k | node_index: current_index, | 378 | 27.3k | has_storage_value: current.has_storage_value, | 379 | 27.3k | } | 380 | | } | 381 | | }; | 382 | | | 383 | 48.7k | if let Some(next_index28.6k ) = current.children[usize::from(u8::from(child_index))] { | 384 | 28.6k | current_index = next_index; | 385 | 28.6k | } else { | 386 | 20.1k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 387 | | } | 388 | | } | 389 | 56.1k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1a_NtNtB5_9trie_node17MerkleValueOutputEEE19existing_node_innerINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1e_4iter8adapters6copied6CopiedINtNtNtB1e_5slice4iter4IterhEEEEB7_ Line | Count | Source | 341 | 1.05M | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( | 342 | 1.05M | &self, | 343 | 1.05M | mut key: I, | 344 | 1.05M | ) -> ExistingNodeInnerResult<I> { | 345 | 1.05M | let mut current_index1.05M = match self.root_index { | 346 | 1.05M | Some(ri) => ri, | 347 | | None => { | 348 | 1.02k | return ExistingNodeInnerResult::NotFound { | 349 | 1.02k | closest_ancestor: None, | 350 | 1.02k | } | 351 | | } | 352 | | }; | 353 | 1.05M | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); | 354 | | | 355 | 1.05M | let mut closest_ancestor = None; | 356 | | | 357 | 1.12M | loop { | 358 | 1.12M | let current = self.nodes.get(current_index).unwrap(); | 359 | | | 360 | | // First, we must remove `current`'s partial key from `key`, making sure that they | 361 | | // match. | 362 | 1.12M | for nibble72.6k in current.partial_key.iter().cloned() { | 363 | 72.6k | if key.next() != Some(nibble) { | 364 | 68.1k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 365 | 4.47k | } | 366 | | } | 367 | | | 368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches | 369 | | // `current`. | 370 | 1.05M | closest_ancestor = Some((current_index, key.clone())); | 371 | | | 372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. | 373 | 1.05M | let child_index845k = match key.next() { | 374 | 845k | Some(n) => n, | 375 | | None => { | 376 | 210k | return ExistingNodeInnerResult::Found { | 377 | 210k | node_index: current_index, | 378 | 210k | has_storage_value: current.has_storage_value, | 379 | 210k | } | 380 | | } | 381 | | }; | 382 | | | 383 | 845k | if let Some(next_index73.2k ) = current.children[usize::from(u8::from(child_index))] { | 384 | 73.2k | current_index = next_index; | 385 | 73.2k | } else { | 386 | 771k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 387 | | } | 388 | | } | 389 | 1.05M | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB5_16TrieEntryVersionEEIB1a_NtNtB5_9trie_node17MerkleValueOutputEEE19existing_node_innerINtNtB1P_9into_iter8IntoIterNtNtB5_6nibble6NibbleEEB7_ Line | Count | Source | 341 | 366k | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( | 342 | 366k | &self, | 343 | 366k | mut key: I, | 344 | 366k | ) -> ExistingNodeInnerResult<I> { | 345 | 366k | let mut current_index = match self.root_index { | 346 | 366k | Some(ri) => ri, | 347 | | None => { | 348 | 0 | return ExistingNodeInnerResult::NotFound { | 349 | 0 | closest_ancestor: None, | 350 | 0 | } | 351 | | } | 352 | | }; | 353 | 366k | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); | 354 | | | 355 | 366k | let mut closest_ancestor = None; | 356 | | | 357 | 439k | loop { | 358 | 439k | let current = self.nodes.get(current_index).unwrap(); | 359 | | | 360 | | // First, we must remove `current`'s partial key from `key`, making sure that they | 361 | | // match. | 362 | 439k | for nibble135k in current.partial_key.iter().cloned() { | 363 | 135k | if key.next() != Some(nibble) { | 364 | 37.2k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 365 | 98.0k | } | 366 | | } | 367 | | | 368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches | 369 | | // `current`. | 370 | 402k | closest_ancestor = Some((current_index, key.clone())); | 371 | | | 372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. | 373 | 402k | let child_index336k = match key.next() { | 374 | 336k | Some(n) => n, | 375 | | None => { | 376 | 66.6k | return ExistingNodeInnerResult::Found { | 377 | 66.6k | node_index: current_index, | 378 | 66.6k | has_storage_value: current.has_storage_value, | 379 | 66.6k | } | 380 | | } | 381 | | }; | 382 | | | 383 | 336k | if let Some(next_index73.9k ) = current.children[usize::from(u8::from(child_index))] { | 384 | 73.9k | current_index = next_index; | 385 | 73.9k | } else { | 386 | 262k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 387 | | } | 388 | | } | 389 | 366k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB5_16TrieEntryVersionEEIB1a_NtNtB5_9trie_node17MerkleValueOutputEEE19existing_node_innerINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1e_4iter8adapters6copied6CopiedINtNtNtB1e_5slice4iter4IterhEEEEB7_ Line | Count | Source | 341 | 589k | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( | 342 | 589k | &self, | 343 | 589k | mut key: I, | 344 | 589k | ) -> ExistingNodeInnerResult<I> { | 345 | 589k | let mut current_index550k = match self.root_index { | 346 | 550k | Some(ri) => ri, | 347 | | None => { | 348 | 38.7k | return ExistingNodeInnerResult::NotFound { | 349 | 38.7k | closest_ancestor: None, | 350 | 38.7k | } | 351 | | } | 352 | | }; | 353 | 550k | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); | 354 | | | 355 | 550k | let mut closest_ancestor = None; | 356 | | | 357 | 620k | loop { | 358 | 620k | let current = self.nodes.get(current_index).unwrap(); | 359 | | | 360 | | // First, we must remove `current`'s partial key from `key`, making sure that they | 361 | | // match. | 362 | 620k | for nibble74.5k in current.partial_key.iter().cloned() { | 363 | 74.5k | if key.next() != Some(nibble) { | 364 | 70.3k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 365 | 4.17k | } | 366 | | } | 367 | | | 368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches | 369 | | // `current`. | 370 | 550k | closest_ancestor = Some((current_index, key.clone())); | 371 | | | 372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. | 373 | 550k | let child_index295k = match key.next() { | 374 | 295k | Some(n) => n, | 375 | | None => { | 376 | 254k | return ExistingNodeInnerResult::Found { | 377 | 254k | node_index: current_index, | 378 | 254k | has_storage_value: current.has_storage_value, | 379 | 254k | } | 380 | | } | 381 | | }; | 382 | | | 383 | 295k | if let Some(next_index70.1k ) = current.children[usize::from(u8::from(child_index))] { | 384 | 70.1k | current_index = next_index; | 385 | 70.1k | } else { | 386 | 225k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 387 | | } | 388 | | } | 389 | 589k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE19existing_node_innerINtNtB5_6nibble14BytesToNibblesINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB29_5slice4iter4IterhEEEEB7_ Line | Count | Source | 341 | 6.20k | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( | 342 | 6.20k | &self, | 343 | 6.20k | mut key: I, | 344 | 6.20k | ) -> ExistingNodeInnerResult<I> { | 345 | 6.20k | let mut current_index4.15k = match self.root_index { | 346 | 4.15k | Some(ri) => ri, | 347 | | None => { | 348 | 2.04k | return ExistingNodeInnerResult::NotFound { | 349 | 2.04k | closest_ancestor: None, | 350 | 2.04k | } | 351 | | } | 352 | | }; | 353 | 4.15k | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); | 354 | | | 355 | 4.15k | let mut closest_ancestor = None; | 356 | | | 357 | 4.30k | loop { | 358 | 4.30k | let current = self.nodes.get(current_index).unwrap(); | 359 | | | 360 | | // First, we must remove `current`'s partial key from `key`, making sure that they | 361 | | // match. | 362 | 4.30k | for nibble156 in current.partial_key.iter().cloned() { | 363 | 156 | if key.next() != Some(nibble) { | 364 | 147 | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 365 | 9 | } | 366 | | } | 367 | | | 368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches | 369 | | // `current`. | 370 | 4.16k | closest_ancestor = Some((current_index, key.clone())); | 371 | | | 372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. | 373 | 4.16k | let child_index3.19k = match key.next() { | 374 | 3.19k | Some(n) => n, | 375 | | None => { | 376 | 972 | return ExistingNodeInnerResult::Found { | 377 | 972 | node_index: current_index, | 378 | 972 | has_storage_value: current.has_storage_value, | 379 | 972 | } | 380 | | } | 381 | | }; | 382 | | | 383 | 3.19k | if let Some(next_index154 ) = current.children[usize::from(u8::from(child_index))] { | 384 | 154 | current_index = next_index; | 385 | 154 | } else { | 386 | 3.03k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 387 | | } | 388 | | } | 389 | 6.20k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE19existing_node_innerINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB5_6nibble6NibbleEEB7_ Line | Count | Source | 341 | 904k | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( | 342 | 904k | &self, | 343 | 904k | mut key: I, | 344 | 904k | ) -> ExistingNodeInnerResult<I> { | 345 | 904k | let mut current_index898k = match self.root_index { | 346 | 898k | Some(ri) => ri, | 347 | | None => { | 348 | 6.24k | return ExistingNodeInnerResult::NotFound { | 349 | 6.24k | closest_ancestor: None, | 350 | 6.24k | } | 351 | | } | 352 | | }; | 353 | 898k | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); | 354 | | | 355 | 898k | let mut closest_ancestor = None; | 356 | | | 357 | 3.10M | loop { | 358 | 3.10M | let current = self.nodes.get(current_index).unwrap(); | 359 | | | 360 | | // First, we must remove `current`'s partial key from `key`, making sure that they | 361 | | // match. | 362 | 3.10M | for nibble1.56M in current.partial_key.iter().cloned() { | 363 | 1.56M | if key.next() != Some(nibble) { | 364 | 253k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 365 | 1.31M | } | 366 | | } | 367 | | | 368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches | 369 | | // `current`. | 370 | 2.84M | closest_ancestor = Some((current_index, key.clone())); | 371 | | | 372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. | 373 | 2.84M | let child_index2.69M = match key.next() { | 374 | 2.69M | Some(n) => n, | 375 | | None => { | 376 | 156k | return ExistingNodeInnerResult::Found { | 377 | 156k | node_index: current_index, | 378 | 156k | has_storage_value: current.has_storage_value, | 379 | 156k | } | 380 | | } | 381 | | }; | 382 | | | 383 | 2.69M | if let Some(next_index2.20M ) = current.children[usize::from(u8::from(child_index))] { | 384 | 2.20M | current_index = next_index; | 385 | 2.20M | } else { | 386 | 487k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 387 | | } | 388 | | } | 389 | 904k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE19existing_node_innerINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1E_5slice4iter4IterNtNtB5_6nibble6NibbleEEEB7_ Line | Count | Source | 341 | 41 | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( | 342 | 41 | &self, | 343 | 41 | mut key: I, | 344 | 41 | ) -> ExistingNodeInnerResult<I> { | 345 | 41 | let mut current_index30 = match self.root_index { | 346 | 30 | Some(ri) => ri, | 347 | | None => { | 348 | 11 | return ExistingNodeInnerResult::NotFound { | 349 | 11 | closest_ancestor: None, | 350 | 11 | } | 351 | | } | 352 | | }; | 353 | 30 | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); | 354 | | | 355 | 30 | let mut closest_ancestor = None; | 356 | | | 357 | 42 | loop { | 358 | 42 | let current = self.nodes.get(current_index).unwrap(); | 359 | | | 360 | | // First, we must remove `current`'s partial key from `key`, making sure that they | 361 | | // match. | 362 | 68 | for nibble in current.partial_key.iter().cloned()42 { | 363 | 68 | if key.next() != Some(nibble) { | 364 | 10 | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 365 | 58 | } | 366 | | } | 367 | | | 368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches | 369 | | // `current`. | 370 | 32 | closest_ancestor = Some((current_index, key.clone())); | 371 | | | 372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. | 373 | 32 | let child_index23 = match key.next() { | 374 | 23 | Some(n) => n, | 375 | | None => { | 376 | 9 | return ExistingNodeInnerResult::Found { | 377 | 9 | node_index: current_index, | 378 | 9 | has_storage_value: current.has_storage_value, | 379 | 9 | } | 380 | | } | 381 | | }; | 382 | | | 383 | 23 | if let Some(next_index12 ) = current.children[usize::from(u8::from(child_index))] { | 384 | 12 | current_index = next_index; | 385 | 12 | } else { | 386 | 11 | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 387 | | } | 388 | | } | 389 | 41 | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE19existing_node_innerINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1E_5slice4iter4IterNtNtB5_6nibble6NibbleEEEB7_ Line | Count | Source | 341 | 245k | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( | 342 | 245k | &self, | 343 | 245k | mut key: I, | 344 | 245k | ) -> ExistingNodeInnerResult<I> { | 345 | 245k | let mut current_index241k = match self.root_index { | 346 | 241k | Some(ri) => ri, | 347 | | None => { | 348 | 4.09k | return ExistingNodeInnerResult::NotFound { | 349 | 4.09k | closest_ancestor: None, | 350 | 4.09k | } | 351 | | } | 352 | | }; | 353 | 241k | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); | 354 | | | 355 | 241k | let mut closest_ancestor = None; | 356 | | | 357 | 655k | loop { | 358 | 655k | let current = self.nodes.get(current_index).unwrap(); | 359 | | | 360 | | // First, we must remove `current`'s partial key from `key`, making sure that they | 361 | | // match. | 362 | 655k | for nibble261k in current.partial_key.iter().cloned() { | 363 | 261k | if key.next() != Some(nibble) { | 364 | 13.5k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 365 | 248k | } | 366 | | } | 367 | | | 368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches | 369 | | // `current`. | 370 | 642k | closest_ancestor = Some((current_index, key.clone())); | 371 | | | 372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. | 373 | 642k | let child_index = match key.next() { | 374 | 642k | Some(n) => n, | 375 | | None => { | 376 | 0 | return ExistingNodeInnerResult::Found { | 377 | 0 | node_index: current_index, | 378 | 0 | has_storage_value: current.has_storage_value, | 379 | 0 | } | 380 | | } | 381 | | }; | 382 | | | 383 | 642k | if let Some(next_index414k ) = current.children[usize::from(u8::from(child_index))] { | 384 | 414k | current_index = next_index; | 385 | 414k | } else { | 386 | 227k | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 387 | | } | 388 | | } | 389 | 245k | } |
Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB5_12proof_encode4NodeEE19existing_node_innerINtNtNtNtB1e_4iter8adapters6copied6CopiedINtNtNtB1e_5slice4iter4IterNtNtB5_6nibble6NibbleEEEB7_ _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1b_NtNtB5_9trie_node17MerkleValueOutputEEE19existing_node_innerINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1f_4iter8adapters6copied6CopiedINtNtNtB1f_5slice4iter4IterhEEEECsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 341 | 70 | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( | 342 | 70 | &self, | 343 | 70 | mut key: I, | 344 | 70 | ) -> ExistingNodeInnerResult<I> { | 345 | 70 | let mut current_index68 = match self.root_index { | 346 | 68 | Some(ri) => ri, | 347 | | None => { | 348 | 2 | return ExistingNodeInnerResult::NotFound { | 349 | 2 | closest_ancestor: None, | 350 | 2 | } | 351 | | } | 352 | | }; | 353 | 68 | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); | 354 | | | 355 | 68 | let mut closest_ancestor = None; | 356 | | | 357 | 158 | loop { | 358 | 158 | let current = self.nodes.get(current_index).unwrap(); | 359 | | | 360 | | // First, we must remove `current`'s partial key from `key`, making sure that they | 361 | | // match. | 362 | 2.13k | for nibble in current.partial_key.iter().cloned()158 { | 363 | 2.13k | if key.next() != Some(nibble) { | 364 | 26 | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 365 | 2.11k | } | 366 | | } | 367 | | | 368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches | 369 | | // `current`. | 370 | 132 | closest_ancestor = Some((current_index, key.clone())); | 371 | | | 372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. | 373 | 132 | let child_index = match key.next() { | 374 | 132 | Some(n) => n, | 375 | | None => { | 376 | 0 | return ExistingNodeInnerResult::Found { | 377 | 0 | node_index: current_index, | 378 | 0 | has_storage_value: current.has_storage_value, | 379 | 0 | } | 380 | | } | 381 | | }; | 382 | | | 383 | 132 | if let Some(next_index90 ) = current.children[usize::from(u8::from(child_index))] { | 384 | 90 | current_index = next_index; | 385 | 90 | } else { | 386 | 42 | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 387 | | } | 388 | | } | 389 | 70 | } |
Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1b_NtNtB5_9trie_node17MerkleValueOutputEEE19existing_node_innerINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1f_4iter8adapters6copied6CopiedINtNtNtB1f_5slice4iter4IterhEEEECscDgN54JpMGG_6author _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1b_NtNtB5_9trie_node17MerkleValueOutputEEE19existing_node_innerINtNtB5_6nibble14BytesToNibblesINtNtNtNtB1f_4iter8adapters6copied6CopiedINtNtNtB1f_5slice4iter4IterhEEEECsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 341 | 665 | fn existing_node_inner<I: Iterator<Item = Nibble> + Clone>( | 342 | 665 | &self, | 343 | 665 | mut key: I, | 344 | 665 | ) -> ExistingNodeInnerResult<I> { | 345 | 665 | let mut current_index646 = match self.root_index { | 346 | 646 | Some(ri) => ri, | 347 | | None => { | 348 | 19 | return ExistingNodeInnerResult::NotFound { | 349 | 19 | closest_ancestor: None, | 350 | 19 | } | 351 | | } | 352 | | }; | 353 | 646 | debug_assert!(self.nodes.get(current_index).unwrap().parent.is_none()); | 354 | | | 355 | 646 | let mut closest_ancestor = None; | 356 | | | 357 | 1.50k | loop { | 358 | 1.50k | let current = self.nodes.get(current_index).unwrap(); | 359 | | | 360 | | // First, we must remove `current`'s partial key from `key`, making sure that they | 361 | | // match. | 362 | 20.2k | for nibble in current.partial_key.iter().cloned()1.50k { | 363 | 20.2k | if key.next() != Some(nibble) { | 364 | 247 | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 365 | 20.0k | } | 366 | | } | 367 | | | 368 | | // At this point, the tree traversal cursor (the `key` iterator) exactly matches | 369 | | // `current`. | 370 | 1.25k | closest_ancestor = Some((current_index, key.clone())); | 371 | | | 372 | | // If `key.next()` is `Some`, put it in `child_index`, otherwise return successfully. | 373 | 1.25k | let child_index = match key.next() { | 374 | 1.25k | Some(n) => n, | 375 | | None => { | 376 | 0 | return ExistingNodeInnerResult::Found { | 377 | 0 | node_index: current_index, | 378 | 0 | has_storage_value: current.has_storage_value, | 379 | 0 | } | 380 | | } | 381 | | }; | 382 | | | 383 | 1.25k | if let Some(next_index855 ) = current.children[usize::from(u8::from(child_index))] { | 384 | 855 | current_index = next_index; | 385 | 855 | } else { | 386 | 399 | return ExistingNodeInnerResult::NotFound { closest_ancestor }; | 387 | | } | 388 | | } | 389 | 665 | } |
|
390 | | |
391 | | /// Removes all nodes whose key starts with the given prefix. |
392 | | /// |
393 | | /// Returns the closest ancestors to the nodes that have been removed, or `None` if that |
394 | | /// closest ancestor is not a descendant of the new trie root. |
395 | 8.10k | pub fn remove_prefix( |
396 | 8.10k | &mut self, |
397 | 8.10k | prefix: impl Iterator<Item = Nibble> + Clone, |
398 | 8.10k | ) -> Option<NodeAccess<TUd>> { |
399 | | // `ancestor` is the node that doesn't have the prefix but is the common ancestor of all |
400 | | // the nodes to remove. |
401 | 8.10k | let (ancestor_index, ancestor_child_nibble7.26k ) = match self.existing_node_inner(prefix.clone()) |
402 | | { |
403 | 6.87k | ExistingNodeInnerResult::Found { node_index, .. } => { |
404 | 6.87k | match self.nodes.get(node_index).unwrap().parent { |
405 | 6.68k | Some(p) => p, |
406 | | None => { |
407 | | // There is no parent, meaning that the trie is empty or the root of trie |
408 | | // is a node with the requested prefix. Simply clear the entire trie. |
409 | 190 | self.nodes.clear(); |
410 | 190 | self.root_index = None; |
411 | 190 | return None; |
412 | | } |
413 | | } |
414 | | } |
415 | | ExistingNodeInnerResult::NotFound { |
416 | | closest_ancestor: None, |
417 | | } => { |
418 | | // The trie is empty, or the key of the root node of the trie doesn't start with |
419 | | // the requested prefix, or the key of the root node of the trie starts with the |
420 | | // requested prefix. |
421 | | // If the trie is empty. then there is nothing to do and we return `None`. |
422 | 66 | let root_index41 = self.root_index?25 ; |
423 | | |
424 | | // Compare root key with the prefix. |
425 | 41 | if !self.nodes[root_index] |
426 | 41 | .partial_key |
427 | 41 | .iter() |
428 | 41 | .zip(prefix) |
429 | 142 | .all(|(a, b)| *a == b)41 _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB7_6nibble6NibbleEE0B9_ Line | Count | Source | 429 | 139 | .all(|(a, b)| *a == b) |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1A_5slice4iter4IterNtNtB7_6nibble6NibbleEEE0B9_ Line | Count | Source | 429 | 3 | .all(|(a, b)| *a == b) |
Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE13remove_prefixpE0B9_ |
430 | | { |
431 | | // Root node key doesn't match the prefix. Nothing to do. |
432 | 18 | return None; |
433 | 23 | } |
434 | 23 | |
435 | 23 | // Root node key starts with the requested prefix. Clear the entire trie. |
436 | 23 | self.nodes.clear(); |
437 | 23 | self.root_index = None; |
438 | 23 | return None; |
439 | | } |
440 | | ExistingNodeInnerResult::NotFound { |
441 | 1.17k | closest_ancestor: Some((ancestor, mut prefix_remain)), |
442 | 1.17k | } => { |
443 | 1.17k | // It is possible that there is simply no node at all with the given prefix, in |
444 | 1.17k | // which case there is closest ancestor but nothing to clear. |
445 | 1.17k | |
446 | 1.17k | let child_index = prefix_remain.next().unwrap(); |
447 | | |
448 | | // First possibility in case there is no node with the given prefix: the ancestor |
449 | | // simply has no child in the direction we want. For example, ancestor is |
450 | | // `[1, 2]`, there is a node at `[1, 2, 8]`, and we want to clear `[1, 2, 5]`. |
451 | 703 | let direct_child = if let Some(c) = |
452 | 1.17k | self.nodes[ancestor].children[usize::from(u8::from(child_index))] |
453 | | { |
454 | 703 | c |
455 | | } else { |
456 | 467 | return Some(self.node_by_index_inner(ancestor).unwrap()); |
457 | | }; |
458 | | |
459 | | // Second possibility in case there is no node with the given prefix: the ancestor |
460 | | // has a child in the direction we want, but this child doesn't have the prefix |
461 | | // that we want. For example, ancestor is `[1, 2]`, there is a node at |
462 | | // `[1, 2, 3, 8]`, and we want to clear `[1, 2, 3, 6]`. |
463 | | // TODO: this seems sub-optimal |
464 | 703 | if !self.nodes[direct_child] |
465 | 703 | .partial_key |
466 | 703 | .iter() |
467 | 703 | .zip(prefix_remain) |
468 | 1.34k | .all(|(a, b)| *a == b)703 _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB7_6nibble6NibbleEEs_0B9_ Line | Count | Source | 468 | 1.34k | .all(|(a, b)| *a == b) |
Unexecuted instantiation: _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1A_5slice4iter4IterNtNtB7_6nibble6NibbleEEEs_0B9_ Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE13remove_prefixpEs_0B9_ |
469 | | { |
470 | 119 | return Some(self.node_by_index_inner(ancestor).unwrap()); |
471 | 584 | } |
472 | 584 | |
473 | 584 | (ancestor, child_index) |
474 | | } |
475 | | }; |
476 | | |
477 | | // Removes all the descendants of `ancestor` through `ancestor_child_nibble`. |
478 | | { |
479 | | // TODO: this performs allocations, do we care? |
480 | 7.26k | let first_remove_index = self |
481 | 7.26k | .nodes |
482 | 7.26k | .get_mut(ancestor_index) |
483 | 7.26k | .unwrap() |
484 | 7.26k | .children |
485 | 7.26k | .get_mut(usize::from(u8::from(ancestor_child_nibble))) |
486 | 7.26k | .unwrap() |
487 | 7.26k | .take() |
488 | 7.26k | .unwrap(); |
489 | 7.26k | |
490 | 7.26k | let mut to_remove = vec![first_remove_index]; |
491 | 25.3k | while !to_remove.is_empty() { |
492 | 18.0k | let mut next_to_remove = Vec::new(); |
493 | 53.4k | for node_index in to_remove.drain(..)18.0k { |
494 | 53.4k | let node = self.nodes.remove(node_index); |
495 | 854k | next_to_remove.extend(node.children.iter().filter_map(|n| *n)); _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB7_6nibble6NibbleEEs0_0B9_ Line | Count | Source | 495 | 854k | next_to_remove.extend(node.children.iter().filter_map(|n| *n)); |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1A_5slice4iter4IterNtNtB7_6nibble6NibbleEEEs0_0B9_ Line | Count | Source | 495 | 128 | next_to_remove.extend(node.children.iter().filter_map(|n| *n)); |
Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE13remove_prefixpEs0_0B9_ |
496 | 53.4k | } |
497 | 18.0k | mem::swap(&mut to_remove, &mut next_to_remove); |
498 | | } |
499 | | } |
500 | | |
501 | | // If `ancestor` is a branch node with only one child (had two children before this |
502 | | // function call, but we removed one earlier), we have to remove it from the tree as well. |
503 | | // If this is the case, `actual_ancestor_index` will be equal to `ancestor`'s parent. |
504 | | // Otherwise it is set to `ancestor_index`. |
505 | 7.26k | let actual_ancestor_index = { |
506 | 7.26k | let ancestor = self.nodes.get_mut(ancestor_index).unwrap(); |
507 | 7.26k | debug_assert!( |
508 | 24.7k | ancestor.has_storage_value7.26k || ancestor.children.iter().any(3.83k |c| c.is_some())3.83k _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB7_6nibble6NibbleEEs5_0B9_ Line | Count | Source | 508 | 24.7k | ancestor.has_storage_value || ancestor.children.iter().any(|c| c.is_some()) |
Unexecuted instantiation: _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1A_5slice4iter4IterNtNtB7_6nibble6NibbleEEEs5_0B9_ Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE13remove_prefixpEs5_0B9_ |
509 | | ); |
510 | 7.26k | if !ancestor.has_storage_value |
511 | 61.3k | && ancestor.children.iter().filter(3.83k |c| c.is_some()).count() == 13.83k _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB7_6nibble6NibbleEEs1_0B9_ Line | Count | Source | 511 | 61.3k | && ancestor.children.iter().filter(|c| c.is_some()).count() == 1 |
Unexecuted instantiation: _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1A_5slice4iter4IterNtNtB7_6nibble6NibbleEEEs1_0B9_ Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE13remove_prefixpEs1_0B9_ |
512 | | { |
513 | 2.04k | let ancestor = self.nodes.remove(ancestor_index); |
514 | 17.1k | let sibling_node_index: usize = ancestor.children.iter().find_map(|c| *c).unwrap(); _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB7_6nibble6NibbleEEs2_0B9_ Line | Count | Source | 514 | 17.1k | let sibling_node_index: usize = ancestor.children.iter().find_map(|c| *c).unwrap(); |
Unexecuted instantiation: _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1A_5slice4iter4IterNtNtB7_6nibble6NibbleEEEs2_0B9_ Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE13remove_prefixpEs2_0B9_ |
515 | 2.04k | |
516 | 2.04k | // Update the sibling to point to the ancestor's parent. |
517 | 2.04k | { |
518 | 2.04k | let sibling = self.nodes.get_mut(sibling_node_index).unwrap(); |
519 | 2.04k | debug_assert_eq!(sibling.parent.as_ref().unwrap().0, ancestor_index); |
520 | 2.04k | insert_front( |
521 | 2.04k | &mut sibling.partial_key, |
522 | 2.04k | ancestor.partial_key, |
523 | 2.04k | sibling.parent.unwrap().1, |
524 | 2.04k | ); |
525 | 2.04k | sibling.parent = ancestor.parent; |
526 | | } |
527 | | |
528 | | // Update the ancestor's parent to point to the sibling. |
529 | 2.04k | if let Some((ancestor_parent_index, parent_to_sibling_index1.71k )) = ancestor.parent { |
530 | | // Update the ancestory's parent to point to the sibling. |
531 | 1.71k | let ancestor_parent = self.nodes.get_mut(ancestor_parent_index).unwrap(); |
532 | 1.71k | debug_assert_eq!( |
533 | 1.71k | ancestor_parent.children[usize::from(u8::from(parent_to_sibling_index))], |
534 | 1.71k | Some(ancestor_index) |
535 | | ); |
536 | 1.71k | ancestor_parent.children[usize::from(u8::from(parent_to_sibling_index))] = |
537 | 1.71k | Some(sibling_node_index); |
538 | | } else { |
539 | 327 | debug_assert_eq!(self.root_index, Some(ancestor_index)); |
540 | 327 | self.root_index = Some(sibling_node_index); |
541 | | } |
542 | | |
543 | 2.04k | ancestor.parent.map(|(idx, _)| idx1.71k ) _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB7_6nibble6NibbleEEs3_0B9_ Line | Count | Source | 543 | 1.71k | ancestor.parent.map(|(idx, _)| idx) |
Unexecuted instantiation: _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1A_5slice4iter4IterNtNtB7_6nibble6NibbleEEEs3_0B9_ Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE13remove_prefixpEs3_0B9_ |
544 | | } else { |
545 | 5.22k | Some(ancestor_index) |
546 | | } |
547 | | }; |
548 | | |
549 | | // Return value of the function. |
550 | 7.26k | actual_ancestor_index.map(move |idx| self.node_by_index_inner(idx).unwrap()6.93k ) _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB7_6nibble6NibbleEEs4_0B9_ Line | Count | Source | 550 | 6.93k | actual_ancestor_index.map(move |idx| self.node_by_index_inner(idx).unwrap()) |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE13remove_prefixINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1A_5slice4iter4IterNtNtB7_6nibble6NibbleEEEs4_0B9_ Line | Count | Source | 550 | 2 | actual_ancestor_index.map(move |idx| self.node_by_index_inner(idx).unwrap()) |
Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE13remove_prefixpEs4_0B9_ |
551 | 8.10k | } _RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE13remove_prefixINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB5_6nibble6NibbleEEB7_ Line | Count | Source | 395 | 8.10k | pub fn remove_prefix( | 396 | 8.10k | &mut self, | 397 | 8.10k | prefix: impl Iterator<Item = Nibble> + Clone, | 398 | 8.10k | ) -> Option<NodeAccess<TUd>> { | 399 | | // `ancestor` is the node that doesn't have the prefix but is the common ancestor of all | 400 | | // the nodes to remove. | 401 | 8.10k | let (ancestor_index, ancestor_child_nibble7.26k ) = match self.existing_node_inner(prefix.clone()) | 402 | | { | 403 | 6.86k | ExistingNodeInnerResult::Found { node_index, .. } => { | 404 | 6.86k | match self.nodes.get(node_index).unwrap().parent { | 405 | 6.67k | Some(p) => p, | 406 | | None => { | 407 | | // There is no parent, meaning that the trie is empty or the root of trie | 408 | | // is a node with the requested prefix. Simply clear the entire trie. | 409 | 189 | self.nodes.clear(); | 410 | 189 | self.root_index = None; | 411 | 189 | return None; | 412 | | } | 413 | | } | 414 | | } | 415 | | ExistingNodeInnerResult::NotFound { | 416 | | closest_ancestor: None, | 417 | | } => { | 418 | | // The trie is empty, or the key of the root node of the trie doesn't start with | 419 | | // the requested prefix, or the key of the root node of the trie starts with the | 420 | | // requested prefix. | 421 | | // If the trie is empty. then there is nothing to do and we return `None`. | 422 | 65 | let root_index40 = self.root_index?25 ; | 423 | | | 424 | | // Compare root key with the prefix. | 425 | 40 | if !self.nodes[root_index] | 426 | 40 | .partial_key | 427 | 40 | .iter() | 428 | 40 | .zip(prefix) | 429 | 40 | .all(|(a, b)| *a == b) | 430 | | { | 431 | | // Root node key doesn't match the prefix. Nothing to do. | 432 | 17 | return None; | 433 | 23 | } | 434 | 23 | | 435 | 23 | // Root node key starts with the requested prefix. Clear the entire trie. | 436 | 23 | self.nodes.clear(); | 437 | 23 | self.root_index = None; | 438 | 23 | return None; | 439 | | } | 440 | | ExistingNodeInnerResult::NotFound { | 441 | 1.16k | closest_ancestor: Some((ancestor, mut prefix_remain)), | 442 | 1.16k | } => { | 443 | 1.16k | // It is possible that there is simply no node at all with the given prefix, in | 444 | 1.16k | // which case there is closest ancestor but nothing to clear. | 445 | 1.16k | | 446 | 1.16k | let child_index = prefix_remain.next().unwrap(); | 447 | | | 448 | | // First possibility in case there is no node with the given prefix: the ancestor | 449 | | // simply has no child in the direction we want. For example, ancestor is | 450 | | // `[1, 2]`, there is a node at `[1, 2, 8]`, and we want to clear `[1, 2, 5]`. | 451 | 703 | let direct_child = if let Some(c) = | 452 | 1.16k | self.nodes[ancestor].children[usize::from(u8::from(child_index))] | 453 | | { | 454 | 703 | c | 455 | | } else { | 456 | 466 | return Some(self.node_by_index_inner(ancestor).unwrap()); | 457 | | }; | 458 | | | 459 | | // Second possibility in case there is no node with the given prefix: the ancestor | 460 | | // has a child in the direction we want, but this child doesn't have the prefix | 461 | | // that we want. For example, ancestor is `[1, 2]`, there is a node at | 462 | | // `[1, 2, 3, 8]`, and we want to clear `[1, 2, 3, 6]`. | 463 | | // TODO: this seems sub-optimal | 464 | 703 | if !self.nodes[direct_child] | 465 | 703 | .partial_key | 466 | 703 | .iter() | 467 | 703 | .zip(prefix_remain) | 468 | 703 | .all(|(a, b)| *a == b) | 469 | | { | 470 | 119 | return Some(self.node_by_index_inner(ancestor).unwrap()); | 471 | 584 | } | 472 | 584 | | 473 | 584 | (ancestor, child_index) | 474 | | } | 475 | | }; | 476 | | | 477 | | // Removes all the descendants of `ancestor` through `ancestor_child_nibble`. | 478 | | { | 479 | | // TODO: this performs allocations, do we care? | 480 | 7.26k | let first_remove_index = self | 481 | 7.26k | .nodes | 482 | 7.26k | .get_mut(ancestor_index) | 483 | 7.26k | .unwrap() | 484 | 7.26k | .children | 485 | 7.26k | .get_mut(usize::from(u8::from(ancestor_child_nibble))) | 486 | 7.26k | .unwrap() | 487 | 7.26k | .take() | 488 | 7.26k | .unwrap(); | 489 | 7.26k | | 490 | 7.26k | let mut to_remove = vec![first_remove_index]; | 491 | 25.3k | while !to_remove.is_empty() { | 492 | 18.0k | let mut next_to_remove = Vec::new(); | 493 | 53.4k | for node_index in to_remove.drain(..)18.0k { | 494 | 53.4k | let node = self.nodes.remove(node_index); | 495 | 53.4k | next_to_remove.extend(node.children.iter().filter_map(|n| *n)); | 496 | 53.4k | } | 497 | 18.0k | mem::swap(&mut to_remove, &mut next_to_remove); | 498 | | } | 499 | | } | 500 | | | 501 | | // If `ancestor` is a branch node with only one child (had two children before this | 502 | | // function call, but we removed one earlier), we have to remove it from the tree as well. | 503 | | // If this is the case, `actual_ancestor_index` will be equal to `ancestor`'s parent. | 504 | | // Otherwise it is set to `ancestor_index`. | 505 | 7.26k | let actual_ancestor_index = { | 506 | 7.26k | let ancestor = self.nodes.get_mut(ancestor_index).unwrap(); | 507 | 7.26k | debug_assert!( | 508 | 7.26k | ancestor.has_storage_value || ancestor.children.iter().any(3.83k |c| c.is_some())3.83k | 509 | | ); | 510 | 7.26k | if !ancestor.has_storage_value | 511 | 3.83k | && ancestor.children.iter().filter(|c| c.is_some()).count() == 1 | 512 | | { | 513 | 2.04k | let ancestor = self.nodes.remove(ancestor_index); | 514 | 2.04k | let sibling_node_index: usize = ancestor.children.iter().find_map(|c| *c).unwrap(); | 515 | 2.04k | | 516 | 2.04k | // Update the sibling to point to the ancestor's parent. | 517 | 2.04k | { | 518 | 2.04k | let sibling = self.nodes.get_mut(sibling_node_index).unwrap(); | 519 | 2.04k | debug_assert_eq!(sibling.parent.as_ref().unwrap().0, ancestor_index); | 520 | 2.04k | insert_front( | 521 | 2.04k | &mut sibling.partial_key, | 522 | 2.04k | ancestor.partial_key, | 523 | 2.04k | sibling.parent.unwrap().1, | 524 | 2.04k | ); | 525 | 2.04k | sibling.parent = ancestor.parent; | 526 | | } | 527 | | | 528 | | // Update the ancestor's parent to point to the sibling. | 529 | 2.04k | if let Some((ancestor_parent_index, parent_to_sibling_index1.71k )) = ancestor.parent { | 530 | | // Update the ancestory's parent to point to the sibling. | 531 | 1.71k | let ancestor_parent = self.nodes.get_mut(ancestor_parent_index).unwrap(); | 532 | 1.71k | debug_assert_eq!( | 533 | 1.71k | ancestor_parent.children[usize::from(u8::from(parent_to_sibling_index))], | 534 | 1.71k | Some(ancestor_index) | 535 | | ); | 536 | 1.71k | ancestor_parent.children[usize::from(u8::from(parent_to_sibling_index))] = | 537 | 1.71k | Some(sibling_node_index); | 538 | | } else { | 539 | 327 | debug_assert_eq!(self.root_index, Some(ancestor_index)); | 540 | 327 | self.root_index = Some(sibling_node_index); | 541 | | } | 542 | | | 543 | 2.04k | ancestor.parent.map(|(idx, _)| idx) | 544 | | } else { | 545 | 5.22k | Some(ancestor_index) | 546 | | } | 547 | | }; | 548 | | | 549 | | // Return value of the function. | 550 | 7.26k | actual_ancestor_index.map(move |idx| self.node_by_index_inner(idx).unwrap()) | 551 | 8.10k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE13remove_prefixINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1y_5slice4iter4IterNtNtB5_6nibble6NibbleEEEB7_ Line | Count | Source | 395 | 5 | pub fn remove_prefix( | 396 | 5 | &mut self, | 397 | 5 | prefix: impl Iterator<Item = Nibble> + Clone, | 398 | 5 | ) -> Option<NodeAccess<TUd>> { | 399 | | // `ancestor` is the node that doesn't have the prefix but is the common ancestor of all | 400 | | // the nodes to remove. | 401 | 5 | let (ancestor_index, ancestor_child_nibble2 ) = match self.existing_node_inner(prefix.clone()) | 402 | | { | 403 | 3 | ExistingNodeInnerResult::Found { node_index, .. } => { | 404 | 3 | match self.nodes.get(node_index).unwrap().parent { | 405 | 2 | Some(p) => p, | 406 | | None => { | 407 | | // There is no parent, meaning that the trie is empty or the root of trie | 408 | | // is a node with the requested prefix. Simply clear the entire trie. | 409 | 1 | self.nodes.clear(); | 410 | 1 | self.root_index = None; | 411 | 1 | return None; | 412 | | } | 413 | | } | 414 | | } | 415 | | ExistingNodeInnerResult::NotFound { | 416 | | closest_ancestor: None, | 417 | | } => { | 418 | | // The trie is empty, or the key of the root node of the trie doesn't start with | 419 | | // the requested prefix, or the key of the root node of the trie starts with the | 420 | | // requested prefix. | 421 | | // If the trie is empty. then there is nothing to do and we return `None`. | 422 | 1 | let root_index = self.root_index?0 ; | 423 | | | 424 | | // Compare root key with the prefix. | 425 | 1 | if !self.nodes[root_index] | 426 | 1 | .partial_key | 427 | 1 | .iter() | 428 | 1 | .zip(prefix) | 429 | 1 | .all(|(a, b)| *a == b) | 430 | | { | 431 | | // Root node key doesn't match the prefix. Nothing to do. | 432 | 1 | return None; | 433 | 0 | } | 434 | 0 |
| 435 | 0 | // Root node key starts with the requested prefix. Clear the entire trie. | 436 | 0 | self.nodes.clear(); | 437 | 0 | self.root_index = None; | 438 | 0 | return None; | 439 | | } | 440 | | ExistingNodeInnerResult::NotFound { | 441 | 1 | closest_ancestor: Some((ancestor, mut prefix_remain)), | 442 | 1 | } => { | 443 | 1 | // It is possible that there is simply no node at all with the given prefix, in | 444 | 1 | // which case there is closest ancestor but nothing to clear. | 445 | 1 | | 446 | 1 | let child_index = prefix_remain.next().unwrap(); | 447 | | | 448 | | // First possibility in case there is no node with the given prefix: the ancestor | 449 | | // simply has no child in the direction we want. For example, ancestor is | 450 | | // `[1, 2]`, there is a node at `[1, 2, 8]`, and we want to clear `[1, 2, 5]`. | 451 | 0 | let direct_child = if let Some(c) = | 452 | 1 | self.nodes[ancestor].children[usize::from(u8::from(child_index))] | 453 | | { | 454 | 0 | c | 455 | | } else { | 456 | 1 | return Some(self.node_by_index_inner(ancestor).unwrap()); | 457 | | }; | 458 | | | 459 | | // Second possibility in case there is no node with the given prefix: the ancestor | 460 | | // has a child in the direction we want, but this child doesn't have the prefix | 461 | | // that we want. For example, ancestor is `[1, 2]`, there is a node at | 462 | | // `[1, 2, 3, 8]`, and we want to clear `[1, 2, 3, 6]`. | 463 | | // TODO: this seems sub-optimal | 464 | 0 | if !self.nodes[direct_child] | 465 | 0 | .partial_key | 466 | 0 | .iter() | 467 | 0 | .zip(prefix_remain) | 468 | 0 | .all(|(a, b)| *a == b) | 469 | | { | 470 | 0 | return Some(self.node_by_index_inner(ancestor).unwrap()); | 471 | 0 | } | 472 | 0 |
| 473 | 0 | (ancestor, child_index) | 474 | | } | 475 | | }; | 476 | | | 477 | | // Removes all the descendants of `ancestor` through `ancestor_child_nibble`. | 478 | | { | 479 | | // TODO: this performs allocations, do we care? | 480 | 2 | let first_remove_index = self | 481 | 2 | .nodes | 482 | 2 | .get_mut(ancestor_index) | 483 | 2 | .unwrap() | 484 | 2 | .children | 485 | 2 | .get_mut(usize::from(u8::from(ancestor_child_nibble))) | 486 | 2 | .unwrap() | 487 | 2 | .take() | 488 | 2 | .unwrap(); | 489 | 2 | | 490 | 2 | let mut to_remove = vec![first_remove_index]; | 491 | 8 | while !to_remove.is_empty() { | 492 | 6 | let mut next_to_remove = Vec::new(); | 493 | 8 | for node_index in to_remove.drain(..)6 { | 494 | 8 | let node = self.nodes.remove(node_index); | 495 | 8 | next_to_remove.extend(node.children.iter().filter_map(|n| *n)); | 496 | 8 | } | 497 | 6 | mem::swap(&mut to_remove, &mut next_to_remove); | 498 | | } | 499 | | } | 500 | | | 501 | | // If `ancestor` is a branch node with only one child (had two children before this | 502 | | // function call, but we removed one earlier), we have to remove it from the tree as well. | 503 | | // If this is the case, `actual_ancestor_index` will be equal to `ancestor`'s parent. | 504 | | // Otherwise it is set to `ancestor_index`. | 505 | 2 | let actual_ancestor_index = { | 506 | 2 | let ancestor = self.nodes.get_mut(ancestor_index).unwrap(); | 507 | 2 | debug_assert!( | 508 | 2 | ancestor.has_storage_value || ancestor.children.iter().any(0 |c| c.is_some())0 | 509 | | ); | 510 | 2 | if !ancestor.has_storage_value | 511 | 0 | && ancestor.children.iter().filter(|c| c.is_some()).count() == 1 | 512 | | { | 513 | 0 | let ancestor = self.nodes.remove(ancestor_index); | 514 | 0 | let sibling_node_index: usize = ancestor.children.iter().find_map(|c| *c).unwrap(); | 515 | 0 |
| 516 | 0 | // Update the sibling to point to the ancestor's parent. | 517 | 0 | { | 518 | 0 | let sibling = self.nodes.get_mut(sibling_node_index).unwrap(); | 519 | 0 | debug_assert_eq!(sibling.parent.as_ref().unwrap().0, ancestor_index); | 520 | 0 | insert_front( | 521 | 0 | &mut sibling.partial_key, | 522 | 0 | ancestor.partial_key, | 523 | 0 | sibling.parent.unwrap().1, | 524 | 0 | ); | 525 | 0 | sibling.parent = ancestor.parent; | 526 | | } | 527 | | | 528 | | // Update the ancestor's parent to point to the sibling. | 529 | 0 | if let Some((ancestor_parent_index, parent_to_sibling_index)) = ancestor.parent { | 530 | | // Update the ancestory's parent to point to the sibling. | 531 | 0 | let ancestor_parent = self.nodes.get_mut(ancestor_parent_index).unwrap(); | 532 | 0 | debug_assert_eq!( | 533 | 0 | ancestor_parent.children[usize::from(u8::from(parent_to_sibling_index))], | 534 | 0 | Some(ancestor_index) | 535 | | ); | 536 | 0 | ancestor_parent.children[usize::from(u8::from(parent_to_sibling_index))] = | 537 | 0 | Some(sibling_node_index); | 538 | | } else { | 539 | 0 | debug_assert_eq!(self.root_index, Some(ancestor_index)); | 540 | 0 | self.root_index = Some(sibling_node_index); | 541 | | } | 542 | | | 543 | 0 | ancestor.parent.map(|(idx, _)| idx) | 544 | | } else { | 545 | 2 | Some(ancestor_index) | 546 | | } | 547 | | }; | 548 | | | 549 | | // Return value of the function. | 550 | 2 | actual_ancestor_index.map(move |idx| self.node_by_index_inner(idx).unwrap()) | 551 | 5 | } |
Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructurepE13remove_prefixpEB7_ |
552 | | |
553 | | /// Returns true if the structure of this trie is the same as the structure of `other`. |
554 | | /// |
555 | | /// Everything is compared for equality except for the user datas. |
556 | | /// |
557 | | /// > **Note**: This function does a preliminary check for `self.len() == other.len()`. If the |
558 | | /// > length are different, `false` is immediately returned. If the lengths are |
559 | | /// > equal, the function performs the expensive operation of traversing both |
560 | | /// > tries in order to detect a potential mismatch. |
561 | | /// |
562 | | /// # Examples |
563 | | /// |
564 | | /// ``` |
565 | | /// use smoldot::trie::{self, trie_structure}; |
566 | | /// |
567 | | /// let mut trie1 = trie_structure::TrieStructure::new(); |
568 | | /// let mut trie2 = trie_structure::TrieStructure::new(); |
569 | | /// assert!(trie1.structure_equal(&trie2)); |
570 | | /// |
571 | | /// // Insert a node in the first trie. |
572 | | /// trie1 |
573 | | /// .node(trie::bytes_to_nibbles(b"foo".iter().cloned())) |
574 | | /// .into_vacant() |
575 | | /// .unwrap() |
576 | | /// .insert_storage_value() |
577 | | /// .insert(1234, 5678); |
578 | | /// assert!(!trie1.structure_equal(&trie2)); |
579 | | /// |
580 | | /// // Insert the same node in the second trie, but with a different user data. |
581 | | /// // The type of the user data of the second trie (strings) isn't even the same as for the |
582 | | /// // first trie (i32s). |
583 | | /// trie2 |
584 | | /// .node(trie::bytes_to_nibbles(b"foo".iter().cloned())) |
585 | | /// .into_vacant() |
586 | | /// .unwrap() |
587 | | /// .insert_storage_value() |
588 | | /// .insert("hello", "world"); |
589 | | /// |
590 | | /// // `structure_equal` returns true because both tries have the same nodes. |
591 | | /// assert!(trie1.structure_equal(&trie2)); |
592 | | /// ``` |
593 | 3.84k | pub fn structure_equal<T>(&self, other: &TrieStructure<T>) -> bool { |
594 | 3.84k | if self.nodes.len() != other.nodes.len() { |
595 | 0 | return false; |
596 | 3.84k | } |
597 | 3.84k | |
598 | 3.84k | let mut me_iter = self.all_node_lexicographic_ordered(); |
599 | 3.84k | let mut other_iter = other.all_node_lexicographic_ordered(); |
600 | | |
601 | | loop { |
602 | 724k | let (me_node_idx, other_node_idx720k ) = match (me_iter.next(), other_iter.next()) { |
603 | 720k | (Some(a), Some(b)) => (a, b), |
604 | 3.84k | (None, None) => return true, |
605 | 0 | _ => return false, |
606 | | }; |
607 | | |
608 | 720k | let me_node = self.nodes.get(me_node_idx).unwrap(); |
609 | 720k | let other_node = other.nodes.get(other_node_idx).unwrap(); |
610 | 720k | |
611 | 720k | if me_node.has_storage_value != other_node.has_storage_value { |
612 | 0 | return false; |
613 | 720k | } |
614 | 720k | |
615 | 720k | match (me_node.parent, other_node.parent) { |
616 | 716k | (Some((_, i)), Some((_, j))) if i == j => {} |
617 | 3.84k | (None, None) => {} |
618 | 0 | _ => return false, |
619 | | } |
620 | | |
621 | 720k | if me_node.partial_key != other_node.partial_key { |
622 | 0 | return false; |
623 | 720k | } |
624 | | } |
625 | 3.84k | } _RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE15structure_equaluEB7_ Line | Count | Source | 593 | 3.84k | pub fn structure_equal<T>(&self, other: &TrieStructure<T>) -> bool { | 594 | 3.84k | if self.nodes.len() != other.nodes.len() { | 595 | 0 | return false; | 596 | 3.84k | } | 597 | 3.84k | | 598 | 3.84k | let mut me_iter = self.all_node_lexicographic_ordered(); | 599 | 3.84k | let mut other_iter = other.all_node_lexicographic_ordered(); | 600 | | | 601 | | loop { | 602 | 724k | let (me_node_idx, other_node_idx720k ) = match (me_iter.next(), other_iter.next()) { | 603 | 720k | (Some(a), Some(b)) => (a, b), | 604 | 3.84k | (None, None) => return true, | 605 | 0 | _ => return false, | 606 | | }; | 607 | | | 608 | 720k | let me_node = self.nodes.get(me_node_idx).unwrap(); | 609 | 720k | let other_node = other.nodes.get(other_node_idx).unwrap(); | 610 | 720k | | 611 | 720k | if me_node.has_storage_value != other_node.has_storage_value { | 612 | 0 | return false; | 613 | 720k | } | 614 | 720k | | 615 | 720k | match (me_node.parent, other_node.parent) { | 616 | 716k | (Some((_, i)), Some((_, j))) if i == j => {} | 617 | 3.84k | (None, None) => {} | 618 | 0 | _ => return false, | 619 | | } | 620 | | | 621 | 720k | if me_node.partial_key != other_node.partial_key { | 622 | 0 | return false; | 623 | 720k | } | 624 | | } | 625 | 3.84k | } |
Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructurepE15structure_equalpEB7_ |
626 | | |
627 | | /// Returns all nodes whose full key is within the given range, in lexicographic order. |
628 | | // TODO: change API to accept the range trait? |
629 | | #[inline] |
630 | 0 | pub fn range<'a>( |
631 | 0 | &'a self, |
632 | 0 | start_bound: ops::Bound<&'a [u8]>, // TODO: why does this require a `'a` lifetime? I don't get it |
633 | 0 | end_bound: ops::Bound<&'a [u8]>, |
634 | 0 | ) -> impl Iterator<Item = NodeIndex> + 'a { |
635 | 0 | let start_bound = match start_bound { |
636 | 0 | ops::Bound::Included(key) => { |
637 | 0 | ops::Bound::Included(bytes_to_nibbles(key.iter().copied())) |
638 | | } |
639 | 0 | ops::Bound::Excluded(key) => { |
640 | 0 | ops::Bound::Excluded(bytes_to_nibbles(key.iter().copied())) |
641 | | } |
642 | 0 | ops::Bound::Unbounded => ops::Bound::Unbounded, |
643 | | }; |
644 | | |
645 | 0 | let end_bound = match end_bound { |
646 | 0 | ops::Bound::Included(key) => { |
647 | 0 | ops::Bound::Included(bytes_to_nibbles(key.iter().copied())) |
648 | | } |
649 | 0 | ops::Bound::Excluded(key) => { |
650 | 0 | ops::Bound::Excluded(bytes_to_nibbles(key.iter().copied())) |
651 | | } |
652 | 0 | ops::Bound::Unbounded => ops::Bound::Unbounded, |
653 | | }; |
654 | | |
655 | 0 | self.range_inner(start_bound, end_bound).map(NodeIndex) |
656 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructurepE5rangeB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructurepE5rangeB6_ |
657 | | |
658 | | /// Returns all nodes whose full key is within the given range, in lexicographic order. |
659 | 6.56M | pub fn range_iter<'a>( |
660 | 6.56M | &'a self, |
661 | 6.56M | start_bound: ops::Bound<impl Iterator<Item = Nibble>>, |
662 | 6.56M | end_bound: ops::Bound<impl Iterator<Item = Nibble> + 'a>, |
663 | 6.56M | ) -> impl Iterator<Item = NodeIndex> + 'a { |
664 | 6.56M | self.range_inner(start_bound, end_bound).map(NodeIndex) |
665 | 6.56M | } _RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE10range_iterINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1v_5slice4iter4IterNtNtB5_6nibble6NibbleEEB1m_EB7_ Line | Count | Source | 659 | 262k | pub fn range_iter<'a>( | 660 | 262k | &'a self, | 661 | 262k | start_bound: ops::Bound<impl Iterator<Item = Nibble>>, | 662 | 262k | end_bound: ops::Bound<impl Iterator<Item = Nibble> + 'a>, | 663 | 262k | ) -> impl Iterator<Item = NodeIndex> + 'a { | 664 | 262k | self.range_inner(start_bound, end_bound).map(NodeIndex) | 665 | 262k | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB5_16TrieEntryVersionEEIB1a_NtNtB5_9trie_node17MerkleValueOutputEEE10range_iterINtNtB1P_9into_iter8IntoIterNtNtB5_6nibble6NibbleEINtNtNtNtB1e_4iter7sources5empty5EmptyB46_EEB7_ Line | Count | Source | 659 | 6.30M | pub fn range_iter<'a>( | 660 | 6.30M | &'a self, | 661 | 6.30M | start_bound: ops::Bound<impl Iterator<Item = Nibble>>, | 662 | 6.30M | end_bound: ops::Bound<impl Iterator<Item = Nibble> + 'a>, | 663 | 6.30M | ) -> impl Iterator<Item = NodeIndex> + 'a { | 664 | 6.30M | self.range_inner(start_bound, end_bound).map(NodeIndex) | 665 | 6.30M | } |
Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructurepE10range_iterppEB7_ |
666 | | |
667 | | /// Returns all nodes whose full key is within the given range, in lexicographic order. |
668 | 6.56M | fn range_inner<'a>( |
669 | 6.56M | &'a self, |
670 | 6.56M | start_bound: ops::Bound<impl Iterator<Item = Nibble>>, |
671 | 6.56M | end_bound: ops::Bound<impl Iterator<Item = Nibble> + 'a>, |
672 | 6.56M | ) -> impl Iterator<Item = usize> + 'a { |
673 | | // Start by processing the end bound to obtain an "end key". |
674 | | // This end key is always assumed to be excluded. In other words, only keys strictly |
675 | | // inferior to the end key are returned. If the user provides `Included`, we modify the key |
676 | | // and append a dummy `0` nibble at the end of it. If the user provides `Unbounded`, we use |
677 | | // an infinite-sized key so that every finite key is always inferior to it. |
678 | | // |
679 | | // The algorithm later down this function will pop nibbles from the start of `end_key`. |
680 | | // Because `end_key` is always excluded, this iterator must always contain at least one |
681 | | // nibble, otherwise the iteration should have ended. |
682 | 6.56M | let mut end_key = match end_bound { |
683 | 6.39M | ops::Bound::Unbounded => either::Left(iter::repeat(Nibble::max())), |
684 | 87.3k | ops::Bound::Excluded(end_key) => either::Right(end_key.chain(None)), |
685 | 87.0k | ops::Bound::Included(end_key) => either::Right(end_key.chain(Some(Nibble::zero()))), |
686 | | } |
687 | 6.56M | .peekable(); |
688 | 6.56M | |
689 | 6.56M | // The user passed `Excluded(&[])`. Return an empty range. |
690 | 6.56M | if end_key.peek().is_none() { |
691 | 14.5k | return either::Right(iter::empty()); |
692 | 6.55M | } |
693 | | |
694 | | // The code below creates a variable named `iter`. This `iter` represents the cursor |
695 | | // where the iterator is. |
696 | | // `iter` also contains an optional nibble. If this optional nibble is `None`, the |
697 | | // iteration is currently at the node itself. If it is `Some`, the iteration isn't at the |
698 | | // node itself but at its child of the given nibble (which potentially doesn't exist). |
699 | | // If it is `Some(None)`, then the iteration is right after the last children of the node. |
700 | | // In other words, `Some(None)` represents an overflow. |
701 | 6.55M | let mut iter: (usize, Option<Option<Nibble>>)6.55M = match self.root_index { |
702 | 6.55M | Some(idx) => (idx, None), |
703 | | None => { |
704 | | // Trie is empty. Special case. |
705 | 367 | return either::Right(iter::empty()); |
706 | | } |
707 | | }; |
708 | | |
709 | | // Equal to `len(key(iter)) - len(key(iter) ∩ end_key)`. In other words, the number of |
710 | | // nibbles at the end of `iter`'s key that do not match the end key. This also includes |
711 | | // the optional nibble within `iter` if any. |
712 | 6.55M | let mut iter_key_nibbles_extra: usize = 0; |
713 | | |
714 | | // Transform `start_bound` into something more simple to process. |
715 | 6.55M | let (mut start_key, start_key_is_inclusive) = match start_bound { |
716 | 82.0k | ops::Bound::Unbounded => (either::Right(iter::empty()), true), |
717 | 6.38M | ops::Bound::Included(k) => (either::Left(k), true), |
718 | 82.9k | ops::Bound::Excluded(k) => (either::Left(k), false), |
719 | | }; |
720 | | |
721 | | // Iterate down the tree, updating the variables above. At each iteration, one of the |
722 | | // three following is true: |
723 | | // |
724 | | // - `iter` is inferior or inferior or equal (depending on `start_key_is_inclusive`) to |
725 | | // `start_key`. |
726 | | // - `iter` is the first node that is superior or strictly superior (depending on |
727 | | // `start_key_is_inclusive`) to `start_key`. |
728 | | // - `iter` points to a non-existing node that is inferior/inferior-or-equal to |
729 | | // `start_key`, but is right before the first node that is superior/strictly superior to |
730 | | // `start_key`. |
731 | | // |
732 | | // As soon as we reach one of the last two conditions, we stop iterating, as it means |
733 | | // that `iter` is at the correct position. |
734 | 8.11M | 'start_search: loop { |
735 | 8.11M | debug_assert!(iter.1.is_none()); |
736 | 8.11M | let iter_node = self.nodes.get(iter.0).unwrap(); |
737 | | |
738 | | // Compare the nibbles at the front of `start_key` with the ones of `iter_node`. |
739 | | // Consumes the nibbles at the start of `start_key`. |
740 | 8.11M | let pk_compare = { |
741 | 8.11M | let mut result = cmp::Ordering::Equal; |
742 | 8.11M | for iter_node_pk_nibble3.01M in iter_node.partial_key.iter() { |
743 | 3.01M | match start_key |
744 | 3.01M | .next() |
745 | 3.01M | .map(|nibble| nibble.cmp(iter_node_pk_nibble)2.95M ) _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEE11range_innerINtNtB1R_9into_iter8IntoIterNtNtB7_6nibble6NibbleEINtNtNtNtB1g_4iter7sources5empty5EmptyB49_EE0B9_ Line | Count | Source | 745 | 2.93M | .map(|nibble| nibble.cmp(iter_node_pk_nibble)) |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE11range_innerINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1y_5slice4iter4IterNtNtB7_6nibble6NibbleEEB1p_E0B9_ Line | Count | Source | 745 | 18.2k | .map(|nibble| nibble.cmp(iter_node_pk_nibble)) |
Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE11range_innerppE0B9_ |
746 | | { |
747 | | None | Some(cmp::Ordering::Less) => { |
748 | 360k | result = cmp::Ordering::Less; |
749 | 360k | break; |
750 | | } |
751 | 2.35M | Some(cmp::Ordering::Equal) => {} |
752 | | Some(cmp::Ordering::Greater) => { |
753 | 299k | result = cmp::Ordering::Greater; |
754 | 299k | break; |
755 | | } |
756 | | } |
757 | | } |
758 | 8.11M | result |
759 | 8.11M | }; |
760 | 8.11M | |
761 | 8.11M | match pk_compare { |
762 | | cmp::Ordering::Less | cmp::Ordering::Equal => { |
763 | | // Update the value of `iter_key_nibbles_extra` to take the current value |
764 | | // of `iter` into account, as it hasn't been done yet. |
765 | 7.81M | for iter_node_pk_nibble3.40M in iter_node.partial_key.iter().cloned() { |
766 | 3.40M | if iter_key_nibbles_extra == 0 |
767 | 75.7k | && iter_node_pk_nibble == *end_key.peek().unwrap() |
768 | | { |
769 | 6.73k | let _ = end_key.next(); |
770 | 6.73k | // `iter` is already past the end bound. Return an empty range. |
771 | 6.73k | if end_key.peek().is_none() { |
772 | 11 | return either::Right(iter::empty()); |
773 | 6.72k | } |
774 | 3.39M | } else if iter_key_nibbles_extra == 0 |
775 | 69.0k | && iter_node_pk_nibble > *end_key.peek().unwrap() |
776 | | { |
777 | 816 | return either::Right(iter::empty()); |
778 | 3.39M | } else { |
779 | 3.39M | iter_key_nibbles_extra += 1; |
780 | 3.39M | } |
781 | | } |
782 | | |
783 | 7.81M | if pk_compare == cmp::Ordering::Less { |
784 | | // `iter` is strictly superior to `start_key`. `iter` is now at the |
785 | | // correct position. |
786 | 359k | break 'start_search; |
787 | 7.45M | } |
788 | | } |
789 | | cmp::Ordering::Greater => { |
790 | | // `iter` is strictly inferior to `start_key`, and all of its children will |
791 | | // also be strictly inferior to `start_key`. |
792 | | // Stop the search immediately after the current node in the parent. |
793 | 299k | let Some((parent, parent_nibble298k )) = iter_node.parent else { |
794 | 326 | return either::Right(iter::empty()); |
795 | | }; |
796 | 298k | let next_nibble = parent_nibble.checked_add(1); |
797 | 298k | if iter_key_nibbles_extra == 0 { |
798 | 18.5k | return either::Right(iter::empty()); |
799 | 280k | } |
800 | 280k | iter_key_nibbles_extra -= 1; |
801 | 280k | if iter_key_nibbles_extra == 0 && next_nibble == Some(*end_key.peek().unwrap())278k |
802 | | { |
803 | 18.3k | let _ = end_key.next(); |
804 | 18.3k | // `iter` is already past the end bound. Return an empty range. |
805 | 18.3k | if end_key.peek().is_none() { |
806 | 46 | return either::Right(iter::empty()); |
807 | 18.2k | } |
808 | 261k | } else { |
809 | 261k | iter_key_nibbles_extra += 1; |
810 | 261k | } |
811 | 280k | iter = (parent, Some(next_nibble)); |
812 | 280k | break 'start_search; |
813 | | } |
814 | | } |
815 | | |
816 | | // Remove the next nibble from `start_key` and update `iter` based on it. |
817 | 7.45M | if let Some(next_nibble7.30M ) = start_key.next() { |
818 | 7.30M | if iter_key_nibbles_extra == 0 && next_nibble == *end_key.peek().unwrap()6.41M { |
819 | 401k | let _ = end_key.next(); |
820 | 401k | // `iter` is already past the end bound. Return an empty range. |
821 | 401k | if end_key.peek().is_none() { |
822 | 1.05k | return either::Right(iter::empty()); |
823 | 400k | } |
824 | 6.90M | } else if iter_key_nibbles_extra == 0 && next_nibble > *end_key.peek().unwrap()6.01M { |
825 | 45.6k | return either::Right(iter::empty()); |
826 | 6.85M | } else { |
827 | 6.85M | iter_key_nibbles_extra += 1; |
828 | 6.85M | } |
829 | | |
830 | 7.25M | if let Some(child1.56M ) = iter_node.children[usize::from(u8::from(next_nibble))] { |
831 | 1.56M | // Update `iter` and continue searching. |
832 | 1.56M | iter = (child, None); |
833 | 1.56M | } else { |
834 | | // `iter` is strictly inferior to `start_key`. |
835 | 5.69M | iter.1 = Some(Some(next_nibble)); |
836 | 5.69M | break 'start_search; |
837 | | } |
838 | | } else { |
839 | | // `iter.0` is an exact match with `start_key`. If the starting bound is |
840 | | // `Excluded`, we don't want to start iterating at `iter` but at `next(iter)`, |
841 | | // which we do by adding a zero nibble afterwards. |
842 | 155k | debug_assert!(iter.1.is_none()); |
843 | 155k | if !start_key_is_inclusive { |
844 | 16.4k | iter.1 = Some(Some(Nibble::zero())); |
845 | 16.4k | if iter_key_nibbles_extra == 0 && *end_key.peek().unwrap() == Nibble::zero()13.7k { |
846 | 1.32k | let _ = end_key.next(); |
847 | 1.32k | // `iter` is already past the end bound. Return an empty range. |
848 | 1.32k | if end_key.peek().is_none() { |
849 | 896 | return either::Right(iter::empty()); |
850 | 431 | } |
851 | 15.1k | } else { |
852 | 15.1k | iter_key_nibbles_extra += 1; |
853 | 15.1k | } |
854 | 139k | } |
855 | | |
856 | 154k | break 'start_search; |
857 | | } |
858 | | } |
859 | | |
860 | | // `iter` is now at the correct position and we can start yielding nodes until we reach |
861 | | // the end. This is done in the iterator that is returned from the function. |
862 | | |
863 | 13.3M | either::Left(iter::from_fn(6.48M move || { |
864 | | loop { |
865 | | // `end_key` must never be empty, as otherwise the iteration has ended. |
866 | | // We return `None` instead of panicking, as it is legitimately possible to reach |
867 | | // this situation through some code paths. |
868 | 37.7M | let _ = end_key.peek()?17.2k ; |
869 | | |
870 | | // If `iter` points to an actual node, yield it and jump to the position right |
871 | | // after. |
872 | 37.7M | let Some(iter_127.8M ) = iter.1 else { |
873 | 9.95M | iter.1 = Some(Some(Nibble::zero())); |
874 | 9.95M | if iter_key_nibbles_extra == 0 && *end_key.peek().unwrap() == Nibble::zero()203k { |
875 | 14.0k | let _ = end_key.next(); |
876 | 9.94M | } else { |
877 | 9.94M | iter_key_nibbles_extra += 1; |
878 | 9.94M | } |
879 | 9.95M | return Some(iter.0); |
880 | | }; |
881 | | |
882 | 27.8M | let node = self.nodes.get(iter.0).unwrap(); |
883 | | |
884 | 9.46M | if let Some(child) = |
885 | 27.8M | iter_1.and_then(|iter_1| node.children[usize::from(u8::from(iter_1))]27.4M ) _RNCNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB1e_NtNtB9_9trie_node17MerkleValueOutputEEE11range_innerINtNtB1T_9into_iter8IntoIterNtNtB9_6nibble6NibbleEINtNtNtNtB1i_4iter7sources5empty5EmptyB4b_EEs_00Bb_ Line | Count | Source | 885 | 9.28M | iter_1.and_then(|iter_1| node.children[usize::from(u8::from(iter_1))]) |
_RNCNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructureuE11range_innerINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1A_5slice4iter4IterNtNtB9_6nibble6NibbleEEB1r_Es_00Bb_ Line | Count | Source | 885 | 18.1M | iter_1.and_then(|iter_1| node.children[usize::from(u8::from(iter_1))]) |
Unexecuted instantiation: _RNCNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE11range_innerppEs_00Bb_ |
886 | | { |
887 | | // `child` might be after the end bound if its partial key is superior or |
888 | | // equal to the `end_key`. |
889 | 12.9M | for child_pk_nibble in self.nodes.get(child).unwrap().partial_key.iter()9.46M { |
890 | 12.9M | match child_pk_nibble.cmp(end_key.peek().unwrap()) { |
891 | 595k | cmp::Ordering::Greater if iter_key_nibbles_extra == 0 => return None11.6k , |
892 | 12.1M | cmp::Ordering::Greater | cmp::Ordering::Less => { |
893 | 12.1M | iter_key_nibbles_extra += 1; |
894 | 12.1M | } |
895 | 814k | cmp::Ordering::Equal if iter_key_nibbles_extra != 0 => { |
896 | 794k | iter_key_nibbles_extra += 1; |
897 | 794k | } |
898 | | cmp::Ordering::Equal => { |
899 | 20.0k | debug_assert_eq!(iter_key_nibbles_extra, 0); |
900 | 20.0k | let _ = end_key.next(); |
901 | 20.0k | let _ = end_key.peek()?360 ; |
902 | | } |
903 | | } |
904 | | } |
905 | | |
906 | 9.45M | iter = (child, None); |
907 | 18.3M | } else if iter_key_nibbles_extra == 0 |
908 | 17.9M | || (iter_key_nibbles_extra == 1 |
909 | 5.87M | && iter_1.map_or(true, |iter_1| iter_1 > *end_key.peek().unwrap())) _RNCNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB1e_NtNtB9_9trie_node17MerkleValueOutputEEE11range_innerINtNtB1T_9into_iter8IntoIterNtNtB9_6nibble6NibbleEINtNtNtNtB1i_4iter7sources5empty5EmptyB4b_EEs_0s_0Bb_ Line | Count | Source | 909 | 5.35M | && iter_1.map_or(true, |iter_1| iter_1 > *end_key.peek().unwrap())) |
_RNCNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructureuE11range_innerINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1A_5slice4iter4IterNtNtB9_6nibble6NibbleEEB1r_Es_0s_0Bb_ Line | Count | Source | 909 | 517k | && iter_1.map_or(true, |iter_1| iter_1 > *end_key.peek().unwrap())) |
Unexecuted instantiation: _RNCNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE11range_innerppEs_0s_0Bb_ |
910 | | { |
911 | 411k | return None; |
912 | 17.9M | } else if let Some(child_index7.50M ) = iter_1.and_then(|iter_1| { |
913 | 17.5M | node.children[(usize::from(u8::from(iter_1))) |
914 | 17.5M | ..=usize::from(u8::from(if iter_key_nibbles_extra == 1 { |
915 | 5.87M | *end_key.peek().unwrap() |
916 | | } else { |
917 | 11.6M | Nibble::max() |
918 | | }))] |
919 | 17.5M | .iter() |
920 | 149M | .position(|c| c.is_some()) _RNCNCNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB9_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtBb_16TrieEntryVersionEEIB1g_NtNtBb_9trie_node17MerkleValueOutputEEE11range_innerINtNtB1V_9into_iter8IntoIterNtNtBb_6nibble6NibbleEINtNtNtNtB1k_4iter7sources5empty5EmptyB4d_EEs_0s0_00Bd_ Line | Count | Source | 920 | 41.4M | .position(|c| c.is_some()) |
_RNCNCNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB9_13TrieStructureuE11range_innerINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1C_5slice4iter4IterNtNtBb_6nibble6NibbleEEB1t_Es_0s0_00Bd_ Line | Count | Source | 920 | 108M | .position(|c| c.is_some()) |
Unexecuted instantiation: _RNCNCNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB9_13TrieStructurepE11range_innerppEs_0s0_00Bd_ |
921 | 17.9M | }) { _RNCNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB1e_NtNtB9_9trie_node17MerkleValueOutputEEE11range_innerINtNtB1T_9into_iter8IntoIterNtNtB9_6nibble6NibbleEINtNtNtNtB1i_4iter7sources5empty5EmptyB4b_EEs_0s0_0Bb_ Line | Count | Source | 912 | 6.21M | } else if let Some(child_index) = iter_1.and_then(|iter_1| { | 913 | 6.21M | node.children[(usize::from(u8::from(iter_1))) | 914 | 6.21M | ..=usize::from(u8::from(if iter_key_nibbles_extra == 1 { | 915 | 5.35M | *end_key.peek().unwrap() | 916 | | } else { | 917 | 854k | Nibble::max() | 918 | | }))] | 919 | 6.21M | .iter() | 920 | 6.21M | .position(|c| c.is_some()) | 921 | 6.21M | }) { |
_RNCNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructureuE11range_innerINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1A_5slice4iter4IterNtNtB9_6nibble6NibbleEEB1r_Es_0s0_0Bb_ Line | Count | Source | 912 | 11.3M | } else if let Some(child_index) = iter_1.and_then(|iter_1| { | 913 | 11.3M | node.children[(usize::from(u8::from(iter_1))) | 914 | 11.3M | ..=usize::from(u8::from(if iter_key_nibbles_extra == 1 { | 915 | 517k | *end_key.peek().unwrap() | 916 | | } else { | 917 | 10.8M | Nibble::max() | 918 | | }))] | 919 | 11.3M | .iter() | 920 | 11.3M | .position(|c| c.is_some()) | 921 | 11.3M | }) { |
Unexecuted instantiation: _RNCNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE11range_innerppEs_0s0_0Bb_ |
922 | 7.50M | let child_nibble = Nibble::try_from( |
923 | 7.50M | u8::try_from(usize::from(u8::from(iter_1.unwrap())) + child_index).unwrap(), |
924 | 7.50M | ) |
925 | 7.50M | .unwrap(); |
926 | 7.50M | |
927 | 7.50M | if iter_key_nibbles_extra == 1 && child_nibble == *end_key.peek().unwrap()3.00M { |
928 | 321k | iter_key_nibbles_extra = 0; |
929 | 321k | let _ = end_key.next(); |
930 | 7.18M | } |
931 | | |
932 | 7.50M | iter.1 = Some(Some(child_nibble)); |
933 | | } else { |
934 | | // `iter` has no child. Go to the parent. |
935 | 10.4M | let node = self.nodes.get(iter.0).unwrap(); |
936 | 10.4M | |
937 | 10.4M | // End the iterator if we were about to jump out of the end bound. |
938 | 10.4M | if iter_key_nibbles_extra < 2 + node.partial_key.len() { |
939 | 2.94M | return None; |
940 | 7.47M | } |
941 | | |
942 | 7.47M | let Some((parent_node_index, parent_nibble_direction)) = node.parent else { |
943 | 0 | return None; |
944 | | }; |
945 | 7.47M | iter_key_nibbles_extra -= 2; |
946 | 7.47M | iter_key_nibbles_extra -= node.partial_key.len(); |
947 | 7.47M | let next_sibling_nibble = parent_nibble_direction.checked_add(1); |
948 | 7.47M | if iter_key_nibbles_extra == 0 |
949 | 1.64M | && next_sibling_nibble == Some(*end_key.peek().unwrap()) |
950 | 147k | { |
951 | 147k | let _ = end_key.next(); |
952 | 7.32M | } else { |
953 | 7.32M | iter_key_nibbles_extra += 1; |
954 | 7.32M | } |
955 | 7.47M | iter = (parent_node_index, Some(next_sibling_nibble)); |
956 | | } |
957 | | } |
958 | 13.3M | }))6.48M _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEE11range_innerINtNtB1R_9into_iter8IntoIterNtNtB7_6nibble6NibbleEINtNtNtNtB1g_4iter7sources5empty5EmptyB49_EEs_0B9_ Line | Count | Source | 863 | 6.28M | either::Left(iter::from_fn(move || { | 864 | | loop { | 865 | | // `end_key` must never be empty, as otherwise the iteration has ended. | 866 | | // We return `None` instead of panicking, as it is legitimately possible to reach | 867 | | // this situation through some code paths. | 868 | 12.3M | let _ = end_key.peek()?0 ; | 869 | | | 870 | | // If `iter` points to an actual node, yield it and jump to the position right | 871 | | // after. | 872 | 12.3M | let Some(iter_19.28M ) = iter.1 else { | 873 | 3.09M | iter.1 = Some(Some(Nibble::zero())); | 874 | 3.09M | if iter_key_nibbles_extra == 0 && *end_key.peek().unwrap() == Nibble::zero()53.9k { | 875 | 0 | let _ = end_key.next(); | 876 | 3.09M | } else { | 877 | 3.09M | iter_key_nibbles_extra += 1; | 878 | 3.09M | } | 879 | 3.09M | return Some(iter.0); | 880 | | }; | 881 | | | 882 | 9.28M | let node = self.nodes.get(iter.0).unwrap(); | 883 | | | 884 | 2.70M | if let Some(child) = | 885 | 9.28M | iter_1.and_then(|iter_1| node.children[usize::from(u8::from(iter_1))]) | 886 | | { | 887 | | // `child` might be after the end bound if its partial key is superior or | 888 | | // equal to the `end_key`. | 889 | 7.69M | for child_pk_nibble in self.nodes.get(child).unwrap().partial_key.iter()2.70M { | 890 | 7.69M | match child_pk_nibble.cmp(end_key.peek().unwrap()) { | 891 | 0 | cmp::Ordering::Greater if iter_key_nibbles_extra == 0 => return None, | 892 | 7.20M | cmp::Ordering::Greater | cmp::Ordering::Less => { | 893 | 7.20M | iter_key_nibbles_extra += 1; | 894 | 7.20M | } | 895 | 488k | cmp::Ordering::Equal if iter_key_nibbles_extra != 0 => { | 896 | 471k | iter_key_nibbles_extra += 1; | 897 | 471k | } | 898 | | cmp::Ordering::Equal => { | 899 | 17.1k | debug_assert_eq!(iter_key_nibbles_extra, 0); | 900 | 17.1k | let _ = end_key.next(); | 901 | 17.1k | let _ = end_key.peek()?0 ; | 902 | | } | 903 | | } | 904 | | } | 905 | | | 906 | 2.70M | iter = (child, None); | 907 | 6.57M | } else if iter_key_nibbles_extra == 0 | 908 | 6.21M | || (iter_key_nibbles_extra == 1 | 909 | 5.35M | && iter_1.map_or(true, |iter_1| iter_1 > *end_key.peek().unwrap())) | 910 | | { | 911 | 360k | return None; | 912 | 6.21M | } else if let Some(child_index2.61M ) = iter_1.and_then(|iter_1| { | 913 | | node.children[(usize::from(u8::from(iter_1))) | 914 | | ..=usize::from(u8::from(if iter_key_nibbles_extra == 1 { | 915 | | *end_key.peek().unwrap() | 916 | | } else { | 917 | | Nibble::max() | 918 | | }))] | 919 | | .iter() | 920 | | .position(|c| c.is_some()) | 921 | 6.21M | }) { | 922 | 2.61M | let child_nibble = Nibble::try_from( | 923 | 2.61M | u8::try_from(usize::from(u8::from(iter_1.unwrap())) + child_index).unwrap(), | 924 | 2.61M | ) | 925 | 2.61M | .unwrap(); | 926 | 2.61M | | 927 | 2.61M | if iter_key_nibbles_extra == 1 && child_nibble == *end_key.peek().unwrap()2.57M { | 928 | 275k | iter_key_nibbles_extra = 0; | 929 | 275k | let _ = end_key.next(); | 930 | 2.34M | } | 931 | | | 932 | 2.61M | iter.1 = Some(Some(child_nibble)); | 933 | | } else { | 934 | | // `iter` has no child. Go to the parent. | 935 | 3.60M | let node = self.nodes.get(iter.0).unwrap(); | 936 | 3.60M | | 937 | 3.60M | // End the iterator if we were about to jump out of the end bound. | 938 | 3.60M | if iter_key_nibbles_extra < 2 + node.partial_key.len() { | 939 | 2.83M | return None; | 940 | 768k | } | 941 | | | 942 | 768k | let Some((parent_node_index, parent_nibble_direction)) = node.parent else { | 943 | 0 | return None; | 944 | | }; | 945 | 768k | iter_key_nibbles_extra -= 2; | 946 | 768k | iter_key_nibbles_extra -= node.partial_key.len(); | 947 | 768k | let next_sibling_nibble = parent_nibble_direction.checked_add(1); | 948 | 768k | if iter_key_nibbles_extra == 0 | 949 | 731k | && next_sibling_nibble == Some(*end_key.peek().unwrap()) | 950 | 48.3k | { | 951 | 48.3k | let _ = end_key.next(); | 952 | 720k | } else { | 953 | 720k | iter_key_nibbles_extra += 1; | 954 | 720k | } | 955 | 768k | iter = (parent_node_index, Some(next_sibling_nibble)); | 956 | | } | 957 | | } | 958 | 6.28M | })) |
_RNCINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuE11range_innerINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1y_5slice4iter4IterNtNtB7_6nibble6NibbleEEB1p_Es_0B9_ Line | Count | Source | 863 | 7.05M | either::Left(iter::from_fn(move || { | 864 | | loop { | 865 | | // `end_key` must never be empty, as otherwise the iteration has ended. | 866 | | // We return `None` instead of panicking, as it is legitimately possible to reach | 867 | | // this situation through some code paths. | 868 | 25.3M | let _ = end_key.peek()?17.2k ; | 869 | | | 870 | | // If `iter` points to an actual node, yield it and jump to the position right | 871 | | // after. | 872 | 25.3M | let Some(iter_118.5M ) = iter.1 else { | 873 | 6.85M | iter.1 = Some(Some(Nibble::zero())); | 874 | 6.85M | if iter_key_nibbles_extra == 0 && *end_key.peek().unwrap() == Nibble::zero()149k { | 875 | 14.0k | let _ = end_key.next(); | 876 | 6.84M | } else { | 877 | 6.84M | iter_key_nibbles_extra += 1; | 878 | 6.84M | } | 879 | 6.85M | return Some(iter.0); | 880 | | }; | 881 | | | 882 | 18.5M | let node = self.nodes.get(iter.0).unwrap(); | 883 | | | 884 | 6.76M | if let Some(child) = | 885 | 18.5M | iter_1.and_then(|iter_1| node.children[usize::from(u8::from(iter_1))]) | 886 | | { | 887 | | // `child` might be after the end bound if its partial key is superior or | 888 | | // equal to the `end_key`. | 889 | 6.76M | for child_pk_nibble5.25M in self.nodes.get(child).unwrap().partial_key.iter() { | 890 | 5.25M | match child_pk_nibble.cmp(end_key.peek().unwrap()) { | 891 | 595k | cmp::Ordering::Greater if iter_key_nibbles_extra == 0 => return None11.6k , | 892 | 4.91M | cmp::Ordering::Greater | cmp::Ordering::Less => { | 893 | 4.91M | iter_key_nibbles_extra += 1; | 894 | 4.91M | } | 895 | 326k | cmp::Ordering::Equal if iter_key_nibbles_extra != 0 => { | 896 | 323k | iter_key_nibbles_extra += 1; | 897 | 323k | } | 898 | | cmp::Ordering::Equal => { | 899 | 2.82k | debug_assert_eq!(iter_key_nibbles_extra, 0); | 900 | 2.82k | let _ = end_key.next(); | 901 | 2.82k | let _ = end_key.peek()?360 ; | 902 | | } | 903 | | } | 904 | | } | 905 | | | 906 | 6.74M | iter = (child, None); | 907 | 11.7M | } else if iter_key_nibbles_extra == 0 | 908 | 11.7M | || (iter_key_nibbles_extra == 1 | 909 | 517k | && iter_1.map_or(true, |iter_1| iter_1 > *end_key.peek().unwrap())) | 910 | | { | 911 | 50.4k | return None; | 912 | 11.7M | } else if let Some(child_index4.88M ) = iter_1.and_then(|iter_1| { | 913 | | node.children[(usize::from(u8::from(iter_1))) | 914 | | ..=usize::from(u8::from(if iter_key_nibbles_extra == 1 { | 915 | | *end_key.peek().unwrap() | 916 | | } else { | 917 | | Nibble::max() | 918 | | }))] | 919 | | .iter() | 920 | | .position(|c| c.is_some()) | 921 | 11.7M | }) { | 922 | 4.88M | let child_nibble = Nibble::try_from( | 923 | 4.88M | u8::try_from(usize::from(u8::from(iter_1.unwrap())) + child_index).unwrap(), | 924 | 4.88M | ) | 925 | 4.88M | .unwrap(); | 926 | 4.88M | | 927 | 4.88M | if iter_key_nibbles_extra == 1 && child_nibble == *end_key.peek().unwrap()430k { | 928 | 46.2k | iter_key_nibbles_extra = 0; | 929 | 46.2k | let _ = end_key.next(); | 930 | 4.83M | } | 931 | | | 932 | 4.88M | iter.1 = Some(Some(child_nibble)); | 933 | | } else { | 934 | | // `iter` has no child. Go to the parent. | 935 | 6.82M | let node = self.nodes.get(iter.0).unwrap(); | 936 | 6.82M | | 937 | 6.82M | // End the iterator if we were about to jump out of the end bound. | 938 | 6.82M | if iter_key_nibbles_extra < 2 + node.partial_key.len() { | 939 | 118k | return None; | 940 | 6.70M | } | 941 | | | 942 | 6.70M | let Some((parent_node_index, parent_nibble_direction)) = node.parent else { | 943 | 0 | return None; | 944 | | }; | 945 | 6.70M | iter_key_nibbles_extra -= 2; | 946 | 6.70M | iter_key_nibbles_extra -= node.partial_key.len(); | 947 | 6.70M | let next_sibling_nibble = parent_nibble_direction.checked_add(1); | 948 | 6.70M | if iter_key_nibbles_extra == 0 | 949 | 909k | && next_sibling_nibble == Some(*end_key.peek().unwrap()) | 950 | 98.6k | { | 951 | 98.6k | let _ = end_key.next(); | 952 | 6.60M | } else { | 953 | 6.60M | iter_key_nibbles_extra += 1; | 954 | 6.60M | } | 955 | 6.70M | iter = (parent_node_index, Some(next_sibling_nibble)); | 956 | | } | 957 | | } | 958 | 7.05M | })) |
Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE11range_innerppEs_0B9_ |
959 | 6.56M | } _RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB5_16TrieEntryVersionEEIB1a_NtNtB5_9trie_node17MerkleValueOutputEEE11range_innerINtNtB1P_9into_iter8IntoIterNtNtB5_6nibble6NibbleEINtNtNtNtB1e_4iter7sources5empty5EmptyB47_EEB7_ Line | Count | Source | 668 | 6.30M | fn range_inner<'a>( | 669 | 6.30M | &'a self, | 670 | 6.30M | start_bound: ops::Bound<impl Iterator<Item = Nibble>>, | 671 | 6.30M | end_bound: ops::Bound<impl Iterator<Item = Nibble> + 'a>, | 672 | 6.30M | ) -> impl Iterator<Item = usize> + 'a { | 673 | | // Start by processing the end bound to obtain an "end key". | 674 | | // This end key is always assumed to be excluded. In other words, only keys strictly | 675 | | // inferior to the end key are returned. If the user provides `Included`, we modify the key | 676 | | // and append a dummy `0` nibble at the end of it. If the user provides `Unbounded`, we use | 677 | | // an infinite-sized key so that every finite key is always inferior to it. | 678 | | // | 679 | | // The algorithm later down this function will pop nibbles from the start of `end_key`. | 680 | | // Because `end_key` is always excluded, this iterator must always contain at least one | 681 | | // nibble, otherwise the iteration should have ended. | 682 | 6.30M | let mut end_key = match end_bound { | 683 | 6.30M | ops::Bound::Unbounded => either::Left(iter::repeat(Nibble::max())), | 684 | 0 | ops::Bound::Excluded(end_key) => either::Right(end_key.chain(None)), | 685 | 0 | ops::Bound::Included(end_key) => either::Right(end_key.chain(Some(Nibble::zero()))), | 686 | | } | 687 | 6.30M | .peekable(); | 688 | 6.30M | | 689 | 6.30M | // The user passed `Excluded(&[])`. Return an empty range. | 690 | 6.30M | if end_key.peek().is_none() { | 691 | 0 | return either::Right(iter::empty()); | 692 | 6.30M | } | 693 | | | 694 | | // The code below creates a variable named `iter`. This `iter` represents the cursor | 695 | | // where the iterator is. | 696 | | // `iter` also contains an optional nibble. If this optional nibble is `None`, the | 697 | | // iteration is currently at the node itself. If it is `Some`, the iteration isn't at the | 698 | | // node itself but at its child of the given nibble (which potentially doesn't exist). | 699 | | // If it is `Some(None)`, then the iteration is right after the last children of the node. | 700 | | // In other words, `Some(None)` represents an overflow. | 701 | 6.30M | let mut iter: (usize, Option<Option<Nibble>>) = match self.root_index { | 702 | 6.30M | Some(idx) => (idx, None), | 703 | | None => { | 704 | | // Trie is empty. Special case. | 705 | 0 | return either::Right(iter::empty()); | 706 | | } | 707 | | }; | 708 | | | 709 | | // Equal to `len(key(iter)) - len(key(iter) ∩ end_key)`. In other words, the number of | 710 | | // nibbles at the end of `iter`'s key that do not match the end key. This also includes | 711 | | // the optional nibble within `iter` if any. | 712 | 6.30M | let mut iter_key_nibbles_extra: usize = 0; | 713 | | | 714 | | // Transform `start_bound` into something more simple to process. | 715 | 6.30M | let (mut start_key, start_key_is_inclusive) = match start_bound { | 716 | 0 | ops::Bound::Unbounded => (either::Right(iter::empty()), true), | 717 | 6.30M | ops::Bound::Included(k) => (either::Left(k), true), | 718 | 0 | ops::Bound::Excluded(k) => (either::Left(k), false), | 719 | | }; | 720 | | | 721 | | // Iterate down the tree, updating the variables above. At each iteration, one of the | 722 | | // three following is true: | 723 | | // | 724 | | // - `iter` is inferior or inferior or equal (depending on `start_key_is_inclusive`) to | 725 | | // `start_key`. | 726 | | // - `iter` is the first node that is superior or strictly superior (depending on | 727 | | // `start_key_is_inclusive`) to `start_key`. | 728 | | // - `iter` points to a non-existing node that is inferior/inferior-or-equal to | 729 | | // `start_key`, but is right before the first node that is superior/strictly superior to | 730 | | // `start_key`. | 731 | | // | 732 | | // As soon as we reach one of the last two conditions, we stop iterating, as it means | 733 | | // that `iter` is at the correct position. | 734 | 7.82M | 'start_search: loop { | 735 | 7.82M | debug_assert!(iter.1.is_none()); | 736 | 7.82M | let iter_node = self.nodes.get(iter.0).unwrap(); | 737 | | | 738 | | // Compare the nibbles at the front of `start_key` with the ones of `iter_node`. | 739 | | // Consumes the nibbles at the start of `start_key`. | 740 | 7.82M | let pk_compare = { | 741 | 7.82M | let mut result = cmp::Ordering::Equal; | 742 | 7.82M | for iter_node_pk_nibble2.99M in iter_node.partial_key.iter() { | 743 | 2.99M | match start_key | 744 | 2.99M | .next() | 745 | 2.99M | .map(|nibble| nibble.cmp(iter_node_pk_nibble)) | 746 | | { | 747 | | None | Some(cmp::Ordering::Less) => { | 748 | 346k | result = cmp::Ordering::Less; | 749 | 346k | break; | 750 | | } | 751 | 2.35M | Some(cmp::Ordering::Equal) => {} | 752 | | Some(cmp::Ordering::Greater) => { | 753 | 290k | result = cmp::Ordering::Greater; | 754 | 290k | break; | 755 | | } | 756 | | } | 757 | | } | 758 | 7.82M | result | 759 | 7.82M | }; | 760 | 7.82M | | 761 | 7.82M | match pk_compare { | 762 | | cmp::Ordering::Less | cmp::Ordering::Equal => { | 763 | | // Update the value of `iter_key_nibbles_extra` to take the current value | 764 | | // of `iter` into account, as it hasn't been done yet. | 765 | 7.53M | for iter_node_pk_nibble3.38M in iter_node.partial_key.iter().cloned() { | 766 | 3.38M | if iter_key_nibbles_extra == 0 | 767 | 73.6k | && iter_node_pk_nibble == *end_key.peek().unwrap() | 768 | | { | 769 | 6.54k | let _ = end_key.next(); | 770 | 6.54k | // `iter` is already past the end bound. Return an empty range. | 771 | 6.54k | if end_key.peek().is_none() { | 772 | 0 | return either::Right(iter::empty()); | 773 | 6.54k | } | 774 | 3.37M | } else if iter_key_nibbles_extra == 0 | 775 | 67.0k | && iter_node_pk_nibble > *end_key.peek().unwrap() | 776 | | { | 777 | 0 | return either::Right(iter::empty()); | 778 | 3.37M | } else { | 779 | 3.37M | iter_key_nibbles_extra += 1; | 780 | 3.37M | } | 781 | | } | 782 | | | 783 | 7.53M | if pk_compare == cmp::Ordering::Less { | 784 | | // `iter` is strictly superior to `start_key`. `iter` is now at the | 785 | | // correct position. | 786 | 346k | break 'start_search; | 787 | 7.18M | } | 788 | | } | 789 | | cmp::Ordering::Greater => { | 790 | | // `iter` is strictly inferior to `start_key`, and all of its children will | 791 | | // also be strictly inferior to `start_key`. | 792 | | // Stop the search immediately after the current node in the parent. | 793 | 290k | let Some((parent, parent_nibble)) = iter_node.parent else { | 794 | 0 | return either::Right(iter::empty()); | 795 | | }; | 796 | 290k | let next_nibble = parent_nibble.checked_add(1); | 797 | 290k | if iter_key_nibbles_extra == 0 { | 798 | 17.8k | return either::Right(iter::empty()); | 799 | 272k | } | 800 | 272k | iter_key_nibbles_extra -= 1; | 801 | 272k | if iter_key_nibbles_extra == 0 && next_nibble == Some(*end_key.peek().unwrap())271k | 802 | | { | 803 | 17.6k | let _ = end_key.next(); | 804 | 17.6k | // `iter` is already past the end bound. Return an empty range. | 805 | 17.6k | if end_key.peek().is_none() { | 806 | 0 | return either::Right(iter::empty()); | 807 | 17.6k | } | 808 | 255k | } else { | 809 | 255k | iter_key_nibbles_extra += 1; | 810 | 255k | } | 811 | 272k | iter = (parent, Some(next_nibble)); | 812 | 272k | break 'start_search; | 813 | | } | 814 | | } | 815 | | | 816 | | // Remove the next nibble from `start_key` and update `iter` based on it. | 817 | 7.18M | if let Some(next_nibble7.14M ) = start_key.next() { | 818 | 7.14M | if iter_key_nibbles_extra == 0 && next_nibble == *end_key.peek().unwrap()6.28M { | 819 | 392k | let _ = end_key.next(); | 820 | 392k | // `iter` is already past the end bound. Return an empty range. | 821 | 392k | if end_key.peek().is_none() { | 822 | 0 | return either::Right(iter::empty()); | 823 | 392k | } | 824 | 6.75M | } else if iter_key_nibbles_extra == 0 && next_nibble > *end_key.peek().unwrap()5.88M { | 825 | 0 | return either::Right(iter::empty()); | 826 | 6.75M | } else { | 827 | 6.75M | iter_key_nibbles_extra += 1; | 828 | 6.75M | } | 829 | | | 830 | 7.14M | if let Some(child1.51M ) = iter_node.children[usize::from(u8::from(next_nibble))] { | 831 | 1.51M | // Update `iter` and continue searching. | 832 | 1.51M | iter = (child, None); | 833 | 1.51M | } else { | 834 | | // `iter` is strictly inferior to `start_key`. | 835 | 5.62M | iter.1 = Some(Some(next_nibble)); | 836 | 5.62M | break 'start_search; | 837 | | } | 838 | | } else { | 839 | | // `iter.0` is an exact match with `start_key`. If the starting bound is | 840 | | // `Excluded`, we don't want to start iterating at `iter` but at `next(iter)`, | 841 | | // which we do by adding a zero nibble afterwards. | 842 | 41.0k | debug_assert!(iter.1.is_none()); | 843 | 41.0k | if !start_key_is_inclusive { | 844 | 0 | iter.1 = Some(Some(Nibble::zero())); | 845 | 0 | if iter_key_nibbles_extra == 0 && *end_key.peek().unwrap() == Nibble::zero() { | 846 | 0 | let _ = end_key.next(); | 847 | 0 | // `iter` is already past the end bound. Return an empty range. | 848 | 0 | if end_key.peek().is_none() { | 849 | 0 | return either::Right(iter::empty()); | 850 | 0 | } | 851 | 0 | } else { | 852 | 0 | iter_key_nibbles_extra += 1; | 853 | 0 | } | 854 | 41.0k | } | 855 | | | 856 | 41.0k | break 'start_search; | 857 | | } | 858 | | } | 859 | | | 860 | | // `iter` is now at the correct position and we can start yielding nodes until we reach | 861 | | // the end. This is done in the iterator that is returned from the function. | 862 | | | 863 | 6.28M | either::Left(iter::from_fn(move || { | 864 | | loop { | 865 | | // `end_key` must never be empty, as otherwise the iteration has ended. | 866 | | // We return `None` instead of panicking, as it is legitimately possible to reach | 867 | | // this situation through some code paths. | 868 | | let _ = end_key.peek()?; | 869 | | | 870 | | // If `iter` points to an actual node, yield it and jump to the position right | 871 | | // after. | 872 | | let Some(iter_1) = iter.1 else { | 873 | | iter.1 = Some(Some(Nibble::zero())); | 874 | | if iter_key_nibbles_extra == 0 && *end_key.peek().unwrap() == Nibble::zero() { | 875 | | let _ = end_key.next(); | 876 | | } else { | 877 | | iter_key_nibbles_extra += 1; | 878 | | } | 879 | | return Some(iter.0); | 880 | | }; | 881 | | | 882 | | let node = self.nodes.get(iter.0).unwrap(); | 883 | | | 884 | | if let Some(child) = | 885 | | iter_1.and_then(|iter_1| node.children[usize::from(u8::from(iter_1))]) | 886 | | { | 887 | | // `child` might be after the end bound if its partial key is superior or | 888 | | // equal to the `end_key`. | 889 | | for child_pk_nibble in self.nodes.get(child).unwrap().partial_key.iter() { | 890 | | match child_pk_nibble.cmp(end_key.peek().unwrap()) { | 891 | | cmp::Ordering::Greater if iter_key_nibbles_extra == 0 => return None, | 892 | | cmp::Ordering::Greater | cmp::Ordering::Less => { | 893 | | iter_key_nibbles_extra += 1; | 894 | | } | 895 | | cmp::Ordering::Equal if iter_key_nibbles_extra != 0 => { | 896 | | iter_key_nibbles_extra += 1; | 897 | | } | 898 | | cmp::Ordering::Equal => { | 899 | | debug_assert_eq!(iter_key_nibbles_extra, 0); | 900 | | let _ = end_key.next(); | 901 | | let _ = end_key.peek()?; | 902 | | } | 903 | | } | 904 | | } | 905 | | | 906 | | iter = (child, None); | 907 | | } else if iter_key_nibbles_extra == 0 | 908 | | || (iter_key_nibbles_extra == 1 | 909 | | && iter_1.map_or(true, |iter_1| iter_1 > *end_key.peek().unwrap())) | 910 | | { | 911 | | return None; | 912 | | } else if let Some(child_index) = iter_1.and_then(|iter_1| { | 913 | | node.children[(usize::from(u8::from(iter_1))) | 914 | | ..=usize::from(u8::from(if iter_key_nibbles_extra == 1 { | 915 | | *end_key.peek().unwrap() | 916 | | } else { | 917 | | Nibble::max() | 918 | | }))] | 919 | | .iter() | 920 | | .position(|c| c.is_some()) | 921 | | }) { | 922 | | let child_nibble = Nibble::try_from( | 923 | | u8::try_from(usize::from(u8::from(iter_1.unwrap())) + child_index).unwrap(), | 924 | | ) | 925 | | .unwrap(); | 926 | | | 927 | | if iter_key_nibbles_extra == 1 && child_nibble == *end_key.peek().unwrap() { | 928 | | iter_key_nibbles_extra = 0; | 929 | | let _ = end_key.next(); | 930 | | } | 931 | | | 932 | | iter.1 = Some(Some(child_nibble)); | 933 | | } else { | 934 | | // `iter` has no child. Go to the parent. | 935 | | let node = self.nodes.get(iter.0).unwrap(); | 936 | | | 937 | | // End the iterator if we were about to jump out of the end bound. | 938 | | if iter_key_nibbles_extra < 2 + node.partial_key.len() { | 939 | | return None; | 940 | | } | 941 | | | 942 | | let Some((parent_node_index, parent_nibble_direction)) = node.parent else { | 943 | | return None; | 944 | | }; | 945 | | iter_key_nibbles_extra -= 2; | 946 | | iter_key_nibbles_extra -= node.partial_key.len(); | 947 | | let next_sibling_nibble = parent_nibble_direction.checked_add(1); | 948 | | if iter_key_nibbles_extra == 0 | 949 | | && next_sibling_nibble == Some(*end_key.peek().unwrap()) | 950 | | { | 951 | | let _ = end_key.next(); | 952 | | } else { | 953 | | iter_key_nibbles_extra += 1; | 954 | | } | 955 | | iter = (parent_node_index, Some(next_sibling_nibble)); | 956 | | } | 957 | | } | 958 | 6.28M | })) | 959 | 6.30M | } |
_RINvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB3_13TrieStructureuE11range_innerINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1w_5slice4iter4IterNtNtB5_6nibble6NibbleEEB1n_EB7_ Line | Count | Source | 668 | 262k | fn range_inner<'a>( | 669 | 262k | &'a self, | 670 | 262k | start_bound: ops::Bound<impl Iterator<Item = Nibble>>, | 671 | 262k | end_bound: ops::Bound<impl Iterator<Item = Nibble> + 'a>, | 672 | 262k | ) -> impl Iterator<Item = usize> + 'a { | 673 | | // Start by processing the end bound to obtain an "end key". | 674 | | // This end key is always assumed to be excluded. In other words, only keys strictly | 675 | | // inferior to the end key are returned. If the user provides `Included`, we modify the key | 676 | | // and append a dummy `0` nibble at the end of it. If the user provides `Unbounded`, we use | 677 | | // an infinite-sized key so that every finite key is always inferior to it. | 678 | | // | 679 | | // The algorithm later down this function will pop nibbles from the start of `end_key`. | 680 | | // Because `end_key` is always excluded, this iterator must always contain at least one | 681 | | // nibble, otherwise the iteration should have ended. | 682 | 262k | let mut end_key = match end_bound { | 683 | 87.7k | ops::Bound::Unbounded => either::Left(iter::repeat(Nibble::max())), | 684 | 87.3k | ops::Bound::Excluded(end_key) => either::Right(end_key.chain(None)), | 685 | 87.0k | ops::Bound::Included(end_key) => either::Right(end_key.chain(Some(Nibble::zero()))), | 686 | | } | 687 | 262k | .peekable(); | 688 | 262k | | 689 | 262k | // The user passed `Excluded(&[])`. Return an empty range. | 690 | 262k | if end_key.peek().is_none() { | 691 | 14.5k | return either::Right(iter::empty()); | 692 | 247k | } | 693 | | | 694 | | // The code below creates a variable named `iter`. This `iter` represents the cursor | 695 | | // where the iterator is. | 696 | | // `iter` also contains an optional nibble. If this optional nibble is `None`, the | 697 | | // iteration is currently at the node itself. If it is `Some`, the iteration isn't at the | 698 | | // node itself but at its child of the given nibble (which potentially doesn't exist). | 699 | | // If it is `Some(None)`, then the iteration is right after the last children of the node. | 700 | | // In other words, `Some(None)` represents an overflow. | 701 | 247k | let mut iter: (usize, Option<Option<Nibble>>)247k = match self.root_index { | 702 | 247k | Some(idx) => (idx, None), | 703 | | None => { | 704 | | // Trie is empty. Special case. | 705 | 367 | return either::Right(iter::empty()); | 706 | | } | 707 | | }; | 708 | | | 709 | | // Equal to `len(key(iter)) - len(key(iter) ∩ end_key)`. In other words, the number of | 710 | | // nibbles at the end of `iter`'s key that do not match the end key. This also includes | 711 | | // the optional nibble within `iter` if any. | 712 | 247k | let mut iter_key_nibbles_extra: usize = 0; | 713 | | | 714 | | // Transform `start_bound` into something more simple to process. | 715 | 247k | let (mut start_key, start_key_is_inclusive) = match start_bound { | 716 | 82.0k | ops::Bound::Unbounded => (either::Right(iter::empty()), true), | 717 | 82.2k | ops::Bound::Included(k) => (either::Left(k), true), | 718 | 82.9k | ops::Bound::Excluded(k) => (either::Left(k), false), | 719 | | }; | 720 | | | 721 | | // Iterate down the tree, updating the variables above. At each iteration, one of the | 722 | | // three following is true: | 723 | | // | 724 | | // - `iter` is inferior or inferior or equal (depending on `start_key_is_inclusive`) to | 725 | | // `start_key`. | 726 | | // - `iter` is the first node that is superior or strictly superior (depending on | 727 | | // `start_key_is_inclusive`) to `start_key`. | 728 | | // - `iter` points to a non-existing node that is inferior/inferior-or-equal to | 729 | | // `start_key`, but is right before the first node that is superior/strictly superior to | 730 | | // `start_key`. | 731 | | // | 732 | | // As soon as we reach one of the last two conditions, we stop iterating, as it means | 733 | | // that `iter` is at the correct position. | 734 | 296k | 'start_search: loop { | 735 | 296k | debug_assert!(iter.1.is_none()); | 736 | 296k | let iter_node = self.nodes.get(iter.0).unwrap(); | 737 | | | 738 | | // Compare the nibbles at the front of `start_key` with the ones of `iter_node`. | 739 | | // Consumes the nibbles at the start of `start_key`. | 740 | 296k | let pk_compare = { | 741 | 296k | let mut result = cmp::Ordering::Equal; | 742 | 296k | for iter_node_pk_nibble23.4k in iter_node.partial_key.iter() { | 743 | 23.4k | match start_key | 744 | 23.4k | .next() | 745 | 23.4k | .map(|nibble| nibble.cmp(iter_node_pk_nibble)) | 746 | | { | 747 | | None | Some(cmp::Ordering::Less) => { | 748 | 13.7k | result = cmp::Ordering::Less; | 749 | 13.7k | break; | 750 | | } | 751 | 1.13k | Some(cmp::Ordering::Equal) => {} | 752 | | Some(cmp::Ordering::Greater) => { | 753 | 8.60k | result = cmp::Ordering::Greater; | 754 | 8.60k | break; | 755 | | } | 756 | | } | 757 | | } | 758 | 296k | result | 759 | 296k | }; | 760 | 296k | | 761 | 296k | match pk_compare { | 762 | | cmp::Ordering::Less | cmp::Ordering::Equal => { | 763 | | // Update the value of `iter_key_nibbles_extra` to take the current value | 764 | | // of `iter` into account, as it hasn't been done yet. | 765 | 287k | for iter_node_pk_nibble20.9k in iter_node.partial_key.iter().cloned() { | 766 | 20.9k | if iter_key_nibbles_extra == 0 | 767 | 2.18k | && iter_node_pk_nibble == *end_key.peek().unwrap() | 768 | | { | 769 | 188 | let _ = end_key.next(); | 770 | 188 | // `iter` is already past the end bound. Return an empty range. | 771 | 188 | if end_key.peek().is_none() { | 772 | 11 | return either::Right(iter::empty()); | 773 | 177 | } | 774 | 20.7k | } else if iter_key_nibbles_extra == 0 | 775 | 1.99k | && iter_node_pk_nibble > *end_key.peek().unwrap() | 776 | | { | 777 | 816 | return either::Right(iter::empty()); | 778 | 19.9k | } else { | 779 | 19.9k | iter_key_nibbles_extra += 1; | 780 | 19.9k | } | 781 | | } | 782 | | | 783 | 287k | if pk_compare == cmp::Ordering::Less { | 784 | | // `iter` is strictly superior to `start_key`. `iter` is now at the | 785 | | // correct position. | 786 | 12.9k | break 'start_search; | 787 | 274k | } | 788 | | } | 789 | | cmp::Ordering::Greater => { | 790 | | // `iter` is strictly inferior to `start_key`, and all of its children will | 791 | | // also be strictly inferior to `start_key`. | 792 | | // Stop the search immediately after the current node in the parent. | 793 | 8.60k | let Some((parent, parent_nibble8.28k )) = iter_node.parent else { | 794 | 326 | return either::Right(iter::empty()); | 795 | | }; | 796 | 8.28k | let next_nibble = parent_nibble.checked_add(1); | 797 | 8.28k | if iter_key_nibbles_extra == 0 { | 798 | 663 | return either::Right(iter::empty()); | 799 | 7.61k | } | 800 | 7.61k | iter_key_nibbles_extra -= 1; | 801 | 7.61k | if iter_key_nibbles_extra == 0 && next_nibble == Some(*end_key.peek().unwrap())7.05k | 802 | | { | 803 | 652 | let _ = end_key.next(); | 804 | 652 | // `iter` is already past the end bound. Return an empty range. | 805 | 652 | if end_key.peek().is_none() { | 806 | 46 | return either::Right(iter::empty()); | 807 | 606 | } | 808 | 6.96k | } else { | 809 | 6.96k | iter_key_nibbles_extra += 1; | 810 | 6.96k | } | 811 | 7.57k | iter = (parent, Some(next_nibble)); | 812 | 7.57k | break 'start_search; | 813 | | } | 814 | | } | 815 | | | 816 | | // Remove the next nibble from `start_key` and update `iter` based on it. | 817 | 274k | if let Some(next_nibble159k ) = start_key.next() { | 818 | 159k | if iter_key_nibbles_extra == 0 && next_nibble == *end_key.peek().unwrap()138k { | 819 | 8.84k | let _ = end_key.next(); | 820 | 8.84k | // `iter` is already past the end bound. Return an empty range. | 821 | 8.84k | if end_key.peek().is_none() { | 822 | 1.05k | return either::Right(iter::empty()); | 823 | 7.79k | } | 824 | 150k | } else if iter_key_nibbles_extra == 0 && next_nibble > *end_key.peek().unwrap()129k { | 825 | 45.6k | return either::Right(iter::empty()); | 826 | 105k | } else { | 827 | 105k | iter_key_nibbles_extra += 1; | 828 | 105k | } | 829 | | | 830 | 112k | if let Some(child49.3k ) = iter_node.children[usize::from(u8::from(next_nibble))] { | 831 | 49.3k | // Update `iter` and continue searching. | 832 | 49.3k | iter = (child, None); | 833 | 49.3k | } else { | 834 | | // `iter` is strictly inferior to `start_key`. | 835 | 63.5k | iter.1 = Some(Some(next_nibble)); | 836 | 63.5k | break 'start_search; | 837 | | } | 838 | | } else { | 839 | | // `iter.0` is an exact match with `start_key`. If the starting bound is | 840 | | // `Excluded`, we don't want to start iterating at `iter` but at `next(iter)`, | 841 | | // which we do by adding a zero nibble afterwards. | 842 | 114k | debug_assert!(iter.1.is_none()); | 843 | 114k | if !start_key_is_inclusive { | 844 | 16.4k | iter.1 = Some(Some(Nibble::zero())); | 845 | 16.4k | if iter_key_nibbles_extra == 0 && *end_key.peek().unwrap() == Nibble::zero()13.7k { | 846 | 1.32k | let _ = end_key.next(); | 847 | 1.32k | // `iter` is already past the end bound. Return an empty range. | 848 | 1.32k | if end_key.peek().is_none() { | 849 | 896 | return either::Right(iter::empty()); | 850 | 431 | } | 851 | 15.1k | } else { | 852 | 15.1k | iter_key_nibbles_extra += 1; | 853 | 15.1k | } | 854 | 98.0k | } | 855 | | | 856 | 113k | break 'start_search; | 857 | | } | 858 | | } | 859 | | | 860 | | // `iter` is now at the correct position and we can start yielding nodes until we reach | 861 | | // the end. This is done in the iterator that is returned from the function. | 862 | | | 863 | 197k | either::Left(iter::from_fn(move || { | 864 | | loop { | 865 | | // `end_key` must never be empty, as otherwise the iteration has ended. | 866 | | // We return `None` instead of panicking, as it is legitimately possible to reach | 867 | | // this situation through some code paths. | 868 | | let _ = end_key.peek()?; | 869 | | | 870 | | // If `iter` points to an actual node, yield it and jump to the position right | 871 | | // after. | 872 | | let Some(iter_1) = iter.1 else { | 873 | | iter.1 = Some(Some(Nibble::zero())); | 874 | | if iter_key_nibbles_extra == 0 && *end_key.peek().unwrap() == Nibble::zero() { | 875 | | let _ = end_key.next(); | 876 | | } else { | 877 | | iter_key_nibbles_extra += 1; | 878 | | } | 879 | | return Some(iter.0); | 880 | | }; | 881 | | | 882 | | let node = self.nodes.get(iter.0).unwrap(); | 883 | | | 884 | | if let Some(child) = | 885 | | iter_1.and_then(|iter_1| node.children[usize::from(u8::from(iter_1))]) | 886 | | { | 887 | | // `child` might be after the end bound if its partial key is superior or | 888 | | // equal to the `end_key`. | 889 | | for child_pk_nibble in self.nodes.get(child).unwrap().partial_key.iter() { | 890 | | match child_pk_nibble.cmp(end_key.peek().unwrap()) { | 891 | | cmp::Ordering::Greater if iter_key_nibbles_extra == 0 => return None, | 892 | | cmp::Ordering::Greater | cmp::Ordering::Less => { | 893 | | iter_key_nibbles_extra += 1; | 894 | | } | 895 | | cmp::Ordering::Equal if iter_key_nibbles_extra != 0 => { | 896 | | iter_key_nibbles_extra += 1; | 897 | | } | 898 | | cmp::Ordering::Equal => { | 899 | | debug_assert_eq!(iter_key_nibbles_extra, 0); | 900 | | let _ = end_key.next(); | 901 | | let _ = end_key.peek()?; | 902 | | } | 903 | | } | 904 | | } | 905 | | | 906 | | iter = (child, None); | 907 | | } else if iter_key_nibbles_extra == 0 | 908 | | || (iter_key_nibbles_extra == 1 | 909 | | && iter_1.map_or(true, |iter_1| iter_1 > *end_key.peek().unwrap())) | 910 | | { | 911 | | return None; | 912 | | } else if let Some(child_index) = iter_1.and_then(|iter_1| { | 913 | | node.children[(usize::from(u8::from(iter_1))) | 914 | | ..=usize::from(u8::from(if iter_key_nibbles_extra == 1 { | 915 | | *end_key.peek().unwrap() | 916 | | } else { | 917 | | Nibble::max() | 918 | | }))] | 919 | | .iter() | 920 | | .position(|c| c.is_some()) | 921 | | }) { | 922 | | let child_nibble = Nibble::try_from( | 923 | | u8::try_from(usize::from(u8::from(iter_1.unwrap())) + child_index).unwrap(), | 924 | | ) | 925 | | .unwrap(); | 926 | | | 927 | | if iter_key_nibbles_extra == 1 && child_nibble == *end_key.peek().unwrap() { | 928 | | iter_key_nibbles_extra = 0; | 929 | | let _ = end_key.next(); | 930 | | } | 931 | | | 932 | | iter.1 = Some(Some(child_nibble)); | 933 | | } else { | 934 | | // `iter` has no child. Go to the parent. | 935 | | let node = self.nodes.get(iter.0).unwrap(); | 936 | | | 937 | | // End the iterator if we were about to jump out of the end bound. | 938 | | if iter_key_nibbles_extra < 2 + node.partial_key.len() { | 939 | | return None; | 940 | | } | 941 | | | 942 | | let Some((parent_node_index, parent_nibble_direction)) = node.parent else { | 943 | | return None; | 944 | | }; | 945 | | iter_key_nibbles_extra -= 2; | 946 | | iter_key_nibbles_extra -= node.partial_key.len(); | 947 | | let next_sibling_nibble = parent_nibble_direction.checked_add(1); | 948 | | if iter_key_nibbles_extra == 0 | 949 | | && next_sibling_nibble == Some(*end_key.peek().unwrap()) | 950 | | { | 951 | | let _ = end_key.next(); | 952 | | } else { | 953 | | iter_key_nibbles_extra += 1; | 954 | | } | 955 | | iter = (parent_node_index, Some(next_sibling_nibble)); | 956 | | } | 957 | | } | 958 | 197k | })) | 959 | 262k | } |
Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB3_13TrieStructurepE11range_innerppEB7_ |
960 | | |
961 | | /// Iterates over all nodes of the trie in a lexicographic order. |
962 | 3.33M | fn all_node_lexicographic_ordered(&'_ self) -> impl Iterator<Item = usize> + '_ { |
963 | 9.66M | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { |
964 | 9.66M | if let Some(first_child3.29M ) = tree |
965 | 9.66M | .nodes |
966 | 9.66M | .get(node_index) |
967 | 9.66M | .unwrap() |
968 | 9.66M | .children |
969 | 9.66M | .iter() |
970 | 121M | .find_map(|c| *c)9.66M _RNCINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB27_NtNtB9_9trie_node17MerkleValueOutputEEE0Bb_ Line | Count | Source | 970 | 58.7M | .find_map(|c| *c) |
_RNCINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB27_NtNtB9_9trie_node17MerkleValueOutputEEE0Bb_ Line | Count | Source | 970 | 12.3M | .find_map(|c| *c) |
_RNCINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextuE0Bb_ Line | Count | Source | 970 | 50.8M | .find_map(|c| *c) |
Unexecuted instantiation: _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextpE0Bb_ _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB28_NtNtB9_9trie_node17MerkleValueOutputEEE0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 970 | 1.24k | .find_map(|c| *c) |
Unexecuted instantiation: _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB28_NtNtB9_9trie_node17MerkleValueOutputEEE0CscDgN54JpMGG_6author _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB28_NtNtB9_9trie_node17MerkleValueOutputEEE0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 970 | 11.8k | .find_map(|c| *c) |
|
971 | 3.33M | { |
972 | 3.33M | return Some(first_child)3.29M ; |
973 | 6.36M | } |
974 | 3.33M | |
975 | 6.36M | if let Some(next_sibling3.01M ) = tree.next_sibling(node_index) { |
976 | 3.33M | return Some(next_sibling)3.01M ; |
977 | 3.35M | } |
978 | 3.35M | |
979 | 3.35M | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i2.50M ); _RNCINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB27_NtNtB9_9trie_node17MerkleValueOutputEEEs_0Bb_ Line | Count | Source | 979 | 1.22M | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); |
_RNCINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB27_NtNtB9_9trie_node17MerkleValueOutputEEEs_0Bb_ Line | Count | Source | 979 | 215k | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); |
_RNCINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextuEs_0Bb_ Line | Count | Source | 979 | 1.05M | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); |
Unexecuted instantiation: _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextpEs_0Bb_ _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB28_NtNtB9_9trie_node17MerkleValueOutputEEEs_0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 979 | 24 | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); |
Unexecuted instantiation: _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB28_NtNtB9_9trie_node17MerkleValueOutputEEEs_0CscDgN54JpMGG_6author _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB28_NtNtB9_9trie_node17MerkleValueOutputEEEs_0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 979 | 228 | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); |
|
980 | 5.53M | while let Some(idx2.73M ) = return_value { |
981 | 3.33M | if let Some(next_sibling546k ) = tree.next_sibling(idx)2.73M { |
982 | 3.33M | return Some(next_sibling)546k ; |
983 | 3.33M | } |
984 | 2.18M | return_value = tree.nodes[idx].parent.map(|(i, _)| i229k ); _RNCINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB27_NtNtB9_9trie_node17MerkleValueOutputEEEs0_0Bb_ Line | Count | Source | 984 | 43.5k | return_value = tree.nodes[idx].parent.map(|(i, _)| i); |
_RNCINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB27_NtNtB9_9trie_node17MerkleValueOutputEEEs0_0Bb_ Line | Count | Source | 984 | 20.6k | return_value = tree.nodes[idx].parent.map(|(i, _)| i); |
_RNCINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextuEs0_0Bb_ Line | Count | Source | 984 | 165k | return_value = tree.nodes[idx].parent.map(|(i, _)| i); |
Unexecuted instantiation: _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextpEs0_0Bb_ _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB28_NtNtB9_9trie_node17MerkleValueOutputEEEs0_0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 984 | 2 | return_value = tree.nodes[idx].parent.map(|(i, _)| i); |
Unexecuted instantiation: _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB28_NtNtB9_9trie_node17MerkleValueOutputEEEs0_0CscDgN54JpMGG_6author _RNCINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB28_NtNtB9_9trie_node17MerkleValueOutputEEEs0_0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 984 | 19 | return_value = tree.nodes[idx].parent.map(|(i, _)| i); |
|
985 | 3.33M | } |
986 | 3.33M | return_value2.80M |
987 | 9.66M | } _RINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB25_NtNtB7_9trie_node17MerkleValueOutputEEEB9_ Line | Count | Source | 963 | 4.66M | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { | 964 | 4.66M | if let Some(first_child1.64M ) = tree | 965 | 4.66M | .nodes | 966 | 4.66M | .get(node_index) | 967 | 4.66M | .unwrap() | 968 | 4.66M | .children | 969 | 4.66M | .iter() | 970 | 4.66M | .find_map(|c| *c) | 971 | | { | 972 | 1.64M | return Some(first_child); | 973 | 3.02M | } | 974 | | | 975 | 3.02M | if let Some(next_sibling1.22M ) = tree.next_sibling(node_index) { | 976 | 1.22M | return Some(next_sibling); | 977 | 1.80M | } | 978 | 1.80M | | 979 | 1.80M | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); | 980 | 3.02M | while let Some(idx1.27M ) = return_value { | 981 | 1.27M | if let Some(next_sibling50.3k ) = tree.next_sibling(idx) { | 982 | 50.3k | return Some(next_sibling); | 983 | 1.22M | } | 984 | 1.22M | return_value = tree.nodes[idx].parent.map(|(i, _)| i); | 985 | | } | 986 | 1.75M | return_value | 987 | 4.66M | } |
_RINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB25_NtNtB7_9trie_node17MerkleValueOutputEEEB9_ Line | Count | Source | 963 | 935k | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { | 964 | 935k | if let Some(first_child236k ) = tree | 965 | 935k | .nodes | 966 | 935k | .get(node_index) | 967 | 935k | .unwrap() | 968 | 935k | .children | 969 | 935k | .iter() | 970 | 935k | .find_map(|c| *c) | 971 | | { | 972 | 236k | return Some(first_child); | 973 | 699k | } | 974 | | | 975 | 699k | if let Some(next_sibling466k ) = tree.next_sibling(node_index) { | 976 | 466k | return Some(next_sibling); | 977 | 232k | } | 978 | 232k | | 979 | 232k | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); | 980 | 367k | while let Some(idx236k ) = return_value { | 981 | 236k | if let Some(next_sibling101k ) = tree.next_sibling(idx) { | 982 | 101k | return Some(next_sibling); | 983 | 134k | } | 984 | 134k | return_value = tree.nodes[idx].parent.map(|(i, _)| i); | 985 | | } | 986 | 131k | return_value | 987 | 935k | } |
_RINvNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextuEB9_ Line | Count | Source | 963 | 4.05M | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { | 964 | 4.05M | if let Some(first_child1.41M ) = tree | 965 | 4.05M | .nodes | 966 | 4.05M | .get(node_index) | 967 | 4.05M | .unwrap() | 968 | 4.05M | .children | 969 | 4.05M | .iter() | 970 | 4.05M | .find_map(|c| *c) | 971 | | { | 972 | 1.41M | return Some(first_child); | 973 | 2.64M | } | 974 | | | 975 | 2.64M | if let Some(next_sibling1.32M ) = tree.next_sibling(node_index) { | 976 | 1.32M | return Some(next_sibling); | 977 | 1.32M | } | 978 | 1.32M | | 979 | 1.32M | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); | 980 | 2.14M | while let Some(idx1.22M ) = return_value { | 981 | 1.22M | if let Some(next_sibling394k ) = tree.next_sibling(idx) { | 982 | 394k | return Some(next_sibling); | 983 | 827k | } | 984 | 827k | return_value = tree.nodes[idx].parent.map(|(i, _)| i); | 985 | | } | 986 | 926k | return_value | 987 | 4.05M | } |
Unexecuted instantiation: _RINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextpEB9_ _RINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB26_NtNtB7_9trie_node17MerkleValueOutputEEECsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 963 | 96 | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { | 964 | 96 | if let Some(first_child26 ) = tree | 965 | 96 | .nodes | 966 | 96 | .get(node_index) | 967 | 96 | .unwrap() | 968 | 96 | .children | 969 | 96 | .iter() | 970 | 96 | .find_map(|c| *c) | 971 | | { | 972 | 26 | return Some(first_child); | 973 | 70 | } | 974 | | | 975 | 70 | if let Some(next_sibling46 ) = tree.next_sibling(node_index) { | 976 | 46 | return Some(next_sibling); | 977 | 24 | } | 978 | 24 | | 979 | 24 | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); | 980 | 28 | while let Some(idx26 ) = return_value { | 981 | 26 | if let Some(next_sibling22 ) = tree.next_sibling(idx) { | 982 | 22 | return Some(next_sibling); | 983 | 4 | } | 984 | 4 | return_value = tree.nodes[idx].parent.map(|(i, _)| i); | 985 | | } | 986 | 2 | return_value | 987 | 96 | } |
Unexecuted instantiation: _RINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB26_NtNtB7_9trie_node17MerkleValueOutputEEECscDgN54JpMGG_6author _RINvNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructurepE30all_node_lexicographic_ordered19ancestry_order_nextTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB26_NtNtB7_9trie_node17MerkleValueOutputEEECsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 963 | 912 | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { | 964 | 912 | if let Some(first_child247 ) = tree | 965 | 912 | .nodes | 966 | 912 | .get(node_index) | 967 | 912 | .unwrap() | 968 | 912 | .children | 969 | 912 | .iter() | 970 | 912 | .find_map(|c| *c) | 971 | | { | 972 | 247 | return Some(first_child); | 973 | 665 | } | 974 | | | 975 | 665 | if let Some(next_sibling437 ) = tree.next_sibling(node_index) { | 976 | 437 | return Some(next_sibling); | 977 | 228 | } | 978 | 228 | | 979 | 228 | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); | 980 | 266 | while let Some(idx247 ) = return_value { | 981 | 247 | if let Some(next_sibling209 ) = tree.next_sibling(idx) { | 982 | 209 | return Some(next_sibling); | 983 | 38 | } | 984 | 38 | return_value = tree.nodes[idx].parent.map(|(i, _)| i); | 985 | | } | 986 | 19 | return_value | 987 | 912 | } |
|
988 | 3.33M | |
989 | 9.66M | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB6_16TrieEntryVersionEEIB1b_NtNtB6_9trie_node17MerkleValueOutputEEE30all_node_lexicographic_ordered0B8_ Line | Count | Source | 989 | 935k | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1b_NtNtB6_9trie_node17MerkleValueOutputEEE30all_node_lexicographic_ordered0B8_ Line | Count | Source | 989 | 4.66M | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureuE30all_node_lexicographic_ordered0B8_ Line | Count | Source | 989 | 4.05M | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) |
Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructurepE30all_node_lexicographic_ordered0B8_ _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE30all_node_lexicographic_ordered0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 989 | 96 | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) |
Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE30all_node_lexicographic_ordered0CscDgN54JpMGG_6author _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE30all_node_lexicographic_ordered0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 989 | 912 | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) |
|
990 | 3.33M | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE30all_node_lexicographic_orderedB6_ Line | Count | Source | 962 | 1.10M | fn all_node_lexicographic_ordered(&'_ self) -> impl Iterator<Item = usize> + '_ { | 963 | 1.10M | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { | 964 | 1.10M | if let Some(first_child) = tree | 965 | 1.10M | .nodes | 966 | 1.10M | .get(node_index) | 967 | 1.10M | .unwrap() | 968 | 1.10M | .children | 969 | 1.10M | .iter() | 970 | 1.10M | .find_map(|c| *c) | 971 | 1.10M | { | 972 | 1.10M | return Some(first_child); | 973 | 1.10M | } | 974 | 1.10M | | 975 | 1.10M | if let Some(next_sibling) = tree.next_sibling(node_index) { | 976 | 1.10M | return Some(next_sibling); | 977 | 1.10M | } | 978 | 1.10M | | 979 | 1.10M | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); | 980 | 1.10M | while let Some(idx) = return_value { | 981 | 1.10M | if let Some(next_sibling) = tree.next_sibling(idx) { | 982 | 1.10M | return Some(next_sibling); | 983 | 1.10M | } | 984 | 1.10M | return_value = tree.nodes[idx].parent.map(|(i, _)| i); | 985 | 1.10M | } | 986 | 1.10M | return_value | 987 | 1.10M | } | 988 | 1.10M | | 989 | 1.10M | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) | 990 | 1.10M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE30all_node_lexicographic_orderedB6_ Line | Count | Source | 962 | 2.09M | fn all_node_lexicographic_ordered(&'_ self) -> impl Iterator<Item = usize> + '_ { | 963 | 2.09M | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { | 964 | 2.09M | if let Some(first_child) = tree | 965 | 2.09M | .nodes | 966 | 2.09M | .get(node_index) | 967 | 2.09M | .unwrap() | 968 | 2.09M | .children | 969 | 2.09M | .iter() | 970 | 2.09M | .find_map(|c| *c) | 971 | 2.09M | { | 972 | 2.09M | return Some(first_child); | 973 | 2.09M | } | 974 | 2.09M | | 975 | 2.09M | if let Some(next_sibling) = tree.next_sibling(node_index) { | 976 | 2.09M | return Some(next_sibling); | 977 | 2.09M | } | 978 | 2.09M | | 979 | 2.09M | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); | 980 | 2.09M | while let Some(idx) = return_value { | 981 | 2.09M | if let Some(next_sibling) = tree.next_sibling(idx) { | 982 | 2.09M | return Some(next_sibling); | 983 | 2.09M | } | 984 | 2.09M | return_value = tree.nodes[idx].parent.map(|(i, _)| i); | 985 | 2.09M | } | 986 | 2.09M | return_value | 987 | 2.09M | } | 988 | 2.09M | | 989 | 2.09M | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) | 990 | 2.09M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE30all_node_lexicographic_orderedB6_ Line | Count | Source | 962 | 131k | fn all_node_lexicographic_ordered(&'_ self) -> impl Iterator<Item = usize> + '_ { | 963 | 131k | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { | 964 | 131k | if let Some(first_child) = tree | 965 | 131k | .nodes | 966 | 131k | .get(node_index) | 967 | 131k | .unwrap() | 968 | 131k | .children | 969 | 131k | .iter() | 970 | 131k | .find_map(|c| *c) | 971 | 131k | { | 972 | 131k | return Some(first_child); | 973 | 131k | } | 974 | 131k | | 975 | 131k | if let Some(next_sibling) = tree.next_sibling(node_index) { | 976 | 131k | return Some(next_sibling); | 977 | 131k | } | 978 | 131k | | 979 | 131k | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); | 980 | 131k | while let Some(idx) = return_value { | 981 | 131k | if let Some(next_sibling) = tree.next_sibling(idx) { | 982 | 131k | return Some(next_sibling); | 983 | 131k | } | 984 | 131k | return_value = tree.nodes[idx].parent.map(|(i, _)| i); | 985 | 131k | } | 986 | 131k | return_value | 987 | 131k | } | 988 | 131k | | 989 | 131k | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) | 990 | 131k | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructurepE30all_node_lexicographic_orderedB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE30all_node_lexicographic_orderedCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 962 | 2 | fn all_node_lexicographic_ordered(&'_ self) -> impl Iterator<Item = usize> + '_ { | 963 | 2 | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { | 964 | 2 | if let Some(first_child) = tree | 965 | 2 | .nodes | 966 | 2 | .get(node_index) | 967 | 2 | .unwrap() | 968 | 2 | .children | 969 | 2 | .iter() | 970 | 2 | .find_map(|c| *c) | 971 | 2 | { | 972 | 2 | return Some(first_child); | 973 | 2 | } | 974 | 2 | | 975 | 2 | if let Some(next_sibling) = tree.next_sibling(node_index) { | 976 | 2 | return Some(next_sibling); | 977 | 2 | } | 978 | 2 | | 979 | 2 | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); | 980 | 2 | while let Some(idx) = return_value { | 981 | 2 | if let Some(next_sibling) = tree.next_sibling(idx) { | 982 | 2 | return Some(next_sibling); | 983 | 2 | } | 984 | 2 | return_value = tree.nodes[idx].parent.map(|(i, _)| i); | 985 | 2 | } | 986 | 2 | return_value | 987 | 2 | } | 988 | 2 | | 989 | 2 | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) | 990 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE30all_node_lexicographic_orderedCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE30all_node_lexicographic_orderedCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 962 | 19 | fn all_node_lexicographic_ordered(&'_ self) -> impl Iterator<Item = usize> + '_ { | 963 | 19 | fn ancestry_order_next<TUd>(tree: &TrieStructure<TUd>, node_index: usize) -> Option<usize> { | 964 | 19 | if let Some(first_child) = tree | 965 | 19 | .nodes | 966 | 19 | .get(node_index) | 967 | 19 | .unwrap() | 968 | 19 | .children | 969 | 19 | .iter() | 970 | 19 | .find_map(|c| *c) | 971 | 19 | { | 972 | 19 | return Some(first_child); | 973 | 19 | } | 974 | 19 | | 975 | 19 | if let Some(next_sibling) = tree.next_sibling(node_index) { | 976 | 19 | return Some(next_sibling); | 977 | 19 | } | 978 | 19 | | 979 | 19 | let mut return_value = tree.nodes[node_index].parent.map(|(i, _)| i); | 980 | 19 | while let Some(idx) = return_value { | 981 | 19 | if let Some(next_sibling) = tree.next_sibling(idx) { | 982 | 19 | return Some(next_sibling); | 983 | 19 | } | 984 | 19 | return_value = tree.nodes[idx].parent.map(|(i, _)| i); | 985 | 19 | } | 986 | 19 | return_value | 987 | 19 | } | 988 | 19 | | 989 | 19 | iter::successors(self.root_index, move |n| ancestry_order_next(self, *n)) | 990 | 19 | } |
|
991 | | |
992 | | /// Returns the [`NodeAccess`] of the node at the given index, or `None` if no such node |
993 | | /// exists. |
994 | | /// |
995 | | /// # Context |
996 | | /// |
997 | | /// Each node inserted in the trie is placed in the underlying data structure at a specific |
998 | | /// [`NodeIndex`] that never changes until the node is removed from the trie. |
999 | | /// |
1000 | | /// This [`NodeIndex`] can be retrieved by calling [`NodeAccess::node_index`], |
1001 | | /// [`StorageNodeAccess::node_index`] or [`BranchNodeAccess::node_index`]. The same node can |
1002 | | /// later be accessed again by calling [`TrieStructure::node_by_index`]. |
1003 | | /// |
1004 | | /// A [`NodeIndex`] value can be reused after its previous node has been removed. |
1005 | | /// |
1006 | | /// # Examples |
1007 | | /// |
1008 | | /// ``` |
1009 | | /// use smoldot::trie::{self, trie_structure}; |
1010 | | /// |
1011 | | /// let mut trie = trie_structure::TrieStructure::new(); |
1012 | | /// |
1013 | | /// // Insert an example node. |
1014 | | /// let inserted_node = trie |
1015 | | /// .node(trie::bytes_to_nibbles(b"foo".iter().cloned())) |
1016 | | /// .into_vacant() |
1017 | | /// .unwrap() |
1018 | | /// .insert_storage_value() |
1019 | | /// .insert(12, 80); |
1020 | | /// let node_index = inserted_node.node_index(); |
1021 | | /// drop(inserted_node); // Drops the borrow to this node. |
1022 | | /// |
1023 | | /// // At this point, no borrow of the `trie` object exists anymore. |
1024 | | /// |
1025 | | /// // Later, the same node can be accessed again. |
1026 | | /// let mut node = trie.node_by_index(node_index).unwrap(); |
1027 | | /// assert_eq!(*node.user_data(), 12); |
1028 | | /// ``` |
1029 | 1.03M | pub fn node_by_index(&mut self, node_index: NodeIndex) -> Option<NodeAccess<TUd>> { |
1030 | 1.03M | self.node_by_index_inner(node_index.0) |
1031 | 1.03M | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE13node_by_indexB6_ Line | Count | Source | 1029 | 5.16k | pub fn node_by_index(&mut self, node_index: NodeIndex) -> Option<NodeAccess<TUd>> { | 1030 | 5.16k | self.node_by_index_inner(node_index.0) | 1031 | 5.16k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE13node_by_indexB6_ Line | Count | Source | 1029 | 518k | pub fn node_by_index(&mut self, node_index: NodeIndex) -> Option<NodeAccess<TUd>> { | 1030 | 518k | self.node_by_index_inner(node_index.0) | 1031 | 518k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE13node_by_indexB6_ Line | Count | Source | 1029 | 28.8k | pub fn node_by_index(&mut self, node_index: NodeIndex) -> Option<NodeAccess<TUd>> { | 1030 | 28.8k | self.node_by_index_inner(node_index.0) | 1031 | 28.8k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE13node_by_indexB6_ Line | Count | Source | 1029 | 483k | pub fn node_by_index(&mut self, node_index: NodeIndex) -> Option<NodeAccess<TUd>> { | 1030 | 483k | self.node_by_index_inner(node_index.0) | 1031 | 483k | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE13node_by_indexB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE13node_by_indexCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1029 | 192 | pub fn node_by_index(&mut self, node_index: NodeIndex) -> Option<NodeAccess<TUd>> { | 1030 | 192 | self.node_by_index_inner(node_index.0) | 1031 | 192 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE13node_by_indexCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE13node_by_indexCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1029 | 1.82k | pub fn node_by_index(&mut self, node_index: NodeIndex) -> Option<NodeAccess<TUd>> { | 1030 | 1.82k | self.node_by_index_inner(node_index.0) | 1031 | 1.82k | } |
|
1032 | | |
1033 | | /// Internal function. Returns the [`NodeAccess`] of the node at the given index. |
1034 | 1.54M | fn node_by_index_inner(&mut self, node_index: usize) -> Option<NodeAccess<TUd>> { |
1035 | 1.54M | if self.nodes.get(node_index)?0 .has_storage_value { |
1036 | 1.30M | Some(NodeAccess::Storage(StorageNodeAccess { |
1037 | 1.30M | trie: self, |
1038 | 1.30M | node_index, |
1039 | 1.30M | })) |
1040 | | } else { |
1041 | 247k | Some(NodeAccess::Branch(BranchNodeAccess { |
1042 | 247k | trie: self, |
1043 | 247k | node_index, |
1044 | 247k | })) |
1045 | | } |
1046 | 1.54M | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE19node_by_index_innerB6_ Line | Count | Source | 1034 | 66.9k | fn node_by_index_inner(&mut self, node_index: usize) -> Option<NodeAccess<TUd>> { | 1035 | 66.9k | if self.nodes.get(node_index)?0 .has_storage_value { | 1036 | 66.9k | Some(NodeAccess::Storage(StorageNodeAccess { | 1037 | 66.9k | trie: self, | 1038 | 66.9k | node_index, | 1039 | 66.9k | })) | 1040 | | } else { | 1041 | 0 | Some(NodeAccess::Branch(BranchNodeAccess { | 1042 | 0 | trie: self, | 1043 | 0 | node_index, | 1044 | 0 | })) | 1045 | | } | 1046 | 66.9k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE19node_by_index_innerB6_ Line | Count | Source | 1034 | 8.28k | fn node_by_index_inner(&mut self, node_index: usize) -> Option<NodeAccess<TUd>> { | 1035 | 8.28k | if self.nodes.get(node_index)?0 .has_storage_value { | 1036 | 8.01k | Some(NodeAccess::Storage(StorageNodeAccess { | 1037 | 8.01k | trie: self, | 1038 | 8.01k | node_index, | 1039 | 8.01k | })) | 1040 | | } else { | 1041 | 272 | Some(NodeAccess::Branch(BranchNodeAccess { | 1042 | 272 | trie: self, | 1043 | 272 | node_index, | 1044 | 272 | })) | 1045 | | } | 1046 | 8.28k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE19node_by_index_innerB6_ Line | Count | Source | 1034 | 895k | fn node_by_index_inner(&mut self, node_index: usize) -> Option<NodeAccess<TUd>> { | 1035 | 895k | if self.nodes.get(node_index)?0 .has_storage_value { | 1036 | 765k | Some(NodeAccess::Storage(StorageNodeAccess { | 1037 | 765k | trie: self, | 1038 | 765k | node_index, | 1039 | 765k | })) | 1040 | | } else { | 1041 | 130k | Some(NodeAccess::Branch(BranchNodeAccess { | 1042 | 130k | trie: self, | 1043 | 130k | node_index, | 1044 | 130k | })) | 1045 | | } | 1046 | 895k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE19node_by_index_innerB6_ Line | Count | Source | 1034 | 573k | fn node_by_index_inner(&mut self, node_index: usize) -> Option<NodeAccess<TUd>> { | 1035 | 573k | if self.nodes.get(node_index)?0 .has_storage_value { | 1036 | 457k | Some(NodeAccess::Storage(StorageNodeAccess { | 1037 | 457k | trie: self, | 1038 | 457k | node_index, | 1039 | 457k | })) | 1040 | | } else { | 1041 | 116k | Some(NodeAccess::Branch(BranchNodeAccess { | 1042 | 116k | trie: self, | 1043 | 116k | node_index, | 1044 | 116k | })) | 1045 | | } | 1046 | 573k | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE19node_by_index_innerB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE19node_by_index_innerCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1034 | 380 | fn node_by_index_inner(&mut self, node_index: usize) -> Option<NodeAccess<TUd>> { | 1035 | 380 | if self.nodes.get(node_index)?0 .has_storage_value { | 1036 | 280 | Some(NodeAccess::Storage(StorageNodeAccess { | 1037 | 280 | trie: self, | 1038 | 280 | node_index, | 1039 | 280 | })) | 1040 | | } else { | 1041 | 100 | Some(NodeAccess::Branch(BranchNodeAccess { | 1042 | 100 | trie: self, | 1043 | 100 | node_index, | 1044 | 100 | })) | 1045 | | } | 1046 | 380 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE19node_by_index_innerCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE19node_by_index_innerCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1034 | 3.61k | fn node_by_index_inner(&mut self, node_index: usize) -> Option<NodeAccess<TUd>> { | 1035 | 3.61k | if self.nodes.get(node_index)?0 .has_storage_value { | 1036 | 2.66k | Some(NodeAccess::Storage(StorageNodeAccess { | 1037 | 2.66k | trie: self, | 1038 | 2.66k | node_index, | 1039 | 2.66k | })) | 1040 | | } else { | 1041 | 950 | Some(NodeAccess::Branch(BranchNodeAccess { | 1042 | 950 | trie: self, | 1043 | 950 | node_index, | 1044 | 950 | })) | 1045 | | } | 1046 | 3.61k | } |
|
1047 | | |
1048 | | /// Returns the key of the node at the given index, or `None` if no such node exists. |
1049 | | /// |
1050 | | /// This method is a shortcut for [`TrieStructure::node_by_index`] followed with |
1051 | | /// [`NodeAccess::full_key`]. |
1052 | 11.1M | pub fn node_full_key_by_index( |
1053 | 11.1M | &'_ self, |
1054 | 11.1M | node_index: NodeIndex, |
1055 | 11.1M | ) -> Option<impl Iterator<Item = Nibble> + '_> { |
1056 | 11.1M | if !self.nodes.contains(node_index.0) { |
1057 | 0 | return None; |
1058 | 11.1M | } |
1059 | 11.1M | |
1060 | 11.1M | Some(self.node_full_key(node_index.0)) |
1061 | 11.1M | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE22node_full_key_by_indexB6_ Line | Count | Source | 1052 | 4.63M | pub fn node_full_key_by_index( | 1053 | 4.63M | &'_ self, | 1054 | 4.63M | node_index: NodeIndex, | 1055 | 4.63M | ) -> Option<impl Iterator<Item = Nibble> + '_> { | 1056 | 4.63M | if !self.nodes.contains(node_index.0) { | 1057 | 0 | return None; | 1058 | 4.63M | } | 1059 | 4.63M | | 1060 | 4.63M | Some(self.node_full_key(node_index.0)) | 1061 | 4.63M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE22node_full_key_by_indexB6_ Line | Count | Source | 1052 | 3.64M | pub fn node_full_key_by_index( | 1053 | 3.64M | &'_ self, | 1054 | 3.64M | node_index: NodeIndex, | 1055 | 3.64M | ) -> Option<impl Iterator<Item = Nibble> + '_> { | 1056 | 3.64M | if !self.nodes.contains(node_index.0) { | 1057 | 0 | return None; | 1058 | 3.64M | } | 1059 | 3.64M | | 1060 | 3.64M | Some(self.node_full_key(node_index.0)) | 1061 | 3.64M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE22node_full_key_by_indexB6_ Line | Count | Source | 1052 | 2.85M | pub fn node_full_key_by_index( | 1053 | 2.85M | &'_ self, | 1054 | 2.85M | node_index: NodeIndex, | 1055 | 2.85M | ) -> Option<impl Iterator<Item = Nibble> + '_> { | 1056 | 2.85M | if !self.nodes.contains(node_index.0) { | 1057 | 0 | return None; | 1058 | 2.85M | } | 1059 | 2.85M | | 1060 | 2.85M | Some(self.node_full_key(node_index.0)) | 1061 | 2.85M | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructurepE22node_full_key_by_indexB6_ |
1062 | | |
1063 | | /// Returns the full key of the node with the given index. |
1064 | | /// |
1065 | | /// # Panic |
1066 | | /// |
1067 | | /// Panics if `target` is not a valid index. |
1068 | 12.4M | fn node_full_key(&'_ self, target: usize) -> impl Iterator<Item = Nibble> + '_ { |
1069 | 12.4M | self.node_path(target) |
1070 | 12.4M | .chain(iter::once(target)) |
1071 | 23.1M | .flat_map(move |n| { |
1072 | 23.1M | let node = self.nodes.get(n).unwrap(); |
1073 | 23.1M | let child_index = node.parent.into_iter().map(|p| p.110.7M ); _RNCNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB6_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB8_12proof_encode4NodeEE13node_full_key00Ba_ Line | Count | Source | 1073 | 8.79k | let child_index = node.parent.into_iter().map(|p| p.1); |
_RNCNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB6_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1d_NtNtB8_9trie_node17MerkleValueOutputEEE13node_full_key00Ba_ Line | Count | Source | 1073 | 2.73M | let child_index = node.parent.into_iter().map(|p| p.1); |
_RNCNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB6_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB8_16TrieEntryVersionEEIB1d_NtNtB8_9trie_node17MerkleValueOutputEEE13node_full_key00Ba_ Line | Count | Source | 1073 | 3.71M | let child_index = node.parent.into_iter().map(|p| p.1); |
_RNCNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB6_13TrieStructureuE13node_full_key00Ba_ Line | Count | Source | 1073 | 4.28M | let child_index = node.parent.into_iter().map(|p| p.1); |
Unexecuted instantiation: _RNCNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB6_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB8_12proof_encode4NodeEE13node_full_key00Ba_ _RNCNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB6_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1e_NtNtB8_9trie_node17MerkleValueOutputEEE13node_full_key00CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1073 | 66 | let child_index = node.parent.into_iter().map(|p| p.1); |
Unexecuted instantiation: _RNCNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB6_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1e_NtNtB8_9trie_node17MerkleValueOutputEEE13node_full_key00CscDgN54JpMGG_6author _RNCNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB6_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1e_NtNtB8_9trie_node17MerkleValueOutputEEE13node_full_key00CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1073 | 627 | let child_index = node.parent.into_iter().map(|p| p.1); |
|
1074 | 23.1M | let partial_key = node.partial_key.iter().cloned(); |
1075 | 23.1M | child_index.chain(partial_key) |
1076 | 23.1M | }) _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB6_12proof_encode4NodeEE13node_full_key0B8_ Line | Count | Source | 1071 | 34.1k | .flat_map(move |n| { | 1072 | 34.1k | let node = self.nodes.get(n).unwrap(); | 1073 | 34.1k | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | 34.1k | let partial_key = node.partial_key.iter().cloned(); | 1075 | 34.1k | child_index.chain(partial_key) | 1076 | 34.1k | }) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1b_NtNtB6_9trie_node17MerkleValueOutputEEE13node_full_key0B8_ Line | Count | Source | 1071 | 7.37M | .flat_map(move |n| { | 1072 | 7.37M | let node = self.nodes.get(n).unwrap(); | 1073 | 7.37M | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | 7.37M | let partial_key = node.partial_key.iter().cloned(); | 1075 | 7.37M | child_index.chain(partial_key) | 1076 | 7.37M | }) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB6_16TrieEntryVersionEEIB1b_NtNtB6_9trie_node17MerkleValueOutputEEE13node_full_key0B8_ Line | Count | Source | 1071 | 7.64M | .flat_map(move |n| { | 1072 | 7.64M | let node = self.nodes.get(n).unwrap(); | 1073 | 7.64M | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | 7.64M | let partial_key = node.partial_key.iter().cloned(); | 1075 | 7.64M | child_index.chain(partial_key) | 1076 | 7.64M | }) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureuE13node_full_key0B8_ Line | Count | Source | 1071 | 8.11M | .flat_map(move |n| { | 1072 | 8.11M | let node = self.nodes.get(n).unwrap(); | 1073 | 8.11M | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | 8.11M | let partial_key = node.partial_key.iter().cloned(); | 1075 | 8.11M | child_index.chain(partial_key) | 1076 | 8.11M | }) |
Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB6_12proof_encode4NodeEE13node_full_key0B8_ _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE13node_full_key0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1071 | 132 | .flat_map(move |n| { | 1072 | 132 | let node = self.nodes.get(n).unwrap(); | 1073 | 132 | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | 132 | let partial_key = node.partial_key.iter().cloned(); | 1075 | 132 | child_index.chain(partial_key) | 1076 | 132 | }) |
Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE13node_full_key0CscDgN54JpMGG_6author _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE13node_full_key0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1071 | 1.25k | .flat_map(move |n| { | 1072 | 1.25k | let node = self.nodes.get(n).unwrap(); | 1073 | 1.25k | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | 1.25k | let partial_key = node.partial_key.iter().cloned(); | 1075 | 1.25k | child_index.chain(partial_key) | 1076 | 1.25k | }) |
|
1077 | 12.4M | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE13node_full_keyB6_ Line | Count | Source | 1068 | 25.3k | fn node_full_key(&'_ self, target: usize) -> impl Iterator<Item = Nibble> + '_ { | 1069 | 25.3k | self.node_path(target) | 1070 | 25.3k | .chain(iter::once(target)) | 1071 | 25.3k | .flat_map(move |n| { | 1072 | | let node = self.nodes.get(n).unwrap(); | 1073 | | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | | let partial_key = node.partial_key.iter().cloned(); | 1075 | | child_index.chain(partial_key) | 1076 | 25.3k | }) | 1077 | 25.3k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE13node_full_keyB6_ Line | Count | Source | 1068 | 4.63M | fn node_full_key(&'_ self, target: usize) -> impl Iterator<Item = Nibble> + '_ { | 1069 | 4.63M | self.node_path(target) | 1070 | 4.63M | .chain(iter::once(target)) | 1071 | 4.63M | .flat_map(move |n| { | 1072 | | let node = self.nodes.get(n).unwrap(); | 1073 | | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | | let partial_key = node.partial_key.iter().cloned(); | 1075 | | child_index.chain(partial_key) | 1076 | 4.63M | }) | 1077 | 4.63M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE13node_full_keyB6_ Line | Count | Source | 1068 | 3.93M | fn node_full_key(&'_ self, target: usize) -> impl Iterator<Item = Nibble> + '_ { | 1069 | 3.93M | self.node_path(target) | 1070 | 3.93M | .chain(iter::once(target)) | 1071 | 3.93M | .flat_map(move |n| { | 1072 | | let node = self.nodes.get(n).unwrap(); | 1073 | | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | | let partial_key = node.partial_key.iter().cloned(); | 1075 | | child_index.chain(partial_key) | 1076 | 3.93M | }) | 1077 | 3.93M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE13node_full_keyB6_ Line | Count | Source | 1068 | 3.82M | fn node_full_key(&'_ self, target: usize) -> impl Iterator<Item = Nibble> + '_ { | 1069 | 3.82M | self.node_path(target) | 1070 | 3.82M | .chain(iter::once(target)) | 1071 | 3.82M | .flat_map(move |n| { | 1072 | | let node = self.nodes.get(n).unwrap(); | 1073 | | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | | let partial_key = node.partial_key.iter().cloned(); | 1075 | | child_index.chain(partial_key) | 1076 | 3.82M | }) | 1077 | 3.82M | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE13node_full_keyB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE13node_full_keyCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1068 | 66 | fn node_full_key(&'_ self, target: usize) -> impl Iterator<Item = Nibble> + '_ { | 1069 | 66 | self.node_path(target) | 1070 | 66 | .chain(iter::once(target)) | 1071 | 66 | .flat_map(move |n| { | 1072 | | let node = self.nodes.get(n).unwrap(); | 1073 | | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | | let partial_key = node.partial_key.iter().cloned(); | 1075 | | child_index.chain(partial_key) | 1076 | 66 | }) | 1077 | 66 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE13node_full_keyCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE13node_full_keyCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1068 | 627 | fn node_full_key(&'_ self, target: usize) -> impl Iterator<Item = Nibble> + '_ { | 1069 | 627 | self.node_path(target) | 1070 | 627 | .chain(iter::once(target)) | 1071 | 627 | .flat_map(move |n| { | 1072 | | let node = self.nodes.get(n).unwrap(); | 1073 | | let child_index = node.parent.into_iter().map(|p| p.1); | 1074 | | let partial_key = node.partial_key.iter().cloned(); | 1075 | | child_index.chain(partial_key) | 1076 | 627 | }) | 1077 | 627 | } |
|
1078 | | |
1079 | | /// Returns the indices of the nodes to traverse to reach `target`. The returned iterator |
1080 | | /// does *not* include `target`. In other words, if `target` is the root node, this returns |
1081 | | /// an empty iterator. |
1082 | | /// |
1083 | | /// # Panic |
1084 | | /// |
1085 | | /// Panics if `target` is not a valid index. |
1086 | 12.4M | fn node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { |
1087 | 12.4M | debug_assert!(self.nodes.get(usize::MAX).is_none()); |
1088 | | // First element is an invalid key, each successor is the last element of |
1089 | | // `reverse_node_path(target)` that isn't equal to `current`. |
1090 | | // Since the first element is invalid, we skip it. |
1091 | | // Since `reverse_node_path` never produces `target`, we know that it also won't be |
1092 | | // produced here. |
1093 | 23.1M | iter::successors(Some(usize::MAX), 12.4M move |¤t| { |
1094 | 23.1M | self.reverse_node_path(target) |
1095 | 24.7M | .take_while(move |n| *n != current) _RNCNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB6_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB8_12proof_encode4NodeEE9node_path00Ba_ Line | Count | Source | 1095 | 18.0k | .take_while(move |n| *n != current) |
_RNCNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB6_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1d_NtNtB8_9trie_node17MerkleValueOutputEEE9node_path00Ba_ Line | Count | Source | 1095 | 5.67M | .take_while(move |n| *n != current) |
_RNCNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB6_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB8_16TrieEntryVersionEEIB1d_NtNtB8_9trie_node17MerkleValueOutputEEE9node_path00Ba_ Line | Count | Source | 1095 | 7.61M | .take_while(move |n| *n != current) |
_RNCNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB6_13TrieStructureuE9node_path00Ba_ Line | Count | Source | 1095 | 11.4M | .take_while(move |n| *n != current) |
Unexecuted instantiation: _RNCNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB6_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB8_12proof_encode4NodeEE9node_path00Ba_ _RNCNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB6_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1e_NtNtB8_9trie_node17MerkleValueOutputEEE9node_path00CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1095 | 154 | .take_while(move |n| *n != current) |
Unexecuted instantiation: _RNCNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB6_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1e_NtNtB8_9trie_node17MerkleValueOutputEEE9node_path00CscDgN54JpMGG_6author _RNCNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB6_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1e_NtNtB8_9trie_node17MerkleValueOutputEEE9node_path00CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1095 | 1.46k | .take_while(move |n| *n != current) |
|
1096 | 23.1M | .last() |
1097 | 23.1M | }) _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB6_12proof_encode4NodeEE9node_path0B8_ Line | Count | Source | 1093 | 34.1k | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | 34.1k | self.reverse_node_path(target) | 1095 | 34.1k | .take_while(move |n| *n != current) | 1096 | 34.1k | .last() | 1097 | 34.1k | }) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1b_NtNtB6_9trie_node17MerkleValueOutputEEE9node_path0B8_ Line | Count | Source | 1093 | 7.37M | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | 7.37M | self.reverse_node_path(target) | 1095 | 7.37M | .take_while(move |n| *n != current) | 1096 | 7.37M | .last() | 1097 | 7.37M | }) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB6_16TrieEntryVersionEEIB1b_NtNtB6_9trie_node17MerkleValueOutputEEE9node_path0B8_ Line | Count | Source | 1093 | 7.64M | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | 7.64M | self.reverse_node_path(target) | 1095 | 7.64M | .take_while(move |n| *n != current) | 1096 | 7.64M | .last() | 1097 | 7.64M | }) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureuE9node_path0B8_ Line | Count | Source | 1093 | 8.11M | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | 8.11M | self.reverse_node_path(target) | 1095 | 8.11M | .take_while(move |n| *n != current) | 1096 | 8.11M | .last() | 1097 | 8.11M | }) |
Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB6_12proof_encode4NodeEE9node_path0B8_ _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE9node_path0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1093 | 132 | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | 132 | self.reverse_node_path(target) | 1095 | 132 | .take_while(move |n| *n != current) | 1096 | 132 | .last() | 1097 | 132 | }) |
Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE9node_path0CscDgN54JpMGG_6author _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE9node_path0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1093 | 1.25k | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | 1.25k | self.reverse_node_path(target) | 1095 | 1.25k | .take_while(move |n| *n != current) | 1096 | 1.25k | .last() | 1097 | 1.25k | }) |
|
1098 | 12.4M | .skip(1) |
1099 | 12.4M | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE9node_pathB6_ Line | Count | Source | 1086 | 25.3k | fn node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1087 | 25.3k | debug_assert!(self.nodes.get(usize::MAX).is_none()); | 1088 | | // First element is an invalid key, each successor is the last element of | 1089 | | // `reverse_node_path(target)` that isn't equal to `current`. | 1090 | | // Since the first element is invalid, we skip it. | 1091 | | // Since `reverse_node_path` never produces `target`, we know that it also won't be | 1092 | | // produced here. | 1093 | 25.3k | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | | self.reverse_node_path(target) | 1095 | | .take_while(move |n| *n != current) | 1096 | | .last() | 1097 | 25.3k | }) | 1098 | 25.3k | .skip(1) | 1099 | 25.3k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE9node_pathB6_ Line | Count | Source | 1086 | 4.63M | fn node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1087 | 4.63M | debug_assert!(self.nodes.get(usize::MAX).is_none()); | 1088 | | // First element is an invalid key, each successor is the last element of | 1089 | | // `reverse_node_path(target)` that isn't equal to `current`. | 1090 | | // Since the first element is invalid, we skip it. | 1091 | | // Since `reverse_node_path` never produces `target`, we know that it also won't be | 1092 | | // produced here. | 1093 | 4.63M | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | | self.reverse_node_path(target) | 1095 | | .take_while(move |n| *n != current) | 1096 | | .last() | 1097 | 4.63M | }) | 1098 | 4.63M | .skip(1) | 1099 | 4.63M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE9node_pathB6_ Line | Count | Source | 1086 | 3.93M | fn node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1087 | 3.93M | debug_assert!(self.nodes.get(usize::MAX).is_none()); | 1088 | | // First element is an invalid key, each successor is the last element of | 1089 | | // `reverse_node_path(target)` that isn't equal to `current`. | 1090 | | // Since the first element is invalid, we skip it. | 1091 | | // Since `reverse_node_path` never produces `target`, we know that it also won't be | 1092 | | // produced here. | 1093 | 3.93M | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | | self.reverse_node_path(target) | 1095 | | .take_while(move |n| *n != current) | 1096 | | .last() | 1097 | 3.93M | }) | 1098 | 3.93M | .skip(1) | 1099 | 3.93M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE9node_pathB6_ Line | Count | Source | 1086 | 3.82M | fn node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1087 | 3.82M | debug_assert!(self.nodes.get(usize::MAX).is_none()); | 1088 | | // First element is an invalid key, each successor is the last element of | 1089 | | // `reverse_node_path(target)` that isn't equal to `current`. | 1090 | | // Since the first element is invalid, we skip it. | 1091 | | // Since `reverse_node_path` never produces `target`, we know that it also won't be | 1092 | | // produced here. | 1093 | 3.82M | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | | self.reverse_node_path(target) | 1095 | | .take_while(move |n| *n != current) | 1096 | | .last() | 1097 | 3.82M | }) | 1098 | 3.82M | .skip(1) | 1099 | 3.82M | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE9node_pathB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE9node_pathCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1086 | 66 | fn node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1087 | 66 | debug_assert!(self.nodes.get(usize::MAX).is_none()); | 1088 | | // First element is an invalid key, each successor is the last element of | 1089 | | // `reverse_node_path(target)` that isn't equal to `current`. | 1090 | | // Since the first element is invalid, we skip it. | 1091 | | // Since `reverse_node_path` never produces `target`, we know that it also won't be | 1092 | | // produced here. | 1093 | 66 | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | | self.reverse_node_path(target) | 1095 | | .take_while(move |n| *n != current) | 1096 | | .last() | 1097 | 66 | }) | 1098 | 66 | .skip(1) | 1099 | 66 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE9node_pathCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE9node_pathCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1086 | 627 | fn node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1087 | 627 | debug_assert!(self.nodes.get(usize::MAX).is_none()); | 1088 | | // First element is an invalid key, each successor is the last element of | 1089 | | // `reverse_node_path(target)` that isn't equal to `current`. | 1090 | | // Since the first element is invalid, we skip it. | 1091 | | // Since `reverse_node_path` never produces `target`, we know that it also won't be | 1092 | | // produced here. | 1093 | 627 | iter::successors(Some(usize::MAX), move |¤t| { | 1094 | | self.reverse_node_path(target) | 1095 | | .take_while(move |n| *n != current) | 1096 | | .last() | 1097 | 627 | }) | 1098 | 627 | .skip(1) | 1099 | 627 | } |
|
1100 | | |
1101 | | /// Returns the indices of the nodes starting from `target` towards the root node. The returned |
1102 | | /// iterator does *not* include `target` but does include the root node if it is different |
1103 | | /// from `target`. If `target` is the root node, this returns an empty iterator. |
1104 | | /// |
1105 | | /// # Panic |
1106 | | /// |
1107 | | /// Panics if `target` is not a valid index. |
1108 | 23.1M | fn reverse_node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { |
1109 | 23.1M | // First element is `target`, each successor is `current.parent`. |
1110 | 23.1M | // Since `target` must explicitly not be included, we skip the first element. |
1111 | 47.8M | iter::successors(Some(target), move |current| { |
1112 | 47.8M | Some(self.nodes.get(*current).unwrap().parent?21.0M .0) |
1113 | 47.8M | }) _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB6_12proof_encode4NodeEE17reverse_node_path0B8_ Line | Count | Source | 1111 | 52.1k | iter::successors(Some(target), move |current| { | 1112 | 52.1k | Some(self.nodes.get(*current).unwrap().parent?33.6k .0) | 1113 | 52.1k | }) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1b_NtNtB6_9trie_node17MerkleValueOutputEEE17reverse_node_path0B8_ Line | Count | Source | 1111 | 13.0M | iter::successors(Some(target), move |current| { | 1112 | 13.0M | Some(self.nodes.get(*current).unwrap().parent?7.17M .0) | 1113 | 13.0M | }) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB6_16TrieEntryVersionEEIB1b_NtNtB6_9trie_node17MerkleValueOutputEEE17reverse_node_path0B8_ Line | Count | Source | 1111 | 15.2M | iter::successors(Some(target), move |current| { | 1112 | 15.2M | Some(self.nodes.get(*current).unwrap().parent?7.46M .0) | 1113 | 15.2M | }) |
_RNCNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB4_13TrieStructureuE17reverse_node_path0B8_ Line | Count | Source | 1111 | 19.5M | iter::successors(Some(target), move |current| { | 1112 | 19.5M | Some(self.nodes.get(*current).unwrap().parent?6.41M .0) | 1113 | 19.5M | }) |
Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB6_12proof_encode4NodeEE17reverse_node_path0B8_ _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE17reverse_node_path0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1111 | 286 | iter::successors(Some(target), move |current| { | 1112 | 286 | Some(self.nodes.get(*current).unwrap().parent?110 .0) | 1113 | 286 | }) |
Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE17reverse_node_path0CscDgN54JpMGG_6author _RNCNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB4_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1c_NtNtB6_9trie_node17MerkleValueOutputEEE17reverse_node_path0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1111 | 2.71k | iter::successors(Some(target), move |current| { | 1112 | 2.71k | Some(self.nodes.get(*current).unwrap().parent?1.04k .0) | 1113 | 2.71k | }) |
|
1114 | 23.1M | .skip(1) |
1115 | 23.1M | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE17reverse_node_pathB6_ Line | Count | Source | 1108 | 34.1k | fn reverse_node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1109 | 34.1k | // First element is `target`, each successor is `current.parent`. | 1110 | 34.1k | // Since `target` must explicitly not be included, we skip the first element. | 1111 | 34.1k | iter::successors(Some(target), move |current| { | 1112 | | Some(self.nodes.get(*current).unwrap().parent?.0) | 1113 | 34.1k | }) | 1114 | 34.1k | .skip(1) | 1115 | 34.1k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE17reverse_node_pathB6_ Line | Count | Source | 1108 | 7.37M | fn reverse_node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1109 | 7.37M | // First element is `target`, each successor is `current.parent`. | 1110 | 7.37M | // Since `target` must explicitly not be included, we skip the first element. | 1111 | 7.37M | iter::successors(Some(target), move |current| { | 1112 | | Some(self.nodes.get(*current).unwrap().parent?.0) | 1113 | 7.37M | }) | 1114 | 7.37M | .skip(1) | 1115 | 7.37M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE17reverse_node_pathB6_ Line | Count | Source | 1108 | 7.64M | fn reverse_node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1109 | 7.64M | // First element is `target`, each successor is `current.parent`. | 1110 | 7.64M | // Since `target` must explicitly not be included, we skip the first element. | 1111 | 7.64M | iter::successors(Some(target), move |current| { | 1112 | | Some(self.nodes.get(*current).unwrap().parent?.0) | 1113 | 7.64M | }) | 1114 | 7.64M | .skip(1) | 1115 | 7.64M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE17reverse_node_pathB6_ Line | Count | Source | 1108 | 8.11M | fn reverse_node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1109 | 8.11M | // First element is `target`, each successor is `current.parent`. | 1110 | 8.11M | // Since `target` must explicitly not be included, we skip the first element. | 1111 | 8.11M | iter::successors(Some(target), move |current| { | 1112 | | Some(self.nodes.get(*current).unwrap().parent?.0) | 1113 | 8.11M | }) | 1114 | 8.11M | .skip(1) | 1115 | 8.11M | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE17reverse_node_pathB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE17reverse_node_pathCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1108 | 132 | fn reverse_node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1109 | 132 | // First element is `target`, each successor is `current.parent`. | 1110 | 132 | // Since `target` must explicitly not be included, we skip the first element. | 1111 | 132 | iter::successors(Some(target), move |current| { | 1112 | | Some(self.nodes.get(*current).unwrap().parent?.0) | 1113 | 132 | }) | 1114 | 132 | .skip(1) | 1115 | 132 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE17reverse_node_pathCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE17reverse_node_pathCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1108 | 1.25k | fn reverse_node_path(&'_ self, target: usize) -> impl Iterator<Item = usize> + '_ { | 1109 | 1.25k | // First element is `target`, each successor is `current.parent`. | 1110 | 1.25k | // Since `target` must explicitly not be included, we skip the first element. | 1111 | 1.25k | iter::successors(Some(target), move |current| { | 1112 | | Some(self.nodes.get(*current).unwrap().parent?.0) | 1113 | 1.25k | }) | 1114 | 1.25k | .skip(1) | 1115 | 1.25k | } |
|
1116 | | |
1117 | | /// Returns the next sibling of the given node. |
1118 | | /// |
1119 | | /// # Panic |
1120 | | /// |
1121 | | /// Panics if `node_index` is not a valid index. |
1122 | 9.12M | fn next_sibling(&self, node_index: usize) -> Option<usize> { |
1123 | 9.12M | let (parent_index, child_index6.31M ) = self.nodes.get(node_index).unwrap().parent?2.80M ; |
1124 | 6.31M | let parent = self.nodes.get(parent_index).unwrap(); |
1125 | | |
1126 | 29.0M | for idx in (u8::from(child_index) + 1)6.31M ..16 { |
1127 | 29.0M | if let Some(child3.57M ) = parent.children[usize::from(idx)] { |
1128 | 3.57M | return Some(child); |
1129 | 25.4M | } |
1130 | | } |
1131 | | |
1132 | 2.73M | None |
1133 | 9.12M | } _RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE12next_siblingB6_ Line | Count | Source | 1122 | 28.8k | fn next_sibling(&self, node_index: usize) -> Option<usize> { | 1123 | 28.8k | let (parent_index, child_index27.3k ) = self.nodes.get(node_index).unwrap().parent?1.50k ; | 1124 | 27.3k | let parent = self.nodes.get(parent_index).unwrap(); | 1125 | | | 1126 | 86.3k | for idx in (u8::from(child_index) + 1)27.3k ..16 { | 1127 | 86.3k | if let Some(child19.5k ) = parent.children[usize::from(idx)] { | 1128 | 19.5k | return Some(child); | 1129 | 66.7k | } | 1130 | | } | 1131 | | | 1132 | 7.76k | None | 1133 | 28.8k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE12next_siblingB6_ Line | Count | Source | 1122 | 4.29M | fn next_sibling(&self, node_index: usize) -> Option<usize> { | 1123 | 4.29M | let (parent_index, child_index2.54M ) = self.nodes.get(node_index).unwrap().parent?1.75M ; | 1124 | 2.54M | let parent = self.nodes.get(parent_index).unwrap(); | 1125 | | | 1126 | 13.3M | for idx in (u8::from(child_index) + 1)2.54M ..16 { | 1127 | 13.3M | if let Some(child1.27M ) = parent.children[usize::from(idx)] { | 1128 | 1.27M | return Some(child); | 1129 | 12.0M | } | 1130 | | } | 1131 | | | 1132 | 1.27M | None | 1133 | 4.29M | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB4_16TrieEntryVersionEEIB19_NtNtB4_9trie_node17MerkleValueOutputEEE12next_siblingB6_ Line | Count | Source | 1122 | 935k | fn next_sibling(&self, node_index: usize) -> Option<usize> { | 1123 | 935k | let (parent_index, child_index804k ) = self.nodes.get(node_index).unwrap().parent?131k ; | 1124 | 804k | let parent = self.nodes.get(parent_index).unwrap(); | 1125 | | | 1126 | 2.63M | for idx in (u8::from(child_index) + 1)804k ..16 { | 1127 | 2.63M | if let Some(child568k ) = parent.children[usize::from(idx)] { | 1128 | 568k | return Some(child); | 1129 | 2.07M | } | 1130 | | } | 1131 | | | 1132 | 236k | None | 1133 | 935k | } |
_RNvMNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB2_13TrieStructureuE12next_siblingB6_ Line | Count | Source | 1122 | 3.86M | fn next_sibling(&self, node_index: usize) -> Option<usize> { | 1123 | 3.86M | let (parent_index, child_index2.93M ) = self.nodes.get(node_index).unwrap().parent?926k ; | 1124 | 2.93M | let parent = self.nodes.get(parent_index).unwrap(); | 1125 | | | 1126 | 12.9M | for idx in (u8::from(child_index) + 1)2.93M ..16 { | 1127 | 12.9M | if let Some(child1.71M ) = parent.children[usize::from(idx)] { | 1128 | 1.71M | return Some(child); | 1129 | 11.2M | } | 1130 | | } | 1131 | | | 1132 | 1.22M | None | 1133 | 3.86M | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureINtNtCsaYZPK01V26L_4core6option6OptionNtNtB4_12proof_encode4NodeEE12next_siblingB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE12next_siblingCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1122 | 96 | fn next_sibling(&self, node_index: usize) -> Option<usize> { | 1123 | 96 | let (parent_index, child_index94 ) = self.nodes.get(node_index).unwrap().parent?2 ; | 1124 | 94 | let parent = self.nodes.get(parent_index).unwrap(); | 1125 | | | 1126 | 292 | for idx in (u8::from(child_index) + 1)94 ..16 { | 1127 | 292 | if let Some(child68 ) = parent.children[usize::from(idx)] { | 1128 | 68 | return Some(child); | 1129 | 224 | } | 1130 | | } | 1131 | | | 1132 | 26 | None | 1133 | 96 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE12next_siblingCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB2_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB4_9trie_node17MerkleValueOutputEEE12next_siblingCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1122 | 912 | fn next_sibling(&self, node_index: usize) -> Option<usize> { | 1123 | 912 | let (parent_index, child_index893 ) = self.nodes.get(node_index).unwrap().parent?19 ; | 1124 | 893 | let parent = self.nodes.get(parent_index).unwrap(); | 1125 | | | 1126 | 2.77k | for idx in (u8::from(child_index) + 1)893 ..16 { | 1127 | 2.77k | if let Some(child646 ) = parent.children[usize::from(idx)] { | 1128 | 646 | return Some(child); | 1129 | 2.12k | } | 1130 | | } | 1131 | | | 1132 | 247 | None | 1133 | 912 | } |
|
1134 | | } |
1135 | | |
1136 | | impl<TUd> Default for TrieStructure<TUd> { |
1137 | 0 | fn default() -> Self { |
1138 | 0 | Self::new() |
1139 | 0 | } Unexecuted instantiation: _RNvXININtNtCsN16ciHI6Qf_7smoldot4trie14trie_structures_0pEINtB5_13TrieStructurepENtNtCsaYZPK01V26L_4core7default7Default7defaultB9_ Unexecuted instantiation: _RNvXININtNtCseuYC0Zibziv_7smoldot4trie14trie_structures_0pEINtB5_13TrieStructurepENtNtCsaYZPK01V26L_4core7default7Default7defaultB9_ |
1140 | | } |
1141 | | |
1142 | | impl<TUd: fmt::Debug> fmt::Debug for TrieStructure<TUd> { |
1143 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
1144 | 0 | f.debug_list() |
1145 | 0 | .entries( |
1146 | 0 | self.all_node_lexicographic_ordered() |
1147 | 0 | .map(|idx| (idx, self.nodes.get(idx).unwrap())), Unexecuted instantiation: _RNCNvXs0_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1e_NtNtB9_9trie_node17MerkleValueOutputEEENtNtB1i_3fmt5Debug3fmt0Bb_ Unexecuted instantiation: _RNCNvXs0_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB1e_NtNtB9_9trie_node17MerkleValueOutputEEENtNtB1i_3fmt5Debug3fmt0Bb_ Unexecuted instantiation: _RNCNvXs0_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_13TrieStructureuENtNtCsaYZPK01V26L_4core3fmt5Debug3fmt0Bb_ Unexecuted instantiation: _RNCNvXININtNtCseuYC0Zibziv_7smoldot4trie14trie_structures0_0pEINtB7_13TrieStructurepENtNtCsaYZPK01V26L_4core3fmt5Debug3fmt0Bb_ |
1148 | 0 | ) |
1149 | 0 | .finish() |
1150 | 0 | } Unexecuted instantiation: _RNvXs0_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEENtNtB1g_3fmt5Debug3fmtB9_ Unexecuted instantiation: _RNvXs0_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEENtNtB1g_3fmt5Debug3fmtB9_ Unexecuted instantiation: _RNvXs0_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureuENtNtCsaYZPK01V26L_4core3fmt5Debug3fmtB9_ Unexecuted instantiation: _RNvXININtNtCseuYC0Zibziv_7smoldot4trie14trie_structures0_0pEINtB5_13TrieStructurepENtNtCsaYZPK01V26L_4core3fmt5Debug3fmtB9_ |
1151 | | } |
1152 | | |
1153 | | impl<TUd> ops::Index<NodeIndex> for TrieStructure<TUd> { |
1154 | | type Output = TUd; |
1155 | | |
1156 | | #[track_caller] |
1157 | 1.91M | fn index(&self, node_index: NodeIndex) -> &TUd { |
1158 | 1.91M | &self.nodes[node_index.0].user_data |
1159 | 1.91M | } _RNvXs1_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEEINtNtNtB1g_3ops5index5IndexNtB5_9NodeIndexE5indexB9_ Line | Count | Source | 1157 | 1.44M | fn index(&self, node_index: NodeIndex) -> &TUd { | 1158 | 1.44M | &self.nodes[node_index.0].user_data | 1159 | 1.44M | } |
_RNvXs1_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEEINtNtNtB1g_3ops5index5IndexNtB5_9NodeIndexE5indexB9_ Line | Count | Source | 1157 | 467k | fn index(&self, node_index: NodeIndex) -> &TUd { | 1158 | 467k | &self.nodes[node_index.0].user_data | 1159 | 467k | } |
Unexecuted instantiation: _RNvXININtNtCseuYC0Zibziv_7smoldot4trie14trie_structures1_0pEINtB5_13TrieStructurepEINtNtNtCsaYZPK01V26L_4core3ops5index5IndexNtB5_9NodeIndexE5indexB9_ _RNvXs1_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1d_NtNtB7_9trie_node17MerkleValueOutputEEEINtNtNtB1h_3ops5index5IndexNtB5_9NodeIndexE5indexCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1157 | 96 | fn index(&self, node_index: NodeIndex) -> &TUd { | 1158 | 96 | &self.nodes[node_index.0].user_data | 1159 | 96 | } |
Unexecuted instantiation: _RNvXs1_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1d_NtNtB7_9trie_node17MerkleValueOutputEEEINtNtNtB1h_3ops5index5IndexNtB5_9NodeIndexE5indexCscDgN54JpMGG_6author _RNvXs1_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13TrieStructureTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1d_NtNtB7_9trie_node17MerkleValueOutputEEEINtNtNtB1h_3ops5index5IndexNtB5_9NodeIndexE5indexCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1157 | 912 | fn index(&self, node_index: NodeIndex) -> &TUd { | 1158 | 912 | &self.nodes[node_index.0].user_data | 1159 | 912 | } |
|
1160 | | } |
1161 | | |
1162 | | impl<TUd> ops::IndexMut<NodeIndex> for TrieStructure<TUd> { |
1163 | | #[track_caller] |
1164 | 0 | fn index_mut(&mut self, node_index: NodeIndex) -> &mut TUd { |
1165 | 0 | &mut self.nodes[node_index.0].user_data |
1166 | 0 | } Unexecuted instantiation: _RNvXININtNtCsN16ciHI6Qf_7smoldot4trie14trie_structures2_0pEINtB5_13TrieStructurepEINtNtNtCsaYZPK01V26L_4core3ops5index8IndexMutNtB5_9NodeIndexE9index_mutB9_ Unexecuted instantiation: _RNvXININtNtCseuYC0Zibziv_7smoldot4trie14trie_structures2_0pEINtB5_13TrieStructurepEINtNtNtCsaYZPK01V26L_4core3ops5index8IndexMutNtB5_9NodeIndexE9index_mutB9_ |
1167 | | } |
1168 | | |
1169 | | enum ExistingNodeInnerResult<I> { |
1170 | | Found { |
1171 | | node_index: usize, |
1172 | | has_storage_value: bool, |
1173 | | }, |
1174 | | NotFound { |
1175 | | /// Closest ancestor that actually exists. |
1176 | | /// If `Some`, also contains `desired_nibbles - closest_ancestor_key`. This iterator is |
1177 | | /// guaranteed to have at least one element. |
1178 | | closest_ancestor: Option<(usize, I)>, |
1179 | | }, |
1180 | | } |
1181 | | |
1182 | | /// Index of a node in the trie. Never invalidated, except when if node in question is destroyed. |
1183 | | /// |
1184 | | /// See [`TrieStructure::node_by_index`] for more information. |
1185 | | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
1186 | | pub struct NodeIndex(usize); |
1187 | | |
1188 | | /// Access to a entry for a potential node within the [`TrieStructure`]. |
1189 | | /// |
1190 | | /// See [`TrieStructure::node`] for more information. |
1191 | | pub enum Entry<'a, TUd, TKIter> { |
1192 | | /// There exists a node with this key. |
1193 | | Occupied(NodeAccess<'a, TUd>), |
1194 | | /// This entry is vacant. |
1195 | | Vacant(Vacant<'a, TUd, TKIter>), |
1196 | | } |
1197 | | |
1198 | | impl<'a, TUd, TKIter> Entry<'a, TUd, TKIter> { |
1199 | | /// Returns `Some` if `self` is an [`Entry::Vacant`]. |
1200 | 30 | pub fn into_vacant(self) -> Option<Vacant<'a, TUd, TKIter>> { |
1201 | 30 | match self { |
1202 | 30 | Entry::Vacant(e) => Some(e), |
1203 | 0 | _ => None, |
1204 | | } |
1205 | 30 | } _RNvMs3_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_5EntryuINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1b_5slice4iter4IterNtNtB7_6nibble6NibbleEEE11into_vacantB9_ Line | Count | Source | 1200 | 30 | pub fn into_vacant(self) -> Option<Vacant<'a, TUd, TKIter>> { | 1201 | 30 | match self { | 1202 | 30 | Entry::Vacant(e) => Some(e), | 1203 | 0 | _ => None, | 1204 | | } | 1205 | 30 | } |
Unexecuted instantiation: _RNvMs3_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_5EntryppE11into_vacantB9_ |
1206 | | |
1207 | | /// Returns `Some` if `self` is an [`Entry::Occupied`]. |
1208 | 6 | pub fn into_occupied(self) -> Option<NodeAccess<'a, TUd>> { |
1209 | 6 | match self { |
1210 | 6 | Entry::Occupied(e) => Some(e), |
1211 | 0 | _ => None, |
1212 | | } |
1213 | 6 | } _RNvMs3_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_5EntryuINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1b_5slice4iter4IterNtNtB7_6nibble6NibbleEEE13into_occupiedB9_ Line | Count | Source | 1208 | 6 | pub fn into_occupied(self) -> Option<NodeAccess<'a, TUd>> { | 1209 | 6 | match self { | 1210 | 6 | Entry::Occupied(e) => Some(e), | 1211 | 0 | _ => None, | 1212 | | } | 1213 | 6 | } |
Unexecuted instantiation: _RNvMs3_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_5EntryppE13into_occupiedB9_ |
1214 | | } |
1215 | | |
1216 | | /// Access to a node within the [`TrieStructure`]. |
1217 | | pub enum NodeAccess<'a, TUd> { |
1218 | | Storage(StorageNodeAccess<'a, TUd>), |
1219 | | Branch(BranchNodeAccess<'a, TUd>), |
1220 | | } |
1221 | | |
1222 | | impl<'a, TUd> NodeAccess<'a, TUd> { |
1223 | | /// Returns `Some` if `self` is an [`NodeAccess::Storage`]. |
1224 | 1 | pub fn into_storage(self) -> Option<StorageNodeAccess<'a, TUd>> { |
1225 | 1 | match self { |
1226 | 1 | NodeAccess::Storage(e) => Some(e), |
1227 | 0 | _ => None, |
1228 | | } |
1229 | 1 | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessuE12into_storageB9_ Line | Count | Source | 1224 | 1 | pub fn into_storage(self) -> Option<StorageNodeAccess<'a, TUd>> { | 1225 | 1 | match self { | 1226 | 1 | NodeAccess::Storage(e) => Some(e), | 1227 | 0 | _ => None, | 1228 | | } | 1229 | 1 | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccesspE12into_storageB9_ |
1230 | | |
1231 | | /// Returns an opaque [`NodeIndex`] representing the node in the trie. |
1232 | | /// |
1233 | | /// It can later be used to retrieve this same node using [`TrieStructure::node_by_index`]. |
1234 | 1.50k | pub fn node_index(&self) -> NodeIndex { |
1235 | 1.50k | match self { |
1236 | 1.50k | NodeAccess::Storage(n) => n.node_index(), |
1237 | 0 | NodeAccess::Branch(n) => n.node_index(), |
1238 | | } |
1239 | 1.50k | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE10node_indexB9_ Line | Count | Source | 1234 | 1.50k | pub fn node_index(&self) -> NodeIndex { | 1235 | 1.50k | match self { | 1236 | 1.50k | NodeAccess::Storage(n) => n.node_index(), | 1237 | 0 | NodeAccess::Branch(n) => n.node_index(), | 1238 | | } | 1239 | 1.50k | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE10node_indexB9_ |
1240 | | |
1241 | | /// Returns the parent of this node, or `None` if this is the root node. |
1242 | 9.26k | pub fn into_parent(self) -> Option<NodeAccess<'a, TUd>> { |
1243 | 9.26k | match self { |
1244 | 9.26k | NodeAccess::Storage(n) => n.into_parent(), |
1245 | 0 | NodeAccess::Branch(n) => n.into_parent(), |
1246 | | } |
1247 | 9.26k | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE11into_parentB9_ Line | Count | Source | 1242 | 9.26k | pub fn into_parent(self) -> Option<NodeAccess<'a, TUd>> { | 1243 | 9.26k | match self { | 1244 | 9.26k | NodeAccess::Storage(n) => n.into_parent(), | 1245 | 0 | NodeAccess::Branch(n) => n.into_parent(), | 1246 | | } | 1247 | 9.26k | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE11into_parentB9_ |
1248 | | |
1249 | | /// Returns the parent of this node, or `None` if this is the root node. |
1250 | 0 | pub fn parent(&mut self) -> Option<NodeAccess<TUd>> { |
1251 | 0 | match self { |
1252 | 0 | NodeAccess::Storage(n) => n.parent(), |
1253 | 0 | NodeAccess::Branch(n) => n.parent(), |
1254 | | } |
1255 | 0 | } Unexecuted instantiation: _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccesspE6parentB9_ Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccesspE6parentB9_ |
1256 | | |
1257 | | /// Returns the user data of the child at the given index. |
1258 | | /// |
1259 | | /// > **Note**: This method exists because it accepts `&self` rather than `&mut self`. A |
1260 | | /// > cleaner alternative would be to split the [`NodeAccess`] struct into |
1261 | | /// > `NodeAccessRef` and `NodeAccessMut`, but that's a lot of efforts compare to |
1262 | | /// > this single method. |
1263 | 922k | pub fn child_user_data(&self, index: Nibble) -> Option<&TUd> { |
1264 | 922k | match self { |
1265 | 832k | NodeAccess::Storage(n) => n.child_user_data(index), |
1266 | 89.4k | NodeAccess::Branch(n) => n.child_user_data(index), |
1267 | | } |
1268 | 922k | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE15child_user_dataB9_ Line | Count | Source | 1263 | 461k | pub fn child_user_data(&self, index: Nibble) -> Option<&TUd> { | 1264 | 461k | match self { | 1265 | 461k | NodeAccess::Storage(n) => n.child_user_data(index), | 1266 | 0 | NodeAccess::Branch(n) => n.child_user_data(index), | 1267 | | } | 1268 | 461k | } |
_RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessuE15child_user_dataB9_ Line | Count | Source | 1263 | 461k | pub fn child_user_data(&self, index: Nibble) -> Option<&TUd> { | 1264 | 461k | match self { | 1265 | 371k | NodeAccess::Storage(n) => n.child_user_data(index), | 1266 | 89.4k | NodeAccess::Branch(n) => n.child_user_data(index), | 1267 | | } | 1268 | 461k | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE15child_user_dataB9_ |
1269 | | |
1270 | | /// Returns the child of this node at the given index. |
1271 | 7.59M | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { |
1272 | 7.59M | match self { |
1273 | 6.46M | NodeAccess::Storage(n) => n.child(index), |
1274 | 1.12M | NodeAccess::Branch(n) => n.child(index), |
1275 | | } |
1276 | 7.59M | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB7_9trie_node17MerkleValueOutputEEE5childB9_ Line | Count | Source | 1271 | 82.6k | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1272 | 82.6k | match self { | 1273 | 80.5k | NodeAccess::Storage(n) => n.child(index), | 1274 | 2.17k | NodeAccess::Branch(n) => n.child(index), | 1275 | | } | 1276 | 82.6k | } |
_RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB19_NtNtB7_9trie_node17MerkleValueOutputEEE5childB9_ Line | Count | Source | 1271 | 7.48M | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1272 | 7.48M | match self { | 1273 | 6.36M | NodeAccess::Storage(n) => n.child(index), | 1274 | 1.11M | NodeAccess::Branch(n) => n.child(index), | 1275 | | } | 1276 | 7.48M | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccesspE5childB9_ _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE5childCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1271 | 3.07k | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1272 | 3.07k | match self { | 1273 | 2.24k | NodeAccess::Storage(n) => n.child(index), | 1274 | 832 | NodeAccess::Branch(n) => n.child(index), | 1275 | | } | 1276 | 3.07k | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE5childCscDgN54JpMGG_6author _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE5childCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1271 | 29.1k | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1272 | 29.1k | match self { | 1273 | 21.2k | NodeAccess::Storage(n) => n.child(index), | 1274 | 7.90k | NodeAccess::Branch(n) => n.child(index), | 1275 | | } | 1276 | 29.1k | } |
|
1277 | | |
1278 | | /// Returns the child of this node given the given index. |
1279 | | /// |
1280 | | /// Returns back `self` if there is no such child at this index. |
1281 | 0 | pub fn into_child(self, index: Nibble) -> Result<NodeAccess<'a, TUd>, Self> { |
1282 | 0 | match self { |
1283 | 0 | NodeAccess::Storage(n) => n.into_child(index).map_err(NodeAccess::Storage), |
1284 | 0 | NodeAccess::Branch(n) => n.into_child(index).map_err(NodeAccess::Branch), |
1285 | | } |
1286 | 0 | } Unexecuted instantiation: _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccesspE10into_childB9_ Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccesspE10into_childB9_ |
1287 | | |
1288 | | /// Returns the first child of this node. |
1289 | | /// |
1290 | | /// Returns back `self` if this node doesn't have any children. |
1291 | 28.8k | pub fn into_first_child(self) -> Result<NodeAccess<'a, TUd>, Self> { |
1292 | 28.8k | match self { |
1293 | 28.8k | NodeAccess::Storage(n) => n.into_first_child().map_err(NodeAccess::Storage), |
1294 | 0 | NodeAccess::Branch(n) => n.into_first_child().map_err(NodeAccess::Branch), |
1295 | | } |
1296 | 28.8k | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE16into_first_childB9_ Line | Count | Source | 1291 | 28.8k | pub fn into_first_child(self) -> Result<NodeAccess<'a, TUd>, Self> { | 1292 | 28.8k | match self { | 1293 | 28.8k | NodeAccess::Storage(n) => n.into_first_child().map_err(NodeAccess::Storage), | 1294 | 0 | NodeAccess::Branch(n) => n.into_first_child().map_err(NodeAccess::Branch), | 1295 | | } | 1296 | 28.8k | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE16into_first_childB9_ |
1297 | | |
1298 | | /// Returns the next sibling of this node. |
1299 | | /// |
1300 | | /// Returns back `self` if this node is the last child of its parent. |
1301 | 28.8k | pub fn into_next_sibling(self) -> Result<NodeAccess<'a, TUd>, Self> { |
1302 | 28.8k | match self { |
1303 | 28.8k | NodeAccess::Storage(n) => n.into_next_sibling().map_err(NodeAccess::Storage), |
1304 | 0 | NodeAccess::Branch(n) => n.into_next_sibling().map_err(NodeAccess::Branch), |
1305 | | } |
1306 | 28.8k | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE17into_next_siblingB9_ Line | Count | Source | 1301 | 28.8k | pub fn into_next_sibling(self) -> Result<NodeAccess<'a, TUd>, Self> { | 1302 | 28.8k | match self { | 1303 | 28.8k | NodeAccess::Storage(n) => n.into_next_sibling().map_err(NodeAccess::Storage), | 1304 | 0 | NodeAccess::Branch(n) => n.into_next_sibling().map_err(NodeAccess::Branch), | 1305 | | } | 1306 | 28.8k | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE17into_next_siblingB9_ |
1307 | | |
1308 | | /// Returns true if this node is the root node of the trie. |
1309 | 471k | pub fn is_root_node(&self) -> bool { |
1310 | 471k | match self { |
1311 | 401k | NodeAccess::Storage(n) => n.is_root_node(), |
1312 | 70.1k | NodeAccess::Branch(n) => n.is_root_node(), |
1313 | | } |
1314 | 471k | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeB9_ Line | Count | Source | 1309 | 2.58k | pub fn is_root_node(&self) -> bool { | 1310 | 2.58k | match self { | 1311 | 2.51k | NodeAccess::Storage(n) => n.is_root_node(), | 1312 | 68 | NodeAccess::Branch(n) => n.is_root_node(), | 1313 | | } | 1314 | 2.58k | } |
_RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB19_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeB9_ Line | Count | Source | 1309 | 467k | pub fn is_root_node(&self) -> bool { | 1310 | 467k | match self { | 1311 | 397k | NodeAccess::Storage(n) => n.is_root_node(), | 1312 | 69.7k | NodeAccess::Branch(n) => n.is_root_node(), | 1313 | | } | 1314 | 467k | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccesspE12is_root_nodeB9_ _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1309 | 96 | pub fn is_root_node(&self) -> bool { | 1310 | 96 | match self { | 1311 | 70 | NodeAccess::Storage(n) => n.is_root_node(), | 1312 | 26 | NodeAccess::Branch(n) => n.is_root_node(), | 1313 | | } | 1314 | 96 | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeCscDgN54JpMGG_6author _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1309 | 912 | pub fn is_root_node(&self) -> bool { | 1310 | 912 | match self { | 1311 | 665 | NodeAccess::Storage(n) => n.is_root_node(), | 1312 | 247 | NodeAccess::Branch(n) => n.is_root_node(), | 1313 | | } | 1314 | 912 | } |
|
1315 | | |
1316 | | /// Returns the full key of the node. |
1317 | 0 | pub fn full_key(&'_ self) -> impl Iterator<Item = Nibble> + '_ { |
1318 | 0 | match self { |
1319 | 0 | NodeAccess::Storage(n) => Either::Left(n.full_key()), |
1320 | 0 | NodeAccess::Branch(n) => Either::Right(n.full_key()), |
1321 | | } |
1322 | 0 | } Unexecuted instantiation: _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccesspE8full_keyB9_ Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccesspE8full_keyB9_ |
1323 | | |
1324 | | /// Returns the partial key of the node. |
1325 | 503k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { |
1326 | 503k | match self { |
1327 | 427k | NodeAccess::Storage(n) => Either::Left(n.partial_key()), |
1328 | 76.0k | NodeAccess::Branch(n) => Either::Right(n.partial_key()), |
1329 | | } |
1330 | 503k | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyB9_ Line | Count | Source | 1325 | 5.16k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1326 | 5.16k | match self { | 1327 | 5.03k | NodeAccess::Storage(n) => Either::Left(n.partial_key()), | 1328 | 136 | NodeAccess::Branch(n) => Either::Right(n.partial_key()), | 1329 | | } | 1330 | 5.16k | } |
_RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB19_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyB9_ Line | Count | Source | 1325 | 467k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1326 | 467k | match self { | 1327 | 397k | NodeAccess::Storage(n) => Either::Left(n.partial_key()), | 1328 | 69.7k | NodeAccess::Branch(n) => Either::Right(n.partial_key()), | 1329 | | } | 1330 | 467k | } |
_RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessuE11partial_keyB9_ Line | Count | Source | 1325 | 28.8k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1326 | 28.8k | match self { | 1327 | 23.2k | NodeAccess::Storage(n) => Either::Left(n.partial_key()), | 1328 | 5.58k | NodeAccess::Branch(n) => Either::Right(n.partial_key()), | 1329 | | } | 1330 | 28.8k | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccesspE11partial_keyB9_ _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1325 | 192 | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1326 | 192 | match self { | 1327 | 140 | NodeAccess::Storage(n) => Either::Left(n.partial_key()), | 1328 | 52 | NodeAccess::Branch(n) => Either::Right(n.partial_key()), | 1329 | | } | 1330 | 192 | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyCscDgN54JpMGG_6author _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1325 | 1.82k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1326 | 1.82k | match self { | 1327 | 1.33k | NodeAccess::Storage(n) => Either::Left(n.partial_key()), | 1328 | 494 | NodeAccess::Branch(n) => Either::Right(n.partial_key()), | 1329 | | } | 1330 | 1.82k | } |
|
1331 | | |
1332 | | /// Returns the user data stored in the node. |
1333 | 1.41M | pub fn user_data(&mut self) -> &mut TUd { |
1334 | 1.41M | match self { |
1335 | 1.21M | NodeAccess::Storage(n) => n.user_data(), |
1336 | 199k | NodeAccess::Branch(n) => n.user_data(), |
1337 | | } |
1338 | 1.41M | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE9user_dataB9_ Line | Count | Source | 1333 | 70.4k | pub fn user_data(&mut self) -> &mut TUd { | 1334 | 70.4k | match self { | 1335 | 70.4k | NodeAccess::Storage(n) => n.user_data(), | 1336 | 0 | NodeAccess::Branch(n) => n.user_data(), | 1337 | | } | 1338 | 70.4k | } |
_RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataB9_ Line | Count | Source | 1333 | 5.70k | pub fn user_data(&mut self) -> &mut TUd { | 1334 | 5.70k | match self { | 1335 | 5.50k | NodeAccess::Storage(n) => n.user_data(), | 1336 | 204 | NodeAccess::Branch(n) => n.user_data(), | 1337 | | } | 1338 | 5.70k | } |
_RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB19_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataB9_ Line | Count | Source | 1333 | 1.33M | pub fn user_data(&mut self) -> &mut TUd { | 1334 | 1.33M | match self { | 1335 | 1.13M | NodeAccess::Storage(n) => n.user_data(), | 1336 | 198k | NodeAccess::Branch(n) => n.user_data(), | 1337 | | } | 1338 | 1.33M | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE9user_dataB9_ _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1333 | 380 | pub fn user_data(&mut self) -> &mut TUd { | 1334 | 380 | match self { | 1335 | 280 | NodeAccess::Storage(n) => n.user_data(), | 1336 | 100 | NodeAccess::Branch(n) => n.user_data(), | 1337 | | } | 1338 | 380 | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataCscDgN54JpMGG_6author _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1333 | 3.61k | pub fn user_data(&mut self) -> &mut TUd { | 1334 | 3.61k | match self { | 1335 | 2.66k | NodeAccess::Storage(n) => n.user_data(), | 1336 | 950 | NodeAccess::Branch(n) => n.user_data(), | 1337 | | } | 1338 | 3.61k | } |
|
1339 | | |
1340 | | /// Returns the user data stored in the node. |
1341 | 487k | pub fn into_user_data(self) -> &'a mut TUd { |
1342 | 487k | match self { |
1343 | 416k | NodeAccess::Storage(n) => n.into_user_data(), |
1344 | 70.8k | NodeAccess::Branch(n) => n.into_user_data(), |
1345 | | } |
1346 | 487k | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB19_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataB9_ Line | Count | Source | 1341 | 2.58k | pub fn into_user_data(self) -> &'a mut TUd { | 1342 | 2.58k | match self { | 1343 | 2.51k | NodeAccess::Storage(n) => n.into_user_data(), | 1344 | 68 | NodeAccess::Branch(n) => n.into_user_data(), | 1345 | | } | 1346 | 2.58k | } |
_RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB19_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataB9_ Line | Count | Source | 1341 | 483k | pub fn into_user_data(self) -> &'a mut TUd { | 1342 | 483k | match self { | 1343 | 413k | NodeAccess::Storage(n) => n.into_user_data(), | 1344 | 70.4k | NodeAccess::Branch(n) => n.into_user_data(), | 1345 | | } | 1346 | 483k | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccesspE14into_user_dataB9_ _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1341 | 96 | pub fn into_user_data(self) -> &'a mut TUd { | 1342 | 96 | match self { | 1343 | 70 | NodeAccess::Storage(n) => n.into_user_data(), | 1344 | 26 | NodeAccess::Branch(n) => n.into_user_data(), | 1345 | | } | 1346 | 96 | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataCscDgN54JpMGG_6author _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1a_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1341 | 912 | pub fn into_user_data(self) -> &'a mut TUd { | 1342 | 912 | match self { | 1343 | 665 | NodeAccess::Storage(n) => n.into_user_data(), | 1344 | 247 | NodeAccess::Branch(n) => n.into_user_data(), | 1345 | | } | 1346 | 912 | } |
|
1347 | | |
1348 | | /// Returns true if the node has a storage value associated to it. |
1349 | 28.8k | pub fn has_storage_value(&self) -> bool { |
1350 | 28.8k | match self { |
1351 | 23.2k | NodeAccess::Storage(_) => true, |
1352 | 5.58k | NodeAccess::Branch(_) => false, |
1353 | | } |
1354 | 28.8k | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_10NodeAccessuE17has_storage_valueB9_ Line | Count | Source | 1349 | 28.8k | pub fn has_storage_value(&self) -> bool { | 1350 | 28.8k | match self { | 1351 | 23.2k | NodeAccess::Storage(_) => true, | 1352 | 5.58k | NodeAccess::Branch(_) => false, | 1353 | | } | 1354 | 28.8k | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_10NodeAccesspE17has_storage_valueB9_ |
1355 | | } |
1356 | | |
1357 | | /// Access to a node within the [`TrieStructure`] that is known to have a storage value associated |
1358 | | /// to it. |
1359 | | pub struct StorageNodeAccess<'a, TUd> { |
1360 | | trie: &'a mut TrieStructure<TUd>, |
1361 | | node_index: usize, |
1362 | | } |
1363 | | |
1364 | | impl<'a, TUd> StorageNodeAccess<'a, TUd> { |
1365 | | /// Returns an opaque [`NodeIndex`] representing the node in the trie. |
1366 | | /// |
1367 | | /// It can later be used to retrieve this same node using [`TrieStructure::node_by_index`]. |
1368 | 1.50k | pub fn node_index(&self) -> NodeIndex { |
1369 | 1.50k | NodeIndex(self.node_index) |
1370 | 1.50k | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE10node_indexB9_ Line | Count | Source | 1368 | 1.50k | pub fn node_index(&self) -> NodeIndex { | 1369 | 1.50k | NodeIndex(self.node_index) | 1370 | 1.50k | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE10node_indexB9_ |
1371 | | |
1372 | | /// Returns the parent of this node, or `None` if this is the root node. |
1373 | 9.26k | pub fn into_parent(self) -> Option<NodeAccess<'a, TUd>> { |
1374 | 9.26k | let parent_idx7.76k = self.trie.nodes.get(self.node_index).unwrap().parent?1.50k .0; |
1375 | 7.76k | Some(self.trie.node_by_index_inner(parent_idx).unwrap()) |
1376 | 9.26k | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE11into_parentB9_ Line | Count | Source | 1373 | 9.26k | pub fn into_parent(self) -> Option<NodeAccess<'a, TUd>> { | 1374 | 9.26k | let parent_idx7.76k = self.trie.nodes.get(self.node_index).unwrap().parent?1.50k .0; | 1375 | 7.76k | Some(self.trie.node_by_index_inner(parent_idx).unwrap()) | 1376 | 9.26k | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE11into_parentB9_ |
1377 | | |
1378 | | /// Returns the parent of this node, or `None` if this is the root node. |
1379 | 0 | pub fn parent(&mut self) -> Option<NodeAccess<TUd>> { |
1380 | 0 | let parent_idx = self.trie.nodes.get(self.node_index).unwrap().parent?.0; |
1381 | 0 | Some(self.trie.node_by_index_inner(parent_idx).unwrap()) |
1382 | 0 | } Unexecuted instantiation: _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE6parentB9_ Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE6parentB9_ |
1383 | | |
1384 | | /// Returns the first child of this node. |
1385 | | /// |
1386 | | /// Returns back `self` if this node doesn't have any children. |
1387 | 28.8k | pub fn into_first_child(self) -> Result<NodeAccess<'a, TUd>, Self> { |
1388 | 28.8k | let first_child_idx = self |
1389 | 28.8k | .trie |
1390 | 28.8k | .nodes |
1391 | 28.8k | .get(self.node_index) |
1392 | 28.8k | .unwrap() |
1393 | 28.8k | .children |
1394 | 28.8k | .iter() |
1395 | 374k | .find_map(|c| *c)28.8k ; _RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB9_12proof_encode4NodeEE16into_first_child0Bb_ Line | Count | Source | 1395 | 374k | .find_map(|c| *c); |
Unexecuted instantiation: _RNCNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB9_12proof_encode4NodeEE16into_first_child0Bb_ |
1396 | | |
1397 | 28.8k | let first_child_idx7.76k = match first_child_idx { |
1398 | 7.76k | Some(fc) => fc, |
1399 | 21.0k | None => return Err(self), |
1400 | | }; |
1401 | | |
1402 | 7.76k | Ok(self.trie.node_by_index_inner(first_child_idx).unwrap()) |
1403 | 28.8k | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE16into_first_childB9_ Line | Count | Source | 1387 | 28.8k | pub fn into_first_child(self) -> Result<NodeAccess<'a, TUd>, Self> { | 1388 | 28.8k | let first_child_idx = self | 1389 | 28.8k | .trie | 1390 | 28.8k | .nodes | 1391 | 28.8k | .get(self.node_index) | 1392 | 28.8k | .unwrap() | 1393 | 28.8k | .children | 1394 | 28.8k | .iter() | 1395 | 28.8k | .find_map(|c| *c); | 1396 | | | 1397 | 28.8k | let first_child_idx7.76k = match first_child_idx { | 1398 | 7.76k | Some(fc) => fc, | 1399 | 21.0k | None => return Err(self), | 1400 | | }; | 1401 | | | 1402 | 7.76k | Ok(self.trie.node_by_index_inner(first_child_idx).unwrap()) | 1403 | 28.8k | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE16into_first_childB9_ |
1404 | | |
1405 | | /// Returns the next sibling of this node. |
1406 | | /// |
1407 | | /// Returns back `self` if this node is the last child of its parent. |
1408 | 28.8k | pub fn into_next_sibling(self) -> Result<NodeAccess<'a, TUd>, Self> { |
1409 | 28.8k | let next_sibling_idx19.5k = match self.trie.next_sibling(self.node_index) { |
1410 | 19.5k | Some(ns) => ns, |
1411 | 9.26k | None => return Err(self), |
1412 | | }; |
1413 | | |
1414 | 19.5k | Ok(self.trie.node_by_index_inner(next_sibling_idx).unwrap()) |
1415 | 28.8k | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE17into_next_siblingB9_ Line | Count | Source | 1408 | 28.8k | pub fn into_next_sibling(self) -> Result<NodeAccess<'a, TUd>, Self> { | 1409 | 28.8k | let next_sibling_idx19.5k = match self.trie.next_sibling(self.node_index) { | 1410 | 19.5k | Some(ns) => ns, | 1411 | 9.26k | None => return Err(self), | 1412 | | }; | 1413 | | | 1414 | 19.5k | Ok(self.trie.node_by_index_inner(next_sibling_idx).unwrap()) | 1415 | 28.8k | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE17into_next_siblingB9_ |
1416 | | |
1417 | | /// Returns the child of this node at the given index. |
1418 | 6.46M | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { |
1419 | 202k | let child_idx = |
1420 | 6.46M | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?6.26M ; |
1421 | 202k | Some(self.trie.node_by_index_inner(child_idx).unwrap()) |
1422 | 6.46M | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE5childB9_ Line | Count | Source | 1418 | 80.5k | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1419 | 2.84k | let child_idx = | 1420 | 80.5k | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?77.6k ; | 1421 | 2.84k | Some(self.trie.node_by_index_inner(child_idx).unwrap()) | 1422 | 80.5k | } |
_RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE5childB9_ Line | Count | Source | 1418 | 6.36M | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1419 | 199k | let child_idx = | 1420 | 6.36M | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?6.16M ; | 1421 | 199k | Some(self.trie.node_by_index_inner(child_idx).unwrap()) | 1422 | 6.36M | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE5childB9_ _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE5childCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1418 | 2.24k | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1419 | 0 | let child_idx = | 1420 | 2.24k | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?; | 1421 | 0 | Some(self.trie.node_by_index_inner(child_idx).unwrap()) | 1422 | 2.24k | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE5childCscDgN54JpMGG_6author _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE5childCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1418 | 21.2k | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1419 | 0 | let child_idx = | 1420 | 21.2k | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?; | 1421 | 0 | Some(self.trie.node_by_index_inner(child_idx).unwrap()) | 1422 | 21.2k | } |
|
1423 | | |
1424 | | /// Returns the user data of the child at the given index. |
1425 | | /// |
1426 | | /// > **Note**: This method exists because it accepts `&self` rather than `&mut self`. A |
1427 | | /// > cleaner alternative would be to split the [`NodeAccess`] struct into |
1428 | | /// > `NodeAccessRef` and `NodeAccessMut`, but that's a lot of efforts compare to |
1429 | | /// > this single method. |
1430 | 832k | pub fn child_user_data(&self, index: Nibble) -> Option<&TUd> { |
1431 | 39.0k | let child_idx = |
1432 | 832k | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?793k ; |
1433 | 39.0k | Some(&self.trie.nodes.get(child_idx).unwrap().user_data) |
1434 | 832k | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE15child_user_dataB9_ Line | Count | Source | 1430 | 461k | pub fn child_user_data(&self, index: Nibble) -> Option<&TUd> { | 1431 | 27.3k | let child_idx = | 1432 | 461k | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?433k ; | 1433 | 27.3k | Some(&self.trie.nodes.get(child_idx).unwrap().user_data) | 1434 | 461k | } |
_RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessuE15child_user_dataB9_ Line | Count | Source | 1430 | 371k | pub fn child_user_data(&self, index: Nibble) -> Option<&TUd> { | 1431 | 11.7k | let child_idx = | 1432 | 371k | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?359k ; | 1433 | 11.7k | Some(&self.trie.nodes.get(child_idx).unwrap().user_data) | 1434 | 371k | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE15child_user_dataB9_ |
1435 | | |
1436 | | /// Returns the child of this node given the given index. |
1437 | | /// |
1438 | | /// Returns back `self` if there is no such child at this index. |
1439 | 0 | pub fn into_child(self, index: Nibble) -> Result<NodeAccess<'a, TUd>, Self> { |
1440 | 0 | let child_idx = match self.trie.nodes.get(self.node_index).unwrap().children |
1441 | 0 | [usize::from(u8::from(index))] |
1442 | | { |
1443 | 0 | Some(c) => c, |
1444 | 0 | None => return Err(self), |
1445 | | }; |
1446 | | |
1447 | 0 | Ok(self.trie.node_by_index_inner(child_idx).unwrap()) |
1448 | 0 | } Unexecuted instantiation: _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE10into_childB9_ Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE10into_childB9_ |
1449 | | |
1450 | | /// Returns true if this node is the root node of the trie. |
1451 | 401k | pub fn is_root_node(&self) -> bool { |
1452 | 401k | self.trie.root_index == Some(self.node_index) |
1453 | 401k | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeB9_ Line | Count | Source | 1451 | 2.51k | pub fn is_root_node(&self) -> bool { | 1452 | 2.51k | self.trie.root_index == Some(self.node_index) | 1453 | 2.51k | } |
_RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeB9_ Line | Count | Source | 1451 | 397k | pub fn is_root_node(&self) -> bool { | 1452 | 397k | self.trie.root_index == Some(self.node_index) | 1453 | 397k | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE12is_root_nodeB9_ _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1451 | 70 | pub fn is_root_node(&self) -> bool { | 1452 | 70 | self.trie.root_index == Some(self.node_index) | 1453 | 70 | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeCscDgN54JpMGG_6author _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1451 | 665 | pub fn is_root_node(&self) -> bool { | 1452 | 665 | self.trie.root_index == Some(self.node_index) | 1453 | 665 | } |
|
1454 | | |
1455 | | /// Returns the full key of the node. |
1456 | 0 | pub fn full_key(&'_ self) -> impl Iterator<Item = Nibble> + '_ { |
1457 | 0 | self.trie.node_full_key(self.node_index) |
1458 | 0 | } Unexecuted instantiation: _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE8full_keyB9_ Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE8full_keyB9_ |
1459 | | |
1460 | | /// Returns the partial key of the node. |
1461 | 427k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { |
1462 | 427k | self.trie |
1463 | 427k | .nodes |
1464 | 427k | .get(self.node_index) |
1465 | 427k | .unwrap() |
1466 | 427k | .partial_key |
1467 | 427k | .iter() |
1468 | 427k | .cloned() |
1469 | 427k | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyB9_ Line | Count | Source | 1461 | 5.03k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1462 | 5.03k | self.trie | 1463 | 5.03k | .nodes | 1464 | 5.03k | .get(self.node_index) | 1465 | 5.03k | .unwrap() | 1466 | 5.03k | .partial_key | 1467 | 5.03k | .iter() | 1468 | 5.03k | .cloned() | 1469 | 5.03k | } |
_RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyB9_ Line | Count | Source | 1461 | 397k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1462 | 397k | self.trie | 1463 | 397k | .nodes | 1464 | 397k | .get(self.node_index) | 1465 | 397k | .unwrap() | 1466 | 397k | .partial_key | 1467 | 397k | .iter() | 1468 | 397k | .cloned() | 1469 | 397k | } |
_RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessuE11partial_keyB9_ Line | Count | Source | 1461 | 23.2k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1462 | 23.2k | self.trie | 1463 | 23.2k | .nodes | 1464 | 23.2k | .get(self.node_index) | 1465 | 23.2k | .unwrap() | 1466 | 23.2k | .partial_key | 1467 | 23.2k | .iter() | 1468 | 23.2k | .cloned() | 1469 | 23.2k | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE11partial_keyB9_ _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1461 | 140 | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1462 | 140 | self.trie | 1463 | 140 | .nodes | 1464 | 140 | .get(self.node_index) | 1465 | 140 | .unwrap() | 1466 | 140 | .partial_key | 1467 | 140 | .iter() | 1468 | 140 | .cloned() | 1469 | 140 | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyCscDgN54JpMGG_6author _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1461 | 1.33k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1462 | 1.33k | self.trie | 1463 | 1.33k | .nodes | 1464 | 1.33k | .get(self.node_index) | 1465 | 1.33k | .unwrap() | 1466 | 1.33k | .partial_key | 1467 | 1.33k | .iter() | 1468 | 1.33k | .cloned() | 1469 | 1.33k | } |
|
1470 | | |
1471 | | /// Returns the user data associated to this node. |
1472 | 481k | pub fn into_user_data(self) -> &'a mut TUd { |
1473 | 481k | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data |
1474 | 481k | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataB9_ Line | Count | Source | 1472 | 2.51k | pub fn into_user_data(self) -> &'a mut TUd { | 1473 | 2.51k | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1474 | 2.51k | } |
_RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataB9_ Line | Count | Source | 1472 | 478k | pub fn into_user_data(self) -> &'a mut TUd { | 1473 | 478k | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1474 | 478k | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE14into_user_dataB9_ _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1472 | 70 | pub fn into_user_data(self) -> &'a mut TUd { | 1473 | 70 | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1474 | 70 | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataCscDgN54JpMGG_6author _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1472 | 665 | pub fn into_user_data(self) -> &'a mut TUd { | 1473 | 665 | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1474 | 665 | } |
|
1475 | | |
1476 | | /// Returns the user data associated to this node. |
1477 | 1.38M | pub fn user_data(&mut self) -> &mut TUd { |
1478 | 1.38M | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data |
1479 | 1.38M | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE9user_dataB9_ Line | Count | Source | 1477 | 70.4k | pub fn user_data(&mut self) -> &mut TUd { | 1478 | 70.4k | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1479 | 70.4k | } |
_RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataB9_ Line | Count | Source | 1477 | 5.50k | pub fn user_data(&mut self) -> &mut TUd { | 1478 | 5.50k | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1479 | 5.50k | } |
_RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataB9_ Line | Count | Source | 1477 | 1.31M | pub fn user_data(&mut self) -> &mut TUd { | 1478 | 1.31M | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1479 | 1.31M | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE9user_dataB9_ _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1477 | 280 | pub fn user_data(&mut self) -> &mut TUd { | 1478 | 280 | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1479 | 280 | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataCscDgN54JpMGG_6author _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1h_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1477 | 2.66k | pub fn user_data(&mut self) -> &mut TUd { | 1478 | 2.66k | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1479 | 2.66k | } |
|
1480 | | |
1481 | | /// Removes the storage value and returns what this changes in the trie structure. |
1482 | 135k | pub fn remove(self) -> Remove<'a, TUd> { |
1483 | 135k | // If the removed node has 2 or more children, then the node continues as a branch node. |
1484 | 135k | { |
1485 | 135k | let node = self.trie.nodes.get_mut(self.node_index).unwrap(); |
1486 | 2.16M | if node.children.iter().filter(|c| c.is_some()).count() >= 2135k { _RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB1i_NtNtB9_9trie_node17MerkleValueOutputEEE6remove0Bb_ Line | Count | Source | 1486 | 1.37M | if node.children.iter().filter(|c| c.is_some()).count() >= 2 { |
_RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessuE6remove0Bb_ Line | Count | Source | 1486 | 787k | if node.children.iter().filter(|c| c.is_some()).count() >= 2 { |
Unexecuted instantiation: _RNCNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_17StorageNodeAccesspE6remove0Bb_ |
1487 | 72.0k | node.has_storage_value = false; |
1488 | 72.0k | return Remove::StorageToBranch(BranchNodeAccess { |
1489 | 72.0k | trie: self.trie, |
1490 | 72.0k | node_index: self.node_index, |
1491 | 72.0k | }); |
1492 | 62.9k | } |
1493 | 62.9k | } |
1494 | 62.9k | |
1495 | 62.9k | let removed_node = self.trie.nodes.remove(self.node_index); |
1496 | 62.9k | debug_assert!(removed_node.has_storage_value); |
1497 | | |
1498 | | // We already know from above that the removed node has only 0 or 1 children. Let's |
1499 | | // determine which. |
1500 | 915k | let child_node_index: Option<usize> = removed_node.children.iter().find_map(62.9k |c| *c)62.9k ; _RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB1i_NtNtB9_9trie_node17MerkleValueOutputEEE6removes_0Bb_ Line | Count | Source | 1500 | 176k | let child_node_index: Option<usize> = removed_node.children.iter().find_map(|c| *c); |
_RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessuE6removes_0Bb_ Line | Count | Source | 1500 | 738k | let child_node_index: Option<usize> = removed_node.children.iter().find_map(|c| *c); |
Unexecuted instantiation: _RNCNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_17StorageNodeAccesspE6removes_0Bb_ |
1501 | | |
1502 | | // If relevant, update our single child's parent to point to `removed_node`'s parent. |
1503 | 62.9k | if let Some(child_node_index12.3k ) = child_node_index { |
1504 | 12.3k | let child = self.trie.nodes.get_mut(child_node_index).unwrap(); |
1505 | 12.3k | debug_assert_eq!(child.parent.as_ref().unwrap().0, self.node_index); |
1506 | 12.3k | insert_front( |
1507 | 12.3k | &mut child.partial_key, |
1508 | 12.3k | removed_node.partial_key, |
1509 | 12.3k | child.parent.unwrap().1, |
1510 | 12.3k | ); |
1511 | 12.3k | child.parent = removed_node.parent; |
1512 | 50.6k | } |
1513 | | |
1514 | | // At this point, we're almost done with removing `removed_node` from `self.trie`. However |
1515 | | // there is potentially another change to make: maybe `parent` has to be removed from the |
1516 | | // trie as well. |
1517 | | |
1518 | | // Update `parent`'s child to point to `child_node_index`. |
1519 | | // `single_remove` is true if we can keep `parent` in the trie. |
1520 | 62.9k | let single_remove = if let Some((parent_index, parent_to_removed_child_index47.5k )) = |
1521 | 62.9k | removed_node.parent |
1522 | | { |
1523 | | // Update `removed_node`'s parent to point to the child. |
1524 | 47.5k | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); |
1525 | 47.5k | debug_assert_eq!( |
1526 | 47.5k | parent.children[usize::from(u8::from(parent_to_removed_child_index))], |
1527 | 47.5k | Some(self.node_index) |
1528 | | ); |
1529 | 47.5k | parent.children[usize::from(u8::from(parent_to_removed_child_index))] = |
1530 | 47.5k | child_node_index; |
1531 | 47.5k | |
1532 | 47.5k | // If `parent` does *not* need to be removed, we can return early. |
1533 | 372k | parent.has_storage_value || parent.children.iter().filter(23.3k |c| c.is_some()).count() >= 223.3k _RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB1i_NtNtB9_9trie_node17MerkleValueOutputEEE6removes0_0Bb_ Line | Count | Source | 1533 | 2.12k | parent.has_storage_value || parent.children.iter().filter(|c| c.is_some()).count() >= 2 |
_RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessuE6removes0_0Bb_ Line | Count | Source | 1533 | 370k | parent.has_storage_value || parent.children.iter().filter(|c| c.is_some()).count() >= 2 |
Unexecuted instantiation: _RNCNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_17StorageNodeAccesspE6removes0_0Bb_ |
1534 | | } else { |
1535 | 15.4k | debug_assert_eq!(self.trie.root_index, Some(self.node_index)); |
1536 | 15.4k | self.trie.root_index = child_node_index; |
1537 | 15.4k | true |
1538 | | }; |
1539 | | |
1540 | | // If we keep the parent in the trie, return early with a `SingleRemove`. |
1541 | 62.9k | if single_remove { |
1542 | 52.2k | return if let Some(child_node_index12.3k ) = child_node_index { |
1543 | 12.3k | Remove::SingleRemoveChild { |
1544 | 12.3k | user_data: removed_node.user_data, |
1545 | 12.3k | child: self.trie.node_by_index_inner(child_node_index).unwrap(), |
1546 | 12.3k | } |
1547 | 39.9k | } else if let Some((parent_index33.4k , _)) = removed_node.parent { |
1548 | 33.4k | Remove::SingleRemoveNoChild { |
1549 | 33.4k | user_data: removed_node.user_data, |
1550 | 33.4k | parent: self.trie.node_by_index_inner(parent_index).unwrap(), |
1551 | 33.4k | } |
1552 | | } else { |
1553 | 6.41k | debug_assert!(self.trie.nodes.is_empty()); |
1554 | 6.41k | debug_assert!(self.trie.root_index.is_none()); |
1555 | 6.41k | Remove::TrieNowEmpty { |
1556 | 6.41k | user_data: removed_node.user_data, |
1557 | 6.41k | } |
1558 | | }; |
1559 | 10.7k | } |
1560 | 10.7k | |
1561 | 10.7k | // If we reach here, then parent has to be removed from the trie as well. |
1562 | 10.7k | let parent_index = removed_node.parent.unwrap().0; |
1563 | 10.7k | debug_assert!(child_node_index.is_none()); |
1564 | 10.7k | let removed_branch = self.trie.nodes.remove(parent_index); |
1565 | 10.7k | debug_assert!(!removed_branch.has_storage_value); |
1566 | | |
1567 | | // We already know from above that the removed branch has exactly 1 sibling. Let's |
1568 | | // determine which. |
1569 | 10.7k | debug_assert_eq!( |
1570 | 10.7k | removed_branch |
1571 | 10.7k | .children |
1572 | 10.7k | .iter() |
1573 | 172k | .filter(|c| c.is_some()) _RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB1i_NtNtB9_9trie_node17MerkleValueOutputEEE6removes2_0Bb_ Line | Count | Source | 1573 | 1.05k | .filter(|c| c.is_some()) |
_RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessuE6removes2_0Bb_ Line | Count | Source | 1573 | 171k | .filter(|c| c.is_some()) |
Unexecuted instantiation: _RNCNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_17StorageNodeAccesspE6removes2_0Bb_ |
1574 | 10.7k | .count(), |
1575 | | 1 |
1576 | | ); |
1577 | 91.0k | let sibling_node_index: usize = removed_branch.children.iter().find_map(10.7k |c| *c).unwrap(); _RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB1i_NtNtB9_9trie_node17MerkleValueOutputEEE6removes1_0Bb_ Line | Count | Source | 1577 | 549 | let sibling_node_index: usize = removed_branch.children.iter().find_map(|c| *c).unwrap(); |
_RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_17StorageNodeAccessuE6removes1_0Bb_ Line | Count | Source | 1577 | 90.4k | let sibling_node_index: usize = removed_branch.children.iter().find_map(|c| *c).unwrap(); |
Unexecuted instantiation: _RNCNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_17StorageNodeAccesspE6removes1_0Bb_ |
1578 | 10.7k | |
1579 | 10.7k | // Update the sibling to point to the parent's parent. |
1580 | 10.7k | { |
1581 | 10.7k | let sibling = self.trie.nodes.get_mut(sibling_node_index).unwrap(); |
1582 | 10.7k | debug_assert_eq!(sibling.parent.as_ref().unwrap().0, parent_index); |
1583 | 10.7k | insert_front( |
1584 | 10.7k | &mut sibling.partial_key, |
1585 | 10.7k | removed_branch.partial_key, |
1586 | 10.7k | sibling.parent.unwrap().1, |
1587 | 10.7k | ); |
1588 | 10.7k | sibling.parent = removed_branch.parent; |
1589 | | } |
1590 | | |
1591 | | // Update the parent's parent to point to the sibling. |
1592 | 10.7k | if let Some((parent_parent_index, parent_to_sibling_index9.90k )) = removed_branch.parent { |
1593 | | // Update the parent's parent to point to the sibling. |
1594 | 9.90k | let parent_parent = self.trie.nodes.get_mut(parent_parent_index).unwrap(); |
1595 | 9.90k | debug_assert_eq!( |
1596 | 9.90k | parent_parent.children[usize::from(u8::from(parent_to_sibling_index))], |
1597 | 9.90k | Some(parent_index) |
1598 | | ); |
1599 | 9.90k | parent_parent.children[usize::from(u8::from(parent_to_sibling_index))] = |
1600 | 9.90k | Some(sibling_node_index); |
1601 | | } else { |
1602 | 878 | debug_assert_eq!(self.trie.root_index, Some(parent_index)); |
1603 | 878 | self.trie.root_index = Some(sibling_node_index); |
1604 | | } |
1605 | | |
1606 | | // Success! |
1607 | 10.7k | Remove::BranchAlsoRemoved { |
1608 | 10.7k | sibling: self.trie.node_by_index_inner(sibling_node_index).unwrap(), |
1609 | 10.7k | storage_user_data: removed_node.user_data, |
1610 | 10.7k | branch_user_data: removed_branch.user_data, |
1611 | 10.7k | } |
1612 | 135k | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE6removeB9_ Line | Count | Source | 1482 | 85.8k | pub fn remove(self) -> Remove<'a, TUd> { | 1483 | 85.8k | // If the removed node has 2 or more children, then the node continues as a branch node. | 1484 | 85.8k | { | 1485 | 85.8k | let node = self.trie.nodes.get_mut(self.node_index).unwrap(); | 1486 | 85.8k | if node.children.iter().filter(|c| c.is_some()).count() >= 2 { | 1487 | 70.6k | node.has_storage_value = false; | 1488 | 70.6k | return Remove::StorageToBranch(BranchNodeAccess { | 1489 | 70.6k | trie: self.trie, | 1490 | 70.6k | node_index: self.node_index, | 1491 | 70.6k | }); | 1492 | 15.2k | } | 1493 | 15.2k | } | 1494 | 15.2k | | 1495 | 15.2k | let removed_node = self.trie.nodes.remove(self.node_index); | 1496 | 15.2k | debug_assert!(removed_node.has_storage_value); | 1497 | | | 1498 | | // We already know from above that the removed node has only 0 or 1 children. Let's | 1499 | | // determine which. | 1500 | 15.2k | let child_node_index: Option<usize> = removed_node.children.iter().find_map(|c| *c); | 1501 | | | 1502 | | // If relevant, update our single child's parent to point to `removed_node`'s parent. | 1503 | 15.2k | if let Some(child_node_index8.96k ) = child_node_index { | 1504 | 8.96k | let child = self.trie.nodes.get_mut(child_node_index).unwrap(); | 1505 | 8.96k | debug_assert_eq!(child.parent.as_ref().unwrap().0, self.node_index); | 1506 | 8.96k | insert_front( | 1507 | 8.96k | &mut child.partial_key, | 1508 | 8.96k | removed_node.partial_key, | 1509 | 8.96k | child.parent.unwrap().1, | 1510 | 8.96k | ); | 1511 | 8.96k | child.parent = removed_node.parent; | 1512 | 6.26k | } | 1513 | | | 1514 | | // At this point, we're almost done with removing `removed_node` from `self.trie`. However | 1515 | | // there is potentially another change to make: maybe `parent` has to be removed from the | 1516 | | // trie as well. | 1517 | | | 1518 | | // Update `parent`'s child to point to `child_node_index`. | 1519 | | // `single_remove` is true if we can keep `parent` in the trie. | 1520 | 15.2k | let single_remove = if let Some((parent_index, parent_to_removed_child_index257 )) = | 1521 | 15.2k | removed_node.parent | 1522 | | { | 1523 | | // Update `removed_node`'s parent to point to the child. | 1524 | 257 | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 1525 | 257 | debug_assert_eq!( | 1526 | 257 | parent.children[usize::from(u8::from(parent_to_removed_child_index))], | 1527 | 257 | Some(self.node_index) | 1528 | | ); | 1529 | 257 | parent.children[usize::from(u8::from(parent_to_removed_child_index))] = | 1530 | 257 | child_node_index; | 1531 | 257 | | 1532 | 257 | // If `parent` does *not* need to be removed, we can return early. | 1533 | 257 | parent.has_storage_value || parent.children.iter().filter(133 |c| c.is_some()).count() >= 2133 | 1534 | | } else { | 1535 | 14.9k | debug_assert_eq!(self.trie.root_index, Some(self.node_index)); | 1536 | 14.9k | self.trie.root_index = child_node_index; | 1537 | 14.9k | true | 1538 | | }; | 1539 | | | 1540 | | // If we keep the parent in the trie, return early with a `SingleRemove`. | 1541 | 15.2k | if single_remove { | 1542 | 15.1k | return if let Some(child_node_index8.96k ) = child_node_index { | 1543 | 8.96k | Remove::SingleRemoveChild { | 1544 | 8.96k | user_data: removed_node.user_data, | 1545 | 8.96k | child: self.trie.node_by_index_inner(child_node_index).unwrap(), | 1546 | 8.96k | } | 1547 | 6.19k | } else if let Some((parent_index185 , _)) = removed_node.parent { | 1548 | 185 | Remove::SingleRemoveNoChild { | 1549 | 185 | user_data: removed_node.user_data, | 1550 | 185 | parent: self.trie.node_by_index_inner(parent_index).unwrap(), | 1551 | 185 | } | 1552 | | } else { | 1553 | 6.01k | debug_assert!(self.trie.nodes.is_empty()); | 1554 | 6.01k | debug_assert!(self.trie.root_index.is_none()); | 1555 | 6.01k | Remove::TrieNowEmpty { | 1556 | 6.01k | user_data: removed_node.user_data, | 1557 | 6.01k | } | 1558 | | }; | 1559 | 66 | } | 1560 | 66 | | 1561 | 66 | // If we reach here, then parent has to be removed from the trie as well. | 1562 | 66 | let parent_index = removed_node.parent.unwrap().0; | 1563 | 66 | debug_assert!(child_node_index.is_none()); | 1564 | 66 | let removed_branch = self.trie.nodes.remove(parent_index); | 1565 | 66 | debug_assert!(!removed_branch.has_storage_value); | 1566 | | | 1567 | | // We already know from above that the removed branch has exactly 1 sibling. Let's | 1568 | | // determine which. | 1569 | 66 | debug_assert_eq!( | 1570 | 66 | removed_branch | 1571 | 66 | .children | 1572 | 66 | .iter() | 1573 | 66 | .filter(|c| c.is_some()) | 1574 | 66 | .count(), | 1575 | | 1 | 1576 | | ); | 1577 | 66 | let sibling_node_index: usize = removed_branch.children.iter().find_map(|c| *c).unwrap(); | 1578 | 66 | | 1579 | 66 | // Update the sibling to point to the parent's parent. | 1580 | 66 | { | 1581 | 66 | let sibling = self.trie.nodes.get_mut(sibling_node_index).unwrap(); | 1582 | 66 | debug_assert_eq!(sibling.parent.as_ref().unwrap().0, parent_index); | 1583 | 66 | insert_front( | 1584 | 66 | &mut sibling.partial_key, | 1585 | 66 | removed_branch.partial_key, | 1586 | 66 | sibling.parent.unwrap().1, | 1587 | 66 | ); | 1588 | 66 | sibling.parent = removed_branch.parent; | 1589 | | } | 1590 | | | 1591 | | // Update the parent's parent to point to the sibling. | 1592 | 66 | if let Some((parent_parent_index, parent_to_sibling_index63 )) = removed_branch.parent { | 1593 | | // Update the parent's parent to point to the sibling. | 1594 | 63 | let parent_parent = self.trie.nodes.get_mut(parent_parent_index).unwrap(); | 1595 | 63 | debug_assert_eq!( | 1596 | 63 | parent_parent.children[usize::from(u8::from(parent_to_sibling_index))], | 1597 | 63 | Some(parent_index) | 1598 | | ); | 1599 | 63 | parent_parent.children[usize::from(u8::from(parent_to_sibling_index))] = | 1600 | 63 | Some(sibling_node_index); | 1601 | | } else { | 1602 | 3 | debug_assert_eq!(self.trie.root_index, Some(parent_index)); | 1603 | 3 | self.trie.root_index = Some(sibling_node_index); | 1604 | | } | 1605 | | | 1606 | | // Success! | 1607 | 66 | Remove::BranchAlsoRemoved { | 1608 | 66 | sibling: self.trie.node_by_index_inner(sibling_node_index).unwrap(), | 1609 | 66 | storage_user_data: removed_node.user_data, | 1610 | 66 | branch_user_data: removed_branch.user_data, | 1611 | 66 | } | 1612 | 85.8k | } |
_RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_17StorageNodeAccessuE6removeB9_ Line | Count | Source | 1482 | 49.1k | pub fn remove(self) -> Remove<'a, TUd> { | 1483 | 49.1k | // If the removed node has 2 or more children, then the node continues as a branch node. | 1484 | 49.1k | { | 1485 | 49.1k | let node = self.trie.nodes.get_mut(self.node_index).unwrap(); | 1486 | 49.1k | if node.children.iter().filter(|c| c.is_some()).count() >= 2 { | 1487 | 1.43k | node.has_storage_value = false; | 1488 | 1.43k | return Remove::StorageToBranch(BranchNodeAccess { | 1489 | 1.43k | trie: self.trie, | 1490 | 1.43k | node_index: self.node_index, | 1491 | 1.43k | }); | 1492 | 47.7k | } | 1493 | 47.7k | } | 1494 | 47.7k | | 1495 | 47.7k | let removed_node = self.trie.nodes.remove(self.node_index); | 1496 | 47.7k | debug_assert!(removed_node.has_storage_value); | 1497 | | | 1498 | | // We already know from above that the removed node has only 0 or 1 children. Let's | 1499 | | // determine which. | 1500 | 47.7k | let child_node_index: Option<usize> = removed_node.children.iter().find_map(|c| *c); | 1501 | | | 1502 | | // If relevant, update our single child's parent to point to `removed_node`'s parent. | 1503 | 47.7k | if let Some(child_node_index3.33k ) = child_node_index { | 1504 | 3.33k | let child = self.trie.nodes.get_mut(child_node_index).unwrap(); | 1505 | 3.33k | debug_assert_eq!(child.parent.as_ref().unwrap().0, self.node_index); | 1506 | 3.33k | insert_front( | 1507 | 3.33k | &mut child.partial_key, | 1508 | 3.33k | removed_node.partial_key, | 1509 | 3.33k | child.parent.unwrap().1, | 1510 | 3.33k | ); | 1511 | 3.33k | child.parent = removed_node.parent; | 1512 | 44.4k | } | 1513 | | | 1514 | | // At this point, we're almost done with removing `removed_node` from `self.trie`. However | 1515 | | // there is potentially another change to make: maybe `parent` has to be removed from the | 1516 | | // trie as well. | 1517 | | | 1518 | | // Update `parent`'s child to point to `child_node_index`. | 1519 | | // `single_remove` is true if we can keep `parent` in the trie. | 1520 | 47.7k | let single_remove = if let Some((parent_index, parent_to_removed_child_index47.3k )) = | 1521 | 47.7k | removed_node.parent | 1522 | | { | 1523 | | // Update `removed_node`'s parent to point to the child. | 1524 | 47.3k | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 1525 | 47.3k | debug_assert_eq!( | 1526 | 47.3k | parent.children[usize::from(u8::from(parent_to_removed_child_index))], | 1527 | 47.3k | Some(self.node_index) | 1528 | | ); | 1529 | 47.3k | parent.children[usize::from(u8::from(parent_to_removed_child_index))] = | 1530 | 47.3k | child_node_index; | 1531 | 47.3k | | 1532 | 47.3k | // If `parent` does *not* need to be removed, we can return early. | 1533 | 47.3k | parent.has_storage_value || parent.children.iter().filter(23.1k |c| c.is_some()).count() >= 223.1k | 1534 | | } else { | 1535 | 452 | debug_assert_eq!(self.trie.root_index, Some(self.node_index)); | 1536 | 452 | self.trie.root_index = child_node_index; | 1537 | 452 | true | 1538 | | }; | 1539 | | | 1540 | | // If we keep the parent in the trie, return early with a `SingleRemove`. | 1541 | 47.7k | if single_remove { | 1542 | 37.0k | return if let Some(child_node_index3.33k ) = child_node_index { | 1543 | 3.33k | Remove::SingleRemoveChild { | 1544 | 3.33k | user_data: removed_node.user_data, | 1545 | 3.33k | child: self.trie.node_by_index_inner(child_node_index).unwrap(), | 1546 | 3.33k | } | 1547 | 33.7k | } else if let Some((parent_index33.3k , _)) = removed_node.parent { | 1548 | 33.3k | Remove::SingleRemoveNoChild { | 1549 | 33.3k | user_data: removed_node.user_data, | 1550 | 33.3k | parent: self.trie.node_by_index_inner(parent_index).unwrap(), | 1551 | 33.3k | } | 1552 | | } else { | 1553 | 407 | debug_assert!(self.trie.nodes.is_empty()); | 1554 | 407 | debug_assert!(self.trie.root_index.is_none()); | 1555 | 407 | Remove::TrieNowEmpty { | 1556 | 407 | user_data: removed_node.user_data, | 1557 | 407 | } | 1558 | | }; | 1559 | 10.7k | } | 1560 | 10.7k | | 1561 | 10.7k | // If we reach here, then parent has to be removed from the trie as well. | 1562 | 10.7k | let parent_index = removed_node.parent.unwrap().0; | 1563 | 10.7k | debug_assert!(child_node_index.is_none()); | 1564 | 10.7k | let removed_branch = self.trie.nodes.remove(parent_index); | 1565 | 10.7k | debug_assert!(!removed_branch.has_storage_value); | 1566 | | | 1567 | | // We already know from above that the removed branch has exactly 1 sibling. Let's | 1568 | | // determine which. | 1569 | 10.7k | debug_assert_eq!( | 1570 | 10.7k | removed_branch | 1571 | 10.7k | .children | 1572 | 10.7k | .iter() | 1573 | 10.7k | .filter(|c| c.is_some()) | 1574 | 10.7k | .count(), | 1575 | | 1 | 1576 | | ); | 1577 | 10.7k | let sibling_node_index: usize = removed_branch.children.iter().find_map(|c| *c).unwrap(); | 1578 | 10.7k | | 1579 | 10.7k | // Update the sibling to point to the parent's parent. | 1580 | 10.7k | { | 1581 | 10.7k | let sibling = self.trie.nodes.get_mut(sibling_node_index).unwrap(); | 1582 | 10.7k | debug_assert_eq!(sibling.parent.as_ref().unwrap().0, parent_index); | 1583 | 10.7k | insert_front( | 1584 | 10.7k | &mut sibling.partial_key, | 1585 | 10.7k | removed_branch.partial_key, | 1586 | 10.7k | sibling.parent.unwrap().1, | 1587 | 10.7k | ); | 1588 | 10.7k | sibling.parent = removed_branch.parent; | 1589 | | } | 1590 | | | 1591 | | // Update the parent's parent to point to the sibling. | 1592 | 10.7k | if let Some((parent_parent_index, parent_to_sibling_index9.83k )) = removed_branch.parent { | 1593 | | // Update the parent's parent to point to the sibling. | 1594 | 9.83k | let parent_parent = self.trie.nodes.get_mut(parent_parent_index).unwrap(); | 1595 | 9.83k | debug_assert_eq!( | 1596 | 9.83k | parent_parent.children[usize::from(u8::from(parent_to_sibling_index))], | 1597 | 9.83k | Some(parent_index) | 1598 | | ); | 1599 | 9.83k | parent_parent.children[usize::from(u8::from(parent_to_sibling_index))] = | 1600 | 9.83k | Some(sibling_node_index); | 1601 | | } else { | 1602 | 875 | debug_assert_eq!(self.trie.root_index, Some(parent_index)); | 1603 | 875 | self.trie.root_index = Some(sibling_node_index); | 1604 | | } | 1605 | | | 1606 | | // Success! | 1607 | 10.7k | Remove::BranchAlsoRemoved { | 1608 | 10.7k | sibling: self.trie.node_by_index_inner(sibling_node_index).unwrap(), | 1609 | 10.7k | storage_user_data: removed_node.user_data, | 1610 | 10.7k | branch_user_data: removed_branch.user_data, | 1611 | 10.7k | } | 1612 | 49.1k | } |
Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_17StorageNodeAccesspE6removeB9_ |
1613 | | } |
1614 | | |
1615 | | /// Outcome of the removal of a storage value. |
1616 | | pub enum Remove<'a, TUd> { |
1617 | | /// Removing the storage value didn't change the structure of the trie. Contains a |
1618 | | /// [`BranchNodeAccess`] representing the same node as the [`StorageNodeAccess`] whose value |
1619 | | /// got removed. |
1620 | | StorageToBranch(BranchNodeAccess<'a, TUd>), |
1621 | | |
1622 | | /// Removing the storage value removed the node that contained the storage value. Apart from |
1623 | | /// this removal, the structure of the trie didn't change. |
1624 | | /// |
1625 | | /// The node that got removed had one single child. This child's parent becomes the parent |
1626 | | /// that the former node had. |
1627 | | /// |
1628 | | /// ```text |
1629 | | /// |
1630 | | /// |
1631 | | /// +-+ +-+ |
1632 | | /// +--> +-+ <--+ +--------> +-+ <--+ |
1633 | | /// | | | | |
1634 | | /// | + | + |
1635 | | /// | (0 or more other children) | (0 or more other children) |
1636 | | /// | | |
1637 | | /// +-+ | |
1638 | | /// +--> +-+ removed node | |
1639 | | /// | | |
1640 | | /// | | |
1641 | | /// | | |
1642 | | /// | | |
1643 | | /// +-+ +-+ |
1644 | | /// +-+ +-+ `child` |
1645 | | /// ^ ^ |
1646 | | /// ++ (0 or more other children) ++ (0 or more other children) |
1647 | | /// |
1648 | | /// ``` |
1649 | | /// |
1650 | | SingleRemoveChild { |
1651 | | /// Unique child that the removed node had. The parent and partial key of this child has |
1652 | | /// been modified. |
1653 | | child: NodeAccess<'a, TUd>, |
1654 | | |
1655 | | /// User data that was in the removed node. |
1656 | | user_data: TUd, |
1657 | | }, |
1658 | | |
1659 | | /// Removing the storage value removed the node that contained the storage value. Apart from |
1660 | | /// this removal, the structure of the trie didn't change. |
1661 | | /// |
1662 | | /// The node that got removed didn't have any children. |
1663 | | /// |
1664 | | /// ```text |
1665 | | /// |
1666 | | /// Before After |
1667 | | /// |
1668 | | /// `parent` |
1669 | | /// +-+ +-+ |
1670 | | /// +--> +-+ <--+ +-+ <--+ |
1671 | | /// | | | |
1672 | | /// | + + |
1673 | | /// | (0 or more other children) (0 or more other children) |
1674 | | /// | |
1675 | | /// +-+ |
1676 | | /// +-+ removed node |
1677 | | /// |
1678 | | /// ``` |
1679 | | /// |
1680 | | SingleRemoveNoChild { |
1681 | | /// Parent that the removed node had. |
1682 | | parent: NodeAccess<'a, TUd>, |
1683 | | |
1684 | | /// User data that was in the removed node. |
1685 | | user_data: TUd, |
1686 | | }, |
1687 | | |
1688 | | /// The trie was empty apart from this node. It is now completely empty. |
1689 | | TrieNowEmpty { |
1690 | | /// User data that was in the removed node. |
1691 | | user_data: TUd, |
1692 | | }, |
1693 | | |
1694 | | /// Removing the storage value removed two nodes from the trie: the one that contained the |
1695 | | /// storage value and its parent, which was a branch node. |
1696 | | /// |
1697 | | /// This can only happen if the removed node had no children and only one sibling. |
1698 | | /// |
1699 | | /// ```text |
1700 | | /// |
1701 | | /// Before After |
1702 | | /// |
1703 | | /// |
1704 | | /// + + |
1705 | | /// | | |
1706 | | /// +-+ | |
1707 | | /// +--> +-+ <--+ +-----+ |
1708 | | /// | | | |
1709 | | /// | | | |
1710 | | /// +-+ +-+ +-+ |
1711 | | /// +-+ +-+ +-+ `sibling` |
1712 | | /// ^ ^ |
1713 | | /// removed node | | |
1714 | | /// + + |
1715 | | /// (0 or more other nodes) (0 or more other nodes) |
1716 | | /// |
1717 | | /// ``` |
1718 | | /// |
1719 | | BranchAlsoRemoved { |
1720 | | /// Sibling of the removed node. The parent and partial key of this sibling have been |
1721 | | /// modified. |
1722 | | sibling: NodeAccess<'a, TUd>, |
1723 | | |
1724 | | /// User data that was in the removed storage node. |
1725 | | storage_user_data: TUd, |
1726 | | |
1727 | | /// User data that was in the removed branch node (former parent of `storage_user_data`). |
1728 | | branch_user_data: TUd, |
1729 | | }, |
1730 | | } |
1731 | | |
1732 | | /// Access to a node within the [`TrieStructure`] that is known to not have any storage value |
1733 | | /// associated to it. |
1734 | | pub struct BranchNodeAccess<'a, TUd> { |
1735 | | trie: &'a mut TrieStructure<TUd>, |
1736 | | node_index: usize, |
1737 | | } |
1738 | | |
1739 | | impl<'a, TUd> BranchNodeAccess<'a, TUd> { |
1740 | | /// Returns an opaque [`NodeIndex`] representing the node in the trie. |
1741 | | /// |
1742 | | /// It can later be used to retrieve this same node using [`TrieStructure::node_by_index`]. |
1743 | 0 | pub fn node_index(&self) -> NodeIndex { |
1744 | 0 | NodeIndex(self.node_index) |
1745 | 0 | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE10node_indexB9_ Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE10node_indexB9_ |
1746 | | |
1747 | | /// Returns the parent of this node, or `None` if this is the root node. |
1748 | 0 | pub fn into_parent(self) -> Option<NodeAccess<'a, TUd>> { |
1749 | 0 | let parent_idx = self.trie.nodes.get(self.node_index).unwrap().parent?.0; |
1750 | 0 | Some(self.trie.node_by_index_inner(parent_idx).unwrap()) |
1751 | 0 | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE11into_parentB9_ Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE11into_parentB9_ |
1752 | | |
1753 | | /// Returns the parent of this node, or `None` if this is the root node. |
1754 | 0 | pub fn parent(&mut self) -> Option<NodeAccess<TUd>> { |
1755 | 0 | let parent_idx = self.trie.nodes.get(self.node_index).unwrap().parent?.0; |
1756 | 0 | Some(self.trie.node_by_index_inner(parent_idx).unwrap()) |
1757 | 0 | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE6parentB9_ Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE6parentB9_ |
1758 | | |
1759 | | /// Returns the first child of this node. |
1760 | | /// |
1761 | | /// Returns back `self` if this node doesn't have any children. |
1762 | 0 | pub fn into_first_child(self) -> Result<NodeAccess<'a, TUd>, Self> { |
1763 | 0 | let first_child_idx = self |
1764 | 0 | .trie |
1765 | 0 | .nodes |
1766 | 0 | .get(self.node_index) |
1767 | 0 | .unwrap() |
1768 | 0 | .children |
1769 | 0 | .iter() |
1770 | 0 | .find_map(|c| *c); Unexecuted instantiation: _RNCNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB9_12proof_encode4NodeEE16into_first_child0Bb_ Unexecuted instantiation: _RNCNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB9_12proof_encode4NodeEE16into_first_child0Bb_ |
1771 | | |
1772 | 0 | let first_child_idx = match first_child_idx { |
1773 | 0 | Some(fc) => fc, |
1774 | 0 | None => return Err(self), |
1775 | | }; |
1776 | | |
1777 | 0 | Ok(self.trie.node_by_index_inner(first_child_idx).unwrap()) |
1778 | 0 | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE16into_first_childB9_ Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE16into_first_childB9_ |
1779 | | |
1780 | | /// Returns the next sibling of this node. |
1781 | | /// |
1782 | | /// Returns back `self` if this node is the last child of its parent. |
1783 | 0 | pub fn into_next_sibling(self) -> Result<NodeAccess<'a, TUd>, Self> { |
1784 | 0 | let next_sibling_idx = match self.trie.next_sibling(self.node_index) { |
1785 | 0 | Some(ns) => ns, |
1786 | 0 | None => return Err(self), |
1787 | | }; |
1788 | | |
1789 | 0 | Ok(self.trie.node_by_index_inner(next_sibling_idx).unwrap()) |
1790 | 0 | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE17into_next_siblingB9_ Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE17into_next_siblingB9_ |
1791 | | |
1792 | | /// Returns the child of this node at the given index. |
1793 | 1.12M | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { |
1794 | 205k | let child_idx = |
1795 | 1.12M | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?922k ; |
1796 | 205k | Some(self.trie.node_by_index_inner(child_idx).unwrap()) |
1797 | 1.12M | } _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE5childB9_ Line | Count | Source | 1793 | 2.17k | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1794 | 272 | let child_idx = | 1795 | 2.17k | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?1.90k ; | 1796 | 272 | Some(self.trie.node_by_index_inner(child_idx).unwrap()) | 1797 | 2.17k | } |
_RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE5childB9_ Line | Count | Source | 1793 | 1.11M | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1794 | 202k | let child_idx = | 1795 | 1.11M | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?913k ; | 1796 | 202k | Some(self.trie.node_by_index_inner(child_idx).unwrap()) | 1797 | 1.11M | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE5childB9_ _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE5childCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1793 | 832 | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1794 | 188 | let child_idx = | 1795 | 832 | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?644 ; | 1796 | 188 | Some(self.trie.node_by_index_inner(child_idx).unwrap()) | 1797 | 832 | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE5childCscDgN54JpMGG_6author _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE5childCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1793 | 7.90k | pub fn child(&mut self, index: Nibble) -> Option<NodeAccess<TUd>> { | 1794 | 1.78k | let child_idx = | 1795 | 7.90k | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?6.11k ; | 1796 | 1.78k | Some(self.trie.node_by_index_inner(child_idx).unwrap()) | 1797 | 7.90k | } |
|
1798 | | |
1799 | | /// Returns the user data of the child at the given index. |
1800 | | /// |
1801 | | /// > **Note**: This method exists because it accepts `&self` rather than `&mut self`. A |
1802 | | /// > cleaner alternative would be to split the [`NodeAccess`] struct into |
1803 | | /// > `NodeAccessRef` and `NodeAccessMut`, but that's a lot of efforts compare to |
1804 | | /// > this single method. |
1805 | 89.4k | pub fn child_user_data(&self, index: Nibble) -> Option<&TUd> { |
1806 | 15.5k | let child_idx = |
1807 | 89.4k | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?73.8k ; |
1808 | 15.5k | Some(&self.trie.nodes.get(child_idx).unwrap().user_data) |
1809 | 89.4k | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE15child_user_dataB9_ _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessuE15child_user_dataB9_ Line | Count | Source | 1805 | 89.4k | pub fn child_user_data(&self, index: Nibble) -> Option<&TUd> { | 1806 | 15.5k | let child_idx = | 1807 | 89.4k | self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?73.8k ; | 1808 | 15.5k | Some(&self.trie.nodes.get(child_idx).unwrap().user_data) | 1809 | 89.4k | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE15child_user_dataB9_ |
1810 | | |
1811 | | /// Returns the child of this node given the given index. |
1812 | | /// |
1813 | | /// Returns back `self` if there is no such child at this index. |
1814 | 0 | pub fn into_child(self, index: Nibble) -> Result<NodeAccess<'a, TUd>, Self> { |
1815 | 0 | let child_idx = match self.trie.nodes.get(self.node_index).unwrap().children |
1816 | 0 | [usize::from(u8::from(index))] |
1817 | | { |
1818 | 0 | Some(c) => c, |
1819 | 0 | None => return Err(self), |
1820 | | }; |
1821 | | |
1822 | 0 | Ok(self.trie.node_by_index_inner(child_idx).unwrap()) |
1823 | 0 | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE10into_childB9_ Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE10into_childB9_ |
1824 | | |
1825 | | /// Returns true if this node is the root node of the trie. |
1826 | 70.1k | pub fn is_root_node(&self) -> bool { |
1827 | 70.1k | self.trie.root_index == Some(self.node_index) |
1828 | 70.1k | } _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeB9_ Line | Count | Source | 1826 | 68 | pub fn is_root_node(&self) -> bool { | 1827 | 68 | self.trie.root_index == Some(self.node_index) | 1828 | 68 | } |
_RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeB9_ Line | Count | Source | 1826 | 69.7k | pub fn is_root_node(&self) -> bool { | 1827 | 69.7k | self.trie.root_index == Some(self.node_index) | 1828 | 69.7k | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE12is_root_nodeB9_ _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1826 | 26 | pub fn is_root_node(&self) -> bool { | 1827 | 26 | self.trie.root_index == Some(self.node_index) | 1828 | 26 | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeCscDgN54JpMGG_6author _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE12is_root_nodeCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1826 | 247 | pub fn is_root_node(&self) -> bool { | 1827 | 247 | self.trie.root_index == Some(self.node_index) | 1828 | 247 | } |
|
1829 | | |
1830 | | /// Returns the full key of the node. |
1831 | 0 | pub fn full_key(&'_ self) -> impl Iterator<Item = Nibble> + '_ { |
1832 | 0 | self.trie.node_full_key(self.node_index) |
1833 | 0 | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE8full_keyB9_ Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE8full_keyB9_ |
1834 | | |
1835 | | /// Returns the partial key of the node. |
1836 | 76.0k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { |
1837 | 76.0k | self.trie |
1838 | 76.0k | .nodes |
1839 | 76.0k | .get(self.node_index) |
1840 | 76.0k | .unwrap() |
1841 | 76.0k | .partial_key |
1842 | 76.0k | .iter() |
1843 | 76.0k | .copied() |
1844 | 76.0k | } _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyB9_ Line | Count | Source | 1836 | 136 | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1837 | 136 | self.trie | 1838 | 136 | .nodes | 1839 | 136 | .get(self.node_index) | 1840 | 136 | .unwrap() | 1841 | 136 | .partial_key | 1842 | 136 | .iter() | 1843 | 136 | .copied() | 1844 | 136 | } |
_RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyB9_ Line | Count | Source | 1836 | 69.7k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1837 | 69.7k | self.trie | 1838 | 69.7k | .nodes | 1839 | 69.7k | .get(self.node_index) | 1840 | 69.7k | .unwrap() | 1841 | 69.7k | .partial_key | 1842 | 69.7k | .iter() | 1843 | 69.7k | .copied() | 1844 | 69.7k | } |
_RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessuE11partial_keyB9_ Line | Count | Source | 1836 | 5.58k | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1837 | 5.58k | self.trie | 1838 | 5.58k | .nodes | 1839 | 5.58k | .get(self.node_index) | 1840 | 5.58k | .unwrap() | 1841 | 5.58k | .partial_key | 1842 | 5.58k | .iter() | 1843 | 5.58k | .copied() | 1844 | 5.58k | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE11partial_keyB9_ _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1836 | 52 | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1837 | 52 | self.trie | 1838 | 52 | .nodes | 1839 | 52 | .get(self.node_index) | 1840 | 52 | .unwrap() | 1841 | 52 | .partial_key | 1842 | 52 | .iter() | 1843 | 52 | .copied() | 1844 | 52 | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyCscDgN54JpMGG_6author _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE11partial_keyCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1836 | 494 | pub fn partial_key(&'_ self) -> impl ExactSizeIterator<Item = Nibble> + Clone + '_ { | 1837 | 494 | self.trie | 1838 | 494 | .nodes | 1839 | 494 | .get(self.node_index) | 1840 | 494 | .unwrap() | 1841 | 494 | .partial_key | 1842 | 494 | .iter() | 1843 | 494 | .copied() | 1844 | 494 | } |
|
1845 | | |
1846 | | /// Adds a storage value to this node, turning it into a [`StorageNodeAccess`]. |
1847 | | /// |
1848 | | /// The trie structure doesn't change. |
1849 | 166k | pub fn insert_storage_value(self) -> StorageNodeAccess<'a, TUd> { |
1850 | 166k | let node = self.trie.nodes.get_mut(self.node_index).unwrap(); |
1851 | 166k | debug_assert!(!node.has_storage_value); |
1852 | 166k | node.has_storage_value = true; |
1853 | 166k | |
1854 | 166k | StorageNodeAccess { |
1855 | 166k | trie: self.trie, |
1856 | 166k | node_index: self.node_index, |
1857 | 166k | } |
1858 | 166k | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE20insert_storage_valueB9_ _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE20insert_storage_valueB9_ Line | Count | Source | 1849 | 66.5k | pub fn insert_storage_value(self) -> StorageNodeAccess<'a, TUd> { | 1850 | 66.5k | let node = self.trie.nodes.get_mut(self.node_index).unwrap(); | 1851 | 66.5k | debug_assert!(!node.has_storage_value); | 1852 | 66.5k | node.has_storage_value = true; | 1853 | 66.5k | | 1854 | 66.5k | StorageNodeAccess { | 1855 | 66.5k | trie: self.trie, | 1856 | 66.5k | node_index: self.node_index, | 1857 | 66.5k | } | 1858 | 66.5k | } |
_RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessuE20insert_storage_valueB9_ Line | Count | Source | 1849 | 99.9k | pub fn insert_storage_value(self) -> StorageNodeAccess<'a, TUd> { | 1850 | 99.9k | let node = self.trie.nodes.get_mut(self.node_index).unwrap(); | 1851 | 99.9k | debug_assert!(!node.has_storage_value); | 1852 | 99.9k | node.has_storage_value = true; | 1853 | 99.9k | | 1854 | 99.9k | StorageNodeAccess { | 1855 | 99.9k | trie: self.trie, | 1856 | 99.9k | node_index: self.node_index, | 1857 | 99.9k | } | 1858 | 99.9k | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE20insert_storage_valueB9_ Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE20insert_storage_valueCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE20insert_storage_valueCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE20insert_storage_valueCsibGXYHQB8Ea_25json_rpc_general_requests |
1859 | | |
1860 | | /// Returns the user data associated to this node. |
1861 | 70.8k | pub fn into_user_data(self) -> &'a mut TUd { |
1862 | 70.8k | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data |
1863 | 70.8k | } _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataB9_ Line | Count | Source | 1861 | 68 | pub fn into_user_data(self) -> &'a mut TUd { | 1862 | 68 | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1863 | 68 | } |
_RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataB9_ Line | Count | Source | 1861 | 70.4k | pub fn into_user_data(self) -> &'a mut TUd { | 1862 | 70.4k | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1863 | 70.4k | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccesspE14into_user_dataB9_ _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1861 | 26 | pub fn into_user_data(self) -> &'a mut TUd { | 1862 | 26 | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1863 | 26 | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataCscDgN54JpMGG_6author _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE14into_user_dataCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1861 | 247 | pub fn into_user_data(self) -> &'a mut TUd { | 1862 | 247 | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1863 | 247 | } |
|
1864 | | |
1865 | | /// Returns the user data associated to this node. |
1866 | 266k | pub fn user_data(&mut self) -> &mut TUd { |
1867 | 266k | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data |
1868 | 266k | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE9user_dataB9_ _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataB9_ Line | Count | Source | 1866 | 204 | pub fn user_data(&mut self) -> &mut TUd { | 1867 | 204 | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1868 | 204 | } |
_RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataB9_ Line | Count | Source | 1866 | 265k | pub fn user_data(&mut self) -> &mut TUd { | 1867 | 265k | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1868 | 265k | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE9user_dataB9_ _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1866 | 100 | pub fn user_data(&mut self) -> &mut TUd { | 1867 | 100 | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1868 | 100 | } |
Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataCscDgN54JpMGG_6author _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16BranchNodeAccessTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE9user_dataCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1866 | 950 | pub fn user_data(&mut self) -> &mut TUd { | 1867 | 950 | &mut self.trie.nodes.get_mut(self.node_index).unwrap().user_data | 1868 | 950 | } |
|
1869 | | } |
1870 | | |
1871 | | /// Access to a non-existing node within the [`TrieStructure`]. |
1872 | | pub struct Vacant<'a, TUd, TKIter> { |
1873 | | trie: &'a mut TrieStructure<TUd>, |
1874 | | /// Full key of the node to insert. |
1875 | | key: TKIter, |
1876 | | /// Known closest ancestor that is in `trie`. Will become the parent of any newly-inserted |
1877 | | /// node. |
1878 | | closest_ancestor: Option<usize>, |
1879 | | } |
1880 | | |
1881 | | impl<'a, TUd, TKIter> Vacant<'a, TUd, TKIter> |
1882 | | where |
1883 | | TKIter: Iterator<Item = Nibble> + Clone, |
1884 | | { |
1885 | | /// Prepare the operation of creating the node in question. |
1886 | | /// |
1887 | | /// This method analyzes the trie to prepare for the operation, but doesn't actually perform |
1888 | | /// any insertion. To perform the insertion, use the returned [`PrepareInsert`]. |
1889 | 1.36M | pub fn insert_storage_value(mut self) -> PrepareInsert<'a, TUd> { |
1890 | | // Retrieve what will be the parent after we insert the new node, not taking branching |
1891 | | // into account yet. |
1892 | | // If `Some`, contains its index and number of nibbles in its key. |
1893 | 1.36M | let future_parent1.31M = match (self.closest_ancestor, self.trie.root_index) { |
1894 | 0 | (Some(_), None) => unreachable!(), |
1895 | 1.28M | (Some(ancestor), Some(_)) => { |
1896 | 1.28M | // TODO: could be optimized by passing in the Vacant the key remainder |
1897 | 1.28M | let key_len = self.trie.node_full_key(ancestor).count(); |
1898 | 1.28M | debug_assert!(self.key.clone().count() > key_len); |
1899 | 1.28M | Some((ancestor, key_len)) |
1900 | | } |
1901 | 24.2k | (None, Some(_)) => None, |
1902 | | (None, None) => { |
1903 | | // Situation where the trie is empty. This is kind of a special case that we |
1904 | | // handle by returning early. |
1905 | 53.6k | return PrepareInsert::One(PrepareInsertOne { |
1906 | 53.6k | trie: self.trie, |
1907 | 53.6k | parent: None, |
1908 | 53.6k | partial_key: self.key.collect(), |
1909 | 53.6k | children: [None; 16], |
1910 | 53.6k | }); |
1911 | | } |
1912 | | }; |
1913 | | |
1914 | | // Get the existing child of `future_parent` that points towards the newly-inserted node, |
1915 | | // or a successful early-return if none. |
1916 | 344k | let existing_node_index = |
1917 | 1.31M | if let Some((future_parent_index, future_parent_key_len1.28M )) = future_parent { |
1918 | 1.28M | let new_child_index = self.key.clone().nth(future_parent_key_len).unwrap(); |
1919 | 1.28M | let future_parent = self.trie.nodes.get(future_parent_index).unwrap(); |
1920 | 1.28M | match future_parent.children[usize::from(u8::from(new_child_index))] { |
1921 | 320k | Some(i) => { |
1922 | 320k | debug_assert_eq!( |
1923 | 320k | self.trie.nodes.get(i).unwrap().parent.unwrap().0, |
1924 | | future_parent_index |
1925 | | ); |
1926 | 320k | i |
1927 | | } |
1928 | | None => { |
1929 | | // There is an empty slot in `future_parent` for our new node. |
1930 | | // |
1931 | | // |
1932 | | // `future_parent` |
1933 | | // +-+ |
1934 | | // +-> +-+ <---------+ |
1935 | | // | <----+ | |
1936 | | // | ^ | | |
1937 | | // +-+ | | | |
1938 | | // New node +-+ +-+-+ +-+ +-+ 0 or more existing children |
1939 | | // +-+ +-+ +-+ |
1940 | | // |
1941 | | // |
1942 | 966k | return PrepareInsert::One(PrepareInsertOne { |
1943 | 966k | trie: self.trie, |
1944 | 966k | parent: Some((future_parent_index, new_child_index)), |
1945 | 966k | partial_key: self.key.skip(future_parent_key_len + 1).collect(), |
1946 | 966k | children: [None; 16], |
1947 | 966k | }); |
1948 | | } |
1949 | | } |
1950 | | } else { |
1951 | 24.2k | self.trie.root_index.unwrap() |
1952 | | }; |
1953 | | |
1954 | | // `existing_node_idx` and the new node are known to either have the same parent and the |
1955 | | // same child index, or to both have no parent. Now let's compare their partial key. |
1956 | 344k | let existing_node_partial_key = &self |
1957 | 344k | .trie |
1958 | 344k | .nodes |
1959 | 344k | .get(existing_node_index) |
1960 | 344k | .unwrap() |
1961 | 344k | .partial_key; |
1962 | 344k | let new_node_partial_key = self |
1963 | 344k | .key |
1964 | 344k | .clone() |
1965 | 344k | .skip(future_parent.map_or(0, |(_, n)| n + 1320k )) _RNCNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_6VacantINtNtCsaYZPK01V26L_4core6option6OptionNtNtB9_12proof_encode4NodeEINtNtNtNtB19_4iter8adapters6copied6CopiedINtNtNtB19_5slice4iter4IterNtNtB9_6nibble6NibbleEEE20insert_storage_value0Bb_ Line | Count | Source | 1965 | 5.14k | .skip(future_parent.map_or(0, |(_, n)| n + 1)) |
_RNCNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_6VacantTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB16_NtNtB9_9trie_node17MerkleValueOutputEEINtNtB9_6nibble14BytesToNibblesINtNtNtNtB1a_4iter8adapters6copied6CopiedINtNtNtB1a_5slice4iter4IterhEEEE20insert_storage_value0Bb_ Line | Count | Source | 1965 | 69 | .skip(future_parent.map_or(0, |(_, n)| n + 1)) |
_RNCNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_6VacantTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB16_NtNtB9_9trie_node17MerkleValueOutputEEINtNtB9_6nibble14BytesToNibblesINtNtNtNtB1a_4iter8adapters6copied6CopiedINtNtNtB1a_5slice4iter4IterhEEEE20insert_storage_value0Bb_ Line | Count | Source | 1965 | 57.4k | .skip(future_parent.map_or(0, |(_, n)| n + 1)) |
_RNCNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_6VacantuINtNtB9_6nibble14BytesToNibblesINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1J_5slice4iter4IterhEEEE20insert_storage_value0Bb_ Line | Count | Source | 1965 | 147 | .skip(future_parent.map_or(0, |(_, n)| n + 1)) |
_RNCNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_6VacantuINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB9_6nibble6NibbleEE20insert_storage_value0Bb_ Line | Count | Source | 1965 | 244k | .skip(future_parent.map_or(0, |(_, n)| n + 1)) |
_RNCNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_6VacantuINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1e_5slice4iter4IterNtNtB9_6nibble6NibbleEEE20insert_storage_value0Bb_ Line | Count | Source | 1965 | 4 | .skip(future_parent.map_or(0, |(_, n)| n + 1)) |
_RNCNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_6VacantuINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1e_5slice4iter4IterNtNtB9_6nibble6NibbleEEE20insert_storage_value0Bb_ Line | Count | Source | 1965 | 12.9k | .skip(future_parent.map_or(0, |(_, n)| n + 1)) |
Unexecuted instantiation: _RNCNvMs7_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_6VacantINtNtCsaYZPK01V26L_4core6option6OptionNtNtB9_12proof_encode4NodeEINtNtNtNtB1a_4iter8adapters6copied6CopiedINtNtNtB1a_5slice4iter4IterNtNtB9_6nibble6NibbleEEE20insert_storage_value0Bb_ _RNCNvMs7_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_6VacantTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB17_NtNtB9_9trie_node17MerkleValueOutputEEINtNtB9_6nibble14BytesToNibblesINtNtNtNtB1b_4iter8adapters6copied6CopiedINtNtNtB1b_5slice4iter4IterhEEEE20insert_storage_value0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1965 | 24 | .skip(future_parent.map_or(0, |(_, n)| n + 1)) |
Unexecuted instantiation: _RNCNvMs7_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_6VacantTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB17_NtNtB9_9trie_node17MerkleValueOutputEEINtNtB9_6nibble14BytesToNibblesINtNtNtNtB1b_4iter8adapters6copied6CopiedINtNtNtB1b_5slice4iter4IterhEEEE20insert_storage_value0CscDgN54JpMGG_6author _RNCNvMs7_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_6VacantTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB17_NtNtB9_9trie_node17MerkleValueOutputEEINtNtB9_6nibble14BytesToNibblesINtNtNtNtB1b_4iter8adapters6copied6CopiedINtNtNtB1b_5slice4iter4IterhEEEE20insert_storage_value0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1965 | 228 | .skip(future_parent.map_or(0, |(_, n)| n + 1)) |
|
1966 | 344k | .collect::<Vec<_>>(); |
1967 | 344k | debug_assert_ne!(*existing_node_partial_key, new_node_partial_key); |
1968 | 344k | debug_assert!(!new_node_partial_key.starts_with(existing_node_partial_key)); |
1969 | | |
1970 | | // If `existing_node_partial_key` starts with `new_node_partial_key`, then the new node |
1971 | | // will be inserted in-between the parent and the existing node. |
1972 | 344k | if existing_node_partial_key.starts_with(&new_node_partial_key) { |
1973 | | // The new node is to be inserted in-between `future_parent` and |
1974 | | // `existing_node_index`. |
1975 | | // |
1976 | | // If `future_parent` is `Some`: |
1977 | | // |
1978 | | // |
1979 | | // +-+ |
1980 | | // `future_parent` +-+ <---------+ |
1981 | | // ^ | |
1982 | | // | + |
1983 | | // +-+ (0 or more existing children) |
1984 | | // New node +-+ |
1985 | | // ^ |
1986 | | // | |
1987 | | // +-+ |
1988 | | // `existing_node_index` +-+ |
1989 | | // ^ |
1990 | | // | |
1991 | | // + |
1992 | | // (0 or more existing children) |
1993 | | // |
1994 | | // |
1995 | | // |
1996 | | // If `future_parent` is `None`: |
1997 | | // |
1998 | | // |
1999 | | // New node +-+ |
2000 | | // (becomes the root) +-+ |
2001 | | // ^ |
2002 | | // | |
2003 | | // `existing_node_index` +-+ |
2004 | | // (current root) +-+ |
2005 | | // ^ |
2006 | | // | |
2007 | | // + |
2008 | | // (0 or more existing children) |
2009 | | // |
2010 | | |
2011 | 101k | let mut new_node_children = [None; 16]; |
2012 | 101k | let existing_node_new_child_index = |
2013 | 101k | existing_node_partial_key[new_node_partial_key.len()]; |
2014 | 101k | new_node_children[usize::from(u8::from(existing_node_new_child_index))] = |
2015 | 101k | Some(existing_node_index); |
2016 | 101k | |
2017 | 101k | return PrepareInsert::One(PrepareInsertOne { |
2018 | 101k | trie: self.trie, |
2019 | 101k | parent: if let Some((future_parent_index, future_parent_key_len93.1k )) = future_parent { |
2020 | 93.1k | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); |
2021 | 93.1k | Some((future_parent_index, new_child_index)) |
2022 | | } else { |
2023 | 7.95k | None |
2024 | | }, |
2025 | 101k | partial_key: new_node_partial_key, |
2026 | 101k | children: new_node_children, |
2027 | | }); |
2028 | 243k | } |
2029 | | |
2030 | | // If we reach here, we know that we will need to create a new branch node in addition to |
2031 | | // the new storage node. |
2032 | | // |
2033 | | // If `future_parent` is `Some`: |
2034 | | // |
2035 | | // |
2036 | | // `future_parent` |
2037 | | // |
2038 | | // +-+ |
2039 | | // +-+ <--------+ (0 or more existing children) |
2040 | | // ^ |
2041 | | // | |
2042 | | // New branch node +-+ |
2043 | | // +-+ <-------+ |
2044 | | // ^ | |
2045 | | // | | |
2046 | | // +-+ +-+ |
2047 | | // `existing_node_index` +-+ +-+ New storage node |
2048 | | // ^ |
2049 | | // | |
2050 | | // |
2051 | | // (0 or more existing children) |
2052 | | // |
2053 | | // |
2054 | | // |
2055 | | // If `future_parent` is `None`: |
2056 | | // |
2057 | | // |
2058 | | // New branch node +-+ |
2059 | | // (becomes root) +-+ <-------+ |
2060 | | // ^ | |
2061 | | // | | |
2062 | | // `existing_node_index` +-+ +-+ |
2063 | | // (current root) +-+ +-+ New storage node |
2064 | | // ^ |
2065 | | // | |
2066 | | // |
2067 | | // (0 or more existing children) |
2068 | | // |
2069 | | // |
2070 | | |
2071 | | // Find the common ancestor between `new_node_partial_key` and `existing_node_partial_key`. |
2072 | 243k | let branch_partial_key_len = { |
2073 | 243k | debug_assert_ne!(new_node_partial_key, &**existing_node_partial_key); |
2074 | 243k | let mut len = 0; |
2075 | 243k | let mut k1 = new_node_partial_key.iter(); |
2076 | 243k | let mut k2 = existing_node_partial_key.iter(); |
2077 | | // Since `new_node_partial_key` is different from `existing_node_partial_key`, we know |
2078 | | // that `k1.next()` and `k2.next()` won't both be `None`. |
2079 | 367k | while k1.next() == k2.next() { |
2080 | 123k | len += 1; |
2081 | 123k | } |
2082 | 243k | debug_assert!(len < new_node_partial_key.len()); |
2083 | 243k | debug_assert!(len < existing_node_partial_key.len()); |
2084 | 243k | len |
2085 | | }; |
2086 | | |
2087 | | // Table of children for the new branch node, not including the new storage node. |
2088 | | // It therefore contains only one entry: `existing_node_index`. |
2089 | 243k | let branch_children = { |
2090 | 243k | let mut branch_children = [None; 16]; |
2091 | 243k | let existing_node_new_child_index = existing_node_partial_key[branch_partial_key_len]; |
2092 | 243k | debug_assert_ne!( |
2093 | | existing_node_new_child_index, |
2094 | 243k | new_node_partial_key[branch_partial_key_len] |
2095 | | ); |
2096 | 243k | branch_children[usize::from(u8::from(existing_node_new_child_index))] = |
2097 | 243k | Some(existing_node_index); |
2098 | 243k | branch_children |
2099 | 243k | }; |
2100 | 243k | |
2101 | 243k | // Success! |
2102 | 243k | PrepareInsert::Two(PrepareInsertTwo { |
2103 | 243k | trie: self.trie, |
2104 | 243k | |
2105 | 243k | storage_child_index: new_node_partial_key[branch_partial_key_len], |
2106 | 243k | storage_partial_key: new_node_partial_key[branch_partial_key_len + 1..].to_owned(), |
2107 | | |
2108 | 243k | branch_parent: if let Some((future_parent_index, future_parent_key_len227k )) = future_parent |
2109 | | { |
2110 | 227k | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); |
2111 | 227k | Some((future_parent_index, new_child_index)) |
2112 | | } else { |
2113 | 16.2k | None |
2114 | | }, |
2115 | 243k | branch_partial_key: new_node_partial_key[..branch_partial_key_len].to_owned(), |
2116 | 243k | branch_children, |
2117 | | }) |
2118 | 1.36M | } _RNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_6VacantINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEINtNtNtNtB17_4iter8adapters6copied6CopiedINtNtNtB17_5slice4iter4IterNtNtB7_6nibble6NibbleEEE20insert_storage_valueB9_ Line | Count | Source | 1889 | 28.8k | pub fn insert_storage_value(mut self) -> PrepareInsert<'a, TUd> { | 1890 | | // Retrieve what will be the parent after we insert the new node, not taking branching | 1891 | | // into account yet. | 1892 | | // If `Some`, contains its index and number of nibbles in its key. | 1893 | 28.8k | let future_parent27.3k = match (self.closest_ancestor, self.trie.root_index) { | 1894 | 0 | (Some(_), None) => unreachable!(), | 1895 | 25.3k | (Some(ancestor), Some(_)) => { | 1896 | 25.3k | // TODO: could be optimized by passing in the Vacant the key remainder | 1897 | 25.3k | let key_len = self.trie.node_full_key(ancestor).count(); | 1898 | 25.3k | debug_assert!(self.key.clone().count() > key_len); | 1899 | 25.3k | Some((ancestor, key_len)) | 1900 | | } | 1901 | 2.01k | (None, Some(_)) => None, | 1902 | | (None, None) => { | 1903 | | // Situation where the trie is empty. This is kind of a special case that we | 1904 | | // handle by returning early. | 1905 | 1.50k | return PrepareInsert::One(PrepareInsertOne { | 1906 | 1.50k | trie: self.trie, | 1907 | 1.50k | parent: None, | 1908 | 1.50k | partial_key: self.key.collect(), | 1909 | 1.50k | children: [None; 16], | 1910 | 1.50k | }); | 1911 | | } | 1912 | | }; | 1913 | | | 1914 | | // Get the existing child of `future_parent` that points towards the newly-inserted node, | 1915 | | // or a successful early-return if none. | 1916 | 7.15k | let existing_node_index = | 1917 | 27.3k | if let Some((future_parent_index, future_parent_key_len25.3k )) = future_parent { | 1918 | 25.3k | let new_child_index = self.key.clone().nth(future_parent_key_len).unwrap(); | 1919 | 25.3k | let future_parent = self.trie.nodes.get(future_parent_index).unwrap(); | 1920 | 25.3k | match future_parent.children[usize::from(u8::from(new_child_index))] { | 1921 | 5.14k | Some(i) => { | 1922 | 5.14k | debug_assert_eq!( | 1923 | 5.14k | self.trie.nodes.get(i).unwrap().parent.unwrap().0, | 1924 | | future_parent_index | 1925 | | ); | 1926 | 5.14k | i | 1927 | | } | 1928 | | None => { | 1929 | | // There is an empty slot in `future_parent` for our new node. | 1930 | | // | 1931 | | // | 1932 | | // `future_parent` | 1933 | | // +-+ | 1934 | | // +-> +-+ <---------+ | 1935 | | // | <----+ | | 1936 | | // | ^ | | | 1937 | | // +-+ | | | | 1938 | | // New node +-+ +-+-+ +-+ +-+ 0 or more existing children | 1939 | | // +-+ +-+ +-+ | 1940 | | // | 1941 | | // | 1942 | 20.1k | return PrepareInsert::One(PrepareInsertOne { | 1943 | 20.1k | trie: self.trie, | 1944 | 20.1k | parent: Some((future_parent_index, new_child_index)), | 1945 | 20.1k | partial_key: self.key.skip(future_parent_key_len + 1).collect(), | 1946 | 20.1k | children: [None; 16], | 1947 | 20.1k | }); | 1948 | | } | 1949 | | } | 1950 | | } else { | 1951 | 2.01k | self.trie.root_index.unwrap() | 1952 | | }; | 1953 | | | 1954 | | // `existing_node_idx` and the new node are known to either have the same parent and the | 1955 | | // same child index, or to both have no parent. Now let's compare their partial key. | 1956 | 7.15k | let existing_node_partial_key = &self | 1957 | 7.15k | .trie | 1958 | 7.15k | .nodes | 1959 | 7.15k | .get(existing_node_index) | 1960 | 7.15k | .unwrap() | 1961 | 7.15k | .partial_key; | 1962 | 7.15k | let new_node_partial_key = self | 1963 | 7.15k | .key | 1964 | 7.15k | .clone() | 1965 | 7.15k | .skip(future_parent.map_or(0, |(_, n)| n + 1)) | 1966 | 7.15k | .collect::<Vec<_>>(); | 1967 | 7.15k | debug_assert_ne!(*existing_node_partial_key, new_node_partial_key); | 1968 | 7.15k | debug_assert!(!new_node_partial_key.starts_with(existing_node_partial_key)); | 1969 | | | 1970 | | // If `existing_node_partial_key` starts with `new_node_partial_key`, then the new node | 1971 | | // will be inserted in-between the parent and the existing node. | 1972 | 7.15k | if existing_node_partial_key.starts_with(&new_node_partial_key) { | 1973 | | // The new node is to be inserted in-between `future_parent` and | 1974 | | // `existing_node_index`. | 1975 | | // | 1976 | | // If `future_parent` is `Some`: | 1977 | | // | 1978 | | // | 1979 | | // +-+ | 1980 | | // `future_parent` +-+ <---------+ | 1981 | | // ^ | | 1982 | | // | + | 1983 | | // +-+ (0 or more existing children) | 1984 | | // New node +-+ | 1985 | | // ^ | 1986 | | // | | 1987 | | // +-+ | 1988 | | // `existing_node_index` +-+ | 1989 | | // ^ | 1990 | | // | | 1991 | | // + | 1992 | | // (0 or more existing children) | 1993 | | // | 1994 | | // | 1995 | | // | 1996 | | // If `future_parent` is `None`: | 1997 | | // | 1998 | | // | 1999 | | // New node +-+ | 2000 | | // (becomes the root) +-+ | 2001 | | // ^ | 2002 | | // | | 2003 | | // `existing_node_index` +-+ | 2004 | | // (current root) +-+ | 2005 | | // ^ | 2006 | | // | | 2007 | | // + | 2008 | | // (0 or more existing children) | 2009 | | // | 2010 | | | 2011 | 7.15k | let mut new_node_children = [None; 16]; | 2012 | 7.15k | let existing_node_new_child_index = | 2013 | 7.15k | existing_node_partial_key[new_node_partial_key.len()]; | 2014 | 7.15k | new_node_children[usize::from(u8::from(existing_node_new_child_index))] = | 2015 | 7.15k | Some(existing_node_index); | 2016 | 7.15k | | 2017 | 7.15k | return PrepareInsert::One(PrepareInsertOne { | 2018 | 7.15k | trie: self.trie, | 2019 | 7.15k | parent: if let Some((future_parent_index, future_parent_key_len5.14k )) = future_parent { | 2020 | 5.14k | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2021 | 5.14k | Some((future_parent_index, new_child_index)) | 2022 | | } else { | 2023 | 2.01k | None | 2024 | | }, | 2025 | 7.15k | partial_key: new_node_partial_key, | 2026 | 7.15k | children: new_node_children, | 2027 | | }); | 2028 | 0 | } | 2029 | | | 2030 | | // If we reach here, we know that we will need to create a new branch node in addition to | 2031 | | // the new storage node. | 2032 | | // | 2033 | | // If `future_parent` is `Some`: | 2034 | | // | 2035 | | // | 2036 | | // `future_parent` | 2037 | | // | 2038 | | // +-+ | 2039 | | // +-+ <--------+ (0 or more existing children) | 2040 | | // ^ | 2041 | | // | | 2042 | | // New branch node +-+ | 2043 | | // +-+ <-------+ | 2044 | | // ^ | | 2045 | | // | | | 2046 | | // +-+ +-+ | 2047 | | // `existing_node_index` +-+ +-+ New storage node | 2048 | | // ^ | 2049 | | // | | 2050 | | // | 2051 | | // (0 or more existing children) | 2052 | | // | 2053 | | // | 2054 | | // | 2055 | | // If `future_parent` is `None`: | 2056 | | // | 2057 | | // | 2058 | | // New branch node +-+ | 2059 | | // (becomes root) +-+ <-------+ | 2060 | | // ^ | | 2061 | | // | | | 2062 | | // `existing_node_index` +-+ +-+ | 2063 | | // (current root) +-+ +-+ New storage node | 2064 | | // ^ | 2065 | | // | | 2066 | | // | 2067 | | // (0 or more existing children) | 2068 | | // | 2069 | | // | 2070 | | | 2071 | | // Find the common ancestor between `new_node_partial_key` and `existing_node_partial_key`. | 2072 | 0 | let branch_partial_key_len = { | 2073 | 0 | debug_assert_ne!(new_node_partial_key, &**existing_node_partial_key); | 2074 | 0 | let mut len = 0; | 2075 | 0 | let mut k1 = new_node_partial_key.iter(); | 2076 | 0 | let mut k2 = existing_node_partial_key.iter(); | 2077 | | // Since `new_node_partial_key` is different from `existing_node_partial_key`, we know | 2078 | | // that `k1.next()` and `k2.next()` won't both be `None`. | 2079 | 0 | while k1.next() == k2.next() { | 2080 | 0 | len += 1; | 2081 | 0 | } | 2082 | 0 | debug_assert!(len < new_node_partial_key.len()); | 2083 | 0 | debug_assert!(len < existing_node_partial_key.len()); | 2084 | 0 | len | 2085 | | }; | 2086 | | | 2087 | | // Table of children for the new branch node, not including the new storage node. | 2088 | | // It therefore contains only one entry: `existing_node_index`. | 2089 | 0 | let branch_children = { | 2090 | 0 | let mut branch_children = [None; 16]; | 2091 | 0 | let existing_node_new_child_index = existing_node_partial_key[branch_partial_key_len]; | 2092 | 0 | debug_assert_ne!( | 2093 | | existing_node_new_child_index, | 2094 | 0 | new_node_partial_key[branch_partial_key_len] | 2095 | | ); | 2096 | 0 | branch_children[usize::from(u8::from(existing_node_new_child_index))] = | 2097 | 0 | Some(existing_node_index); | 2098 | 0 | branch_children | 2099 | 0 | }; | 2100 | 0 |
| 2101 | 0 | // Success! | 2102 | 0 | PrepareInsert::Two(PrepareInsertTwo { | 2103 | 0 | trie: self.trie, | 2104 | 0 |
| 2105 | 0 | storage_child_index: new_node_partial_key[branch_partial_key_len], | 2106 | 0 | storage_partial_key: new_node_partial_key[branch_partial_key_len + 1..].to_owned(), | 2107 | | | 2108 | 0 | branch_parent: if let Some((future_parent_index, future_parent_key_len)) = future_parent | 2109 | | { | 2110 | 0 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2111 | 0 | Some((future_parent_index, new_child_index)) | 2112 | | } else { | 2113 | 0 | None | 2114 | | }, | 2115 | 0 | branch_partial_key: new_node_partial_key[..branch_partial_key_len].to_owned(), | 2116 | 0 | branch_children, | 2117 | | }) | 2118 | 28.8k | } |
_RNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_6VacantTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB14_NtNtB7_9trie_node17MerkleValueOutputEEINtNtB7_6nibble14BytesToNibblesINtNtNtNtB18_4iter8adapters6copied6CopiedINtNtNtB18_5slice4iter4IterhEEEE20insert_storage_valueB9_ Line | Count | Source | 1889 | 2.51k | pub fn insert_storage_value(mut self) -> PrepareInsert<'a, TUd> { | 1890 | | // Retrieve what will be the parent after we insert the new node, not taking branching | 1891 | | // into account yet. | 1892 | | // If `Some`, contains its index and number of nibbles in its key. | 1893 | 2.51k | let future_parent1.49k = match (self.closest_ancestor, self.trie.root_index) { | 1894 | 0 | (Some(_), None) => unreachable!(), | 1895 | 1.49k | (Some(ancestor), Some(_)) => { | 1896 | 1.49k | // TODO: could be optimized by passing in the Vacant the key remainder | 1897 | 1.49k | let key_len = self.trie.node_full_key(ancestor).count(); | 1898 | 1.49k | debug_assert!(self.key.clone().count() > key_len); | 1899 | 1.49k | Some((ancestor, key_len)) | 1900 | | } | 1901 | 0 | (None, Some(_)) => None, | 1902 | | (None, None) => { | 1903 | | // Situation where the trie is empty. This is kind of a special case that we | 1904 | | // handle by returning early. | 1905 | 1.02k | return PrepareInsert::One(PrepareInsertOne { | 1906 | 1.02k | trie: self.trie, | 1907 | 1.02k | parent: None, | 1908 | 1.02k | partial_key: self.key.collect(), | 1909 | 1.02k | children: [None; 16], | 1910 | 1.02k | }); | 1911 | | } | 1912 | | }; | 1913 | | | 1914 | | // Get the existing child of `future_parent` that points towards the newly-inserted node, | 1915 | | // or a successful early-return if none. | 1916 | 69 | let existing_node_index = | 1917 | 1.49k | if let Some((future_parent_index, future_parent_key_len)) = future_parent { | 1918 | 1.49k | let new_child_index = self.key.clone().nth(future_parent_key_len).unwrap(); | 1919 | 1.49k | let future_parent = self.trie.nodes.get(future_parent_index).unwrap(); | 1920 | 1.49k | match future_parent.children[usize::from(u8::from(new_child_index))] { | 1921 | 69 | Some(i) => { | 1922 | 69 | debug_assert_eq!( | 1923 | 69 | self.trie.nodes.get(i).unwrap().parent.unwrap().0, | 1924 | | future_parent_index | 1925 | | ); | 1926 | 69 | i | 1927 | | } | 1928 | | None => { | 1929 | | // There is an empty slot in `future_parent` for our new node. | 1930 | | // | 1931 | | // | 1932 | | // `future_parent` | 1933 | | // +-+ | 1934 | | // +-> +-+ <---------+ | 1935 | | // | <----+ | | 1936 | | // | ^ | | | 1937 | | // +-+ | | | | 1938 | | // New node +-+ +-+-+ +-+ +-+ 0 or more existing children | 1939 | | // +-+ +-+ +-+ | 1940 | | // | 1941 | | // | 1942 | 1.42k | return PrepareInsert::One(PrepareInsertOne { | 1943 | 1.42k | trie: self.trie, | 1944 | 1.42k | parent: Some((future_parent_index, new_child_index)), | 1945 | 1.42k | partial_key: self.key.skip(future_parent_key_len + 1).collect(), | 1946 | 1.42k | children: [None; 16], | 1947 | 1.42k | }); | 1948 | | } | 1949 | | } | 1950 | | } else { | 1951 | 0 | self.trie.root_index.unwrap() | 1952 | | }; | 1953 | | | 1954 | | // `existing_node_idx` and the new node are known to either have the same parent and the | 1955 | | // same child index, or to both have no parent. Now let's compare their partial key. | 1956 | 69 | let existing_node_partial_key = &self | 1957 | 69 | .trie | 1958 | 69 | .nodes | 1959 | 69 | .get(existing_node_index) | 1960 | 69 | .unwrap() | 1961 | 69 | .partial_key; | 1962 | 69 | let new_node_partial_key = self | 1963 | 69 | .key | 1964 | 69 | .clone() | 1965 | 69 | .skip(future_parent.map_or(0, |(_, n)| n + 1)) | 1966 | 69 | .collect::<Vec<_>>(); | 1967 | 69 | debug_assert_ne!(*existing_node_partial_key, new_node_partial_key); | 1968 | 69 | debug_assert!(!new_node_partial_key.starts_with(existing_node_partial_key)); | 1969 | | | 1970 | | // If `existing_node_partial_key` starts with `new_node_partial_key`, then the new node | 1971 | | // will be inserted in-between the parent and the existing node. | 1972 | 69 | if existing_node_partial_key.starts_with(&new_node_partial_key) { | 1973 | | // The new node is to be inserted in-between `future_parent` and | 1974 | | // `existing_node_index`. | 1975 | | // | 1976 | | // If `future_parent` is `Some`: | 1977 | | // | 1978 | | // | 1979 | | // +-+ | 1980 | | // `future_parent` +-+ <---------+ | 1981 | | // ^ | | 1982 | | // | + | 1983 | | // +-+ (0 or more existing children) | 1984 | | // New node +-+ | 1985 | | // ^ | 1986 | | // | | 1987 | | // +-+ | 1988 | | // `existing_node_index` +-+ | 1989 | | // ^ | 1990 | | // | | 1991 | | // + | 1992 | | // (0 or more existing children) | 1993 | | // | 1994 | | // | 1995 | | // | 1996 | | // If `future_parent` is `None`: | 1997 | | // | 1998 | | // | 1999 | | // New node +-+ | 2000 | | // (becomes the root) +-+ | 2001 | | // ^ | 2002 | | // | | 2003 | | // `existing_node_index` +-+ | 2004 | | // (current root) +-+ | 2005 | | // ^ | 2006 | | // | | 2007 | | // + | 2008 | | // (0 or more existing children) | 2009 | | // | 2010 | | | 2011 | 1 | let mut new_node_children = [None; 16]; | 2012 | 1 | let existing_node_new_child_index = | 2013 | 1 | existing_node_partial_key[new_node_partial_key.len()]; | 2014 | 1 | new_node_children[usize::from(u8::from(existing_node_new_child_index))] = | 2015 | 1 | Some(existing_node_index); | 2016 | 1 | | 2017 | 1 | return PrepareInsert::One(PrepareInsertOne { | 2018 | 1 | trie: self.trie, | 2019 | 1 | parent: if let Some((future_parent_index, future_parent_key_len)) = future_parent { | 2020 | 1 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2021 | 1 | Some((future_parent_index, new_child_index)) | 2022 | | } else { | 2023 | 0 | None | 2024 | | }, | 2025 | 1 | partial_key: new_node_partial_key, | 2026 | 1 | children: new_node_children, | 2027 | | }); | 2028 | 68 | } | 2029 | | | 2030 | | // If we reach here, we know that we will need to create a new branch node in addition to | 2031 | | // the new storage node. | 2032 | | // | 2033 | | // If `future_parent` is `Some`: | 2034 | | // | 2035 | | // | 2036 | | // `future_parent` | 2037 | | // | 2038 | | // +-+ | 2039 | | // +-+ <--------+ (0 or more existing children) | 2040 | | // ^ | 2041 | | // | | 2042 | | // New branch node +-+ | 2043 | | // +-+ <-------+ | 2044 | | // ^ | | 2045 | | // | | | 2046 | | // +-+ +-+ | 2047 | | // `existing_node_index` +-+ +-+ New storage node | 2048 | | // ^ | 2049 | | // | | 2050 | | // | 2051 | | // (0 or more existing children) | 2052 | | // | 2053 | | // | 2054 | | // | 2055 | | // If `future_parent` is `None`: | 2056 | | // | 2057 | | // | 2058 | | // New branch node +-+ | 2059 | | // (becomes root) +-+ <-------+ | 2060 | | // ^ | | 2061 | | // | | | 2062 | | // `existing_node_index` +-+ +-+ | 2063 | | // (current root) +-+ +-+ New storage node | 2064 | | // ^ | 2065 | | // | | 2066 | | // | 2067 | | // (0 or more existing children) | 2068 | | // | 2069 | | // | 2070 | | | 2071 | | // Find the common ancestor between `new_node_partial_key` and `existing_node_partial_key`. | 2072 | 68 | let branch_partial_key_len = { | 2073 | 68 | debug_assert_ne!(new_node_partial_key, &**existing_node_partial_key); | 2074 | 68 | let mut len = 0; | 2075 | 68 | let mut k1 = new_node_partial_key.iter(); | 2076 | 68 | let mut k2 = existing_node_partial_key.iter(); | 2077 | | // Since `new_node_partial_key` is different from `existing_node_partial_key`, we know | 2078 | | // that `k1.next()` and `k2.next()` won't both be `None`. | 2079 | 71 | while k1.next() == k2.next() { | 2080 | 3 | len += 1; | 2081 | 3 | } | 2082 | 68 | debug_assert!(len < new_node_partial_key.len()); | 2083 | 68 | debug_assert!(len < existing_node_partial_key.len()); | 2084 | 68 | len | 2085 | | }; | 2086 | | | 2087 | | // Table of children for the new branch node, not including the new storage node. | 2088 | | // It therefore contains only one entry: `existing_node_index`. | 2089 | 68 | let branch_children = { | 2090 | 68 | let mut branch_children = [None; 16]; | 2091 | 68 | let existing_node_new_child_index = existing_node_partial_key[branch_partial_key_len]; | 2092 | 68 | debug_assert_ne!( | 2093 | | existing_node_new_child_index, | 2094 | 68 | new_node_partial_key[branch_partial_key_len] | 2095 | | ); | 2096 | 68 | branch_children[usize::from(u8::from(existing_node_new_child_index))] = | 2097 | 68 | Some(existing_node_index); | 2098 | 68 | branch_children | 2099 | 68 | }; | 2100 | 68 | | 2101 | 68 | // Success! | 2102 | 68 | PrepareInsert::Two(PrepareInsertTwo { | 2103 | 68 | trie: self.trie, | 2104 | 68 | | 2105 | 68 | storage_child_index: new_node_partial_key[branch_partial_key_len], | 2106 | 68 | storage_partial_key: new_node_partial_key[branch_partial_key_len + 1..].to_owned(), | 2107 | | | 2108 | 68 | branch_parent: if let Some((future_parent_index, future_parent_key_len)) = future_parent | 2109 | | { | 2110 | 68 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2111 | 68 | Some((future_parent_index, new_child_index)) | 2112 | | } else { | 2113 | 0 | None | 2114 | | }, | 2115 | 68 | branch_partial_key: new_node_partial_key[..branch_partial_key_len].to_owned(), | 2116 | 68 | branch_children, | 2117 | | }) | 2118 | 2.51k | } |
_RNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_6VacantTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB14_NtNtB7_9trie_node17MerkleValueOutputEEINtNtB7_6nibble14BytesToNibblesINtNtNtNtB18_4iter8adapters6copied6CopiedINtNtNtB18_5slice4iter4IterhEEEE20insert_storage_valueB9_ Line | Count | Source | 1889 | 335k | pub fn insert_storage_value(mut self) -> PrepareInsert<'a, TUd> { | 1890 | | // Retrieve what will be the parent after we insert the new node, not taking branching | 1891 | | // into account yet. | 1892 | | // If `Some`, contains its index and number of nibbles in its key. | 1893 | 335k | let future_parent296k = match (self.closest_ancestor, self.trie.root_index) { | 1894 | 0 | (Some(_), None) => unreachable!(), | 1895 | 283k | (Some(ancestor), Some(_)) => { | 1896 | 283k | // TODO: could be optimized by passing in the Vacant the key remainder | 1897 | 283k | let key_len = self.trie.node_full_key(ancestor).count(); | 1898 | 283k | debug_assert!(self.key.clone().count() > key_len); | 1899 | 283k | Some((ancestor, key_len)) | 1900 | | } | 1901 | 12.9k | (None, Some(_)) => None, | 1902 | | (None, None) => { | 1903 | | // Situation where the trie is empty. This is kind of a special case that we | 1904 | | // handle by returning early. | 1905 | 38.7k | return PrepareInsert::One(PrepareInsertOne { | 1906 | 38.7k | trie: self.trie, | 1907 | 38.7k | parent: None, | 1908 | 38.7k | partial_key: self.key.collect(), | 1909 | 38.7k | children: [None; 16], | 1910 | 38.7k | }); | 1911 | | } | 1912 | | }; | 1913 | | | 1914 | | // Get the existing child of `future_parent` that points towards the newly-inserted node, | 1915 | | // or a successful early-return if none. | 1916 | 70.3k | let existing_node_index = | 1917 | 296k | if let Some((future_parent_index, future_parent_key_len283k )) = future_parent { | 1918 | 283k | let new_child_index = self.key.clone().nth(future_parent_key_len).unwrap(); | 1919 | 283k | let future_parent = self.trie.nodes.get(future_parent_index).unwrap(); | 1920 | 283k | match future_parent.children[usize::from(u8::from(new_child_index))] { | 1921 | 57.4k | Some(i) => { | 1922 | 57.4k | debug_assert_eq!( | 1923 | 57.4k | self.trie.nodes.get(i).unwrap().parent.unwrap().0, | 1924 | | future_parent_index | 1925 | | ); | 1926 | 57.4k | i | 1927 | | } | 1928 | | None => { | 1929 | | // There is an empty slot in `future_parent` for our new node. | 1930 | | // | 1931 | | // | 1932 | | // `future_parent` | 1933 | | // +-+ | 1934 | | // +-> +-+ <---------+ | 1935 | | // | <----+ | | 1936 | | // | ^ | | | 1937 | | // +-+ | | | | 1938 | | // New node +-+ +-+-+ +-+ +-+ 0 or more existing children | 1939 | | // +-+ +-+ +-+ | 1940 | | // | 1941 | | // | 1942 | 225k | return PrepareInsert::One(PrepareInsertOne { | 1943 | 225k | trie: self.trie, | 1944 | 225k | parent: Some((future_parent_index, new_child_index)), | 1945 | 225k | partial_key: self.key.skip(future_parent_key_len + 1).collect(), | 1946 | 225k | children: [None; 16], | 1947 | 225k | }); | 1948 | | } | 1949 | | } | 1950 | | } else { | 1951 | 12.9k | self.trie.root_index.unwrap() | 1952 | | }; | 1953 | | | 1954 | | // `existing_node_idx` and the new node are known to either have the same parent and the | 1955 | | // same child index, or to both have no parent. Now let's compare their partial key. | 1956 | 70.3k | let existing_node_partial_key = &self | 1957 | 70.3k | .trie | 1958 | 70.3k | .nodes | 1959 | 70.3k | .get(existing_node_index) | 1960 | 70.3k | .unwrap() | 1961 | 70.3k | .partial_key; | 1962 | 70.3k | let new_node_partial_key = self | 1963 | 70.3k | .key | 1964 | 70.3k | .clone() | 1965 | 70.3k | .skip(future_parent.map_or(0, |(_, n)| n + 1)) | 1966 | 70.3k | .collect::<Vec<_>>(); | 1967 | 70.3k | debug_assert_ne!(*existing_node_partial_key, new_node_partial_key); | 1968 | 70.3k | debug_assert!(!new_node_partial_key.starts_with(existing_node_partial_key)); | 1969 | | | 1970 | | // If `existing_node_partial_key` starts with `new_node_partial_key`, then the new node | 1971 | | // will be inserted in-between the parent and the existing node. | 1972 | 70.3k | if existing_node_partial_key.starts_with(&new_node_partial_key) { | 1973 | | // The new node is to be inserted in-between `future_parent` and | 1974 | | // `existing_node_index`. | 1975 | | // | 1976 | | // If `future_parent` is `Some`: | 1977 | | // | 1978 | | // | 1979 | | // +-+ | 1980 | | // `future_parent` +-+ <---------+ | 1981 | | // ^ | | 1982 | | // | + | 1983 | | // +-+ (0 or more existing children) | 1984 | | // New node +-+ | 1985 | | // ^ | 1986 | | // | | 1987 | | // +-+ | 1988 | | // `existing_node_index` +-+ | 1989 | | // ^ | 1990 | | // | | 1991 | | // + | 1992 | | // (0 or more existing children) | 1993 | | // | 1994 | | // | 1995 | | // | 1996 | | // If `future_parent` is `None`: | 1997 | | // | 1998 | | // | 1999 | | // New node +-+ | 2000 | | // (becomes the root) +-+ | 2001 | | // ^ | 2002 | | // | | 2003 | | // `existing_node_index` +-+ | 2004 | | // (current root) +-+ | 2005 | | // ^ | 2006 | | // | | 2007 | | // + | 2008 | | // (0 or more existing children) | 2009 | | // | 2010 | | | 2011 | 6.67k | let mut new_node_children = [None; 16]; | 2012 | 6.67k | let existing_node_new_child_index = | 2013 | 6.67k | existing_node_partial_key[new_node_partial_key.len()]; | 2014 | 6.67k | new_node_children[usize::from(u8::from(existing_node_new_child_index))] = | 2015 | 6.67k | Some(existing_node_index); | 2016 | 6.67k | | 2017 | 6.67k | return PrepareInsert::One(PrepareInsertOne { | 2018 | 6.67k | trie: self.trie, | 2019 | 6.67k | parent: if let Some((future_parent_index, future_parent_key_len1.10k )) = future_parent { | 2020 | 1.10k | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2021 | 1.10k | Some((future_parent_index, new_child_index)) | 2022 | | } else { | 2023 | 5.57k | None | 2024 | | }, | 2025 | 6.67k | partial_key: new_node_partial_key, | 2026 | 6.67k | children: new_node_children, | 2027 | | }); | 2028 | 63.7k | } | 2029 | | | 2030 | | // If we reach here, we know that we will need to create a new branch node in addition to | 2031 | | // the new storage node. | 2032 | | // | 2033 | | // If `future_parent` is `Some`: | 2034 | | // | 2035 | | // | 2036 | | // `future_parent` | 2037 | | // | 2038 | | // +-+ | 2039 | | // +-+ <--------+ (0 or more existing children) | 2040 | | // ^ | 2041 | | // | | 2042 | | // New branch node +-+ | 2043 | | // +-+ <-------+ | 2044 | | // ^ | | 2045 | | // | | | 2046 | | // +-+ +-+ | 2047 | | // `existing_node_index` +-+ +-+ New storage node | 2048 | | // ^ | 2049 | | // | | 2050 | | // | 2051 | | // (0 or more existing children) | 2052 | | // | 2053 | | // | 2054 | | // | 2055 | | // If `future_parent` is `None`: | 2056 | | // | 2057 | | // | 2058 | | // New branch node +-+ | 2059 | | // (becomes root) +-+ <-------+ | 2060 | | // ^ | | 2061 | | // | | | 2062 | | // `existing_node_index` +-+ +-+ | 2063 | | // (current root) +-+ +-+ New storage node | 2064 | | // ^ | 2065 | | // | | 2066 | | // | 2067 | | // (0 or more existing children) | 2068 | | // | 2069 | | // | 2070 | | | 2071 | | // Find the common ancestor between `new_node_partial_key` and `existing_node_partial_key`. | 2072 | 63.7k | let branch_partial_key_len = { | 2073 | 63.7k | debug_assert_ne!(new_node_partial_key, &**existing_node_partial_key); | 2074 | 63.7k | let mut len = 0; | 2075 | 63.7k | let mut k1 = new_node_partial_key.iter(); | 2076 | 63.7k | let mut k2 = existing_node_partial_key.iter(); | 2077 | | // Since `new_node_partial_key` is different from `existing_node_partial_key`, we know | 2078 | | // that `k1.next()` and `k2.next()` won't both be `None`. | 2079 | 65.8k | while k1.next() == k2.next() { | 2080 | 2.10k | len += 1; | 2081 | 2.10k | } | 2082 | 63.7k | debug_assert!(len < new_node_partial_key.len()); | 2083 | 63.7k | debug_assert!(len < existing_node_partial_key.len()); | 2084 | 63.7k | len | 2085 | | }; | 2086 | | | 2087 | | // Table of children for the new branch node, not including the new storage node. | 2088 | | // It therefore contains only one entry: `existing_node_index`. | 2089 | 63.7k | let branch_children = { | 2090 | 63.7k | let mut branch_children = [None; 16]; | 2091 | 63.7k | let existing_node_new_child_index = existing_node_partial_key[branch_partial_key_len]; | 2092 | 63.7k | debug_assert_ne!( | 2093 | | existing_node_new_child_index, | 2094 | 63.7k | new_node_partial_key[branch_partial_key_len] | 2095 | | ); | 2096 | 63.7k | branch_children[usize::from(u8::from(existing_node_new_child_index))] = | 2097 | 63.7k | Some(existing_node_index); | 2098 | 63.7k | branch_children | 2099 | 63.7k | }; | 2100 | 63.7k | | 2101 | 63.7k | // Success! | 2102 | 63.7k | PrepareInsert::Two(PrepareInsertTwo { | 2103 | 63.7k | trie: self.trie, | 2104 | 63.7k | | 2105 | 63.7k | storage_child_index: new_node_partial_key[branch_partial_key_len], | 2106 | 63.7k | storage_partial_key: new_node_partial_key[branch_partial_key_len + 1..].to_owned(), | 2107 | | | 2108 | 63.7k | branch_parent: if let Some((future_parent_index, future_parent_key_len56.3k )) = future_parent | 2109 | | { | 2110 | 56.3k | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2111 | 56.3k | Some((future_parent_index, new_child_index)) | 2112 | | } else { | 2113 | 7.33k | None | 2114 | | }, | 2115 | 63.7k | branch_partial_key: new_node_partial_key[..branch_partial_key_len].to_owned(), | 2116 | 63.7k | branch_children, | 2117 | | }) | 2118 | 335k | } |
_RNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_6VacantuINtNtB7_6nibble14BytesToNibblesINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1H_5slice4iter4IterhEEEE20insert_storage_valueB9_ Line | Count | Source | 1889 | 5.23k | pub fn insert_storage_value(mut self) -> PrepareInsert<'a, TUd> { | 1890 | | // Retrieve what will be the parent after we insert the new node, not taking branching | 1891 | | // into account yet. | 1892 | | // If `Some`, contains its index and number of nibbles in its key. | 1893 | 5.23k | let future_parent3.18k = match (self.closest_ancestor, self.trie.root_index) { | 1894 | 0 | (Some(_), None) => unreachable!(), | 1895 | 3.18k | (Some(ancestor), Some(_)) => { | 1896 | 3.18k | // TODO: could be optimized by passing in the Vacant the key remainder | 1897 | 3.18k | let key_len = self.trie.node_full_key(ancestor).count(); | 1898 | 3.18k | debug_assert!(self.key.clone().count() > key_len); | 1899 | 3.18k | Some((ancestor, key_len)) | 1900 | | } | 1901 | 0 | (None, Some(_)) => None, | 1902 | | (None, None) => { | 1903 | | // Situation where the trie is empty. This is kind of a special case that we | 1904 | | // handle by returning early. | 1905 | 2.04k | return PrepareInsert::One(PrepareInsertOne { | 1906 | 2.04k | trie: self.trie, | 1907 | 2.04k | parent: None, | 1908 | 2.04k | partial_key: self.key.collect(), | 1909 | 2.04k | children: [None; 16], | 1910 | 2.04k | }); | 1911 | | } | 1912 | | }; | 1913 | | | 1914 | | // Get the existing child of `future_parent` that points towards the newly-inserted node, | 1915 | | // or a successful early-return if none. | 1916 | 147 | let existing_node_index = | 1917 | 3.18k | if let Some((future_parent_index, future_parent_key_len)) = future_parent { | 1918 | 3.18k | let new_child_index = self.key.clone().nth(future_parent_key_len).unwrap(); | 1919 | 3.18k | let future_parent = self.trie.nodes.get(future_parent_index).unwrap(); | 1920 | 3.18k | match future_parent.children[usize::from(u8::from(new_child_index))] { | 1921 | 147 | Some(i) => { | 1922 | 147 | debug_assert_eq!( | 1923 | 147 | self.trie.nodes.get(i).unwrap().parent.unwrap().0, | 1924 | | future_parent_index | 1925 | | ); | 1926 | 147 | i | 1927 | | } | 1928 | | None => { | 1929 | | // There is an empty slot in `future_parent` for our new node. | 1930 | | // | 1931 | | // | 1932 | | // `future_parent` | 1933 | | // +-+ | 1934 | | // +-> +-+ <---------+ | 1935 | | // | <----+ | | 1936 | | // | ^ | | | 1937 | | // +-+ | | | | 1938 | | // New node +-+ +-+-+ +-+ +-+ 0 or more existing children | 1939 | | // +-+ +-+ +-+ | 1940 | | // | 1941 | | // | 1942 | 3.03k | return PrepareInsert::One(PrepareInsertOne { | 1943 | 3.03k | trie: self.trie, | 1944 | 3.03k | parent: Some((future_parent_index, new_child_index)), | 1945 | 3.03k | partial_key: self.key.skip(future_parent_key_len + 1).collect(), | 1946 | 3.03k | children: [None; 16], | 1947 | 3.03k | }); | 1948 | | } | 1949 | | } | 1950 | | } else { | 1951 | 0 | self.trie.root_index.unwrap() | 1952 | | }; | 1953 | | | 1954 | | // `existing_node_idx` and the new node are known to either have the same parent and the | 1955 | | // same child index, or to both have no parent. Now let's compare their partial key. | 1956 | 147 | let existing_node_partial_key = &self | 1957 | 147 | .trie | 1958 | 147 | .nodes | 1959 | 147 | .get(existing_node_index) | 1960 | 147 | .unwrap() | 1961 | 147 | .partial_key; | 1962 | 147 | let new_node_partial_key = self | 1963 | 147 | .key | 1964 | 147 | .clone() | 1965 | 147 | .skip(future_parent.map_or(0, |(_, n)| n + 1)) | 1966 | 147 | .collect::<Vec<_>>(); | 1967 | 147 | debug_assert_ne!(*existing_node_partial_key, new_node_partial_key); | 1968 | 147 | debug_assert!(!new_node_partial_key.starts_with(existing_node_partial_key)); | 1969 | | | 1970 | | // If `existing_node_partial_key` starts with `new_node_partial_key`, then the new node | 1971 | | // will be inserted in-between the parent and the existing node. | 1972 | 147 | if existing_node_partial_key.starts_with(&new_node_partial_key) { | 1973 | | // The new node is to be inserted in-between `future_parent` and | 1974 | | // `existing_node_index`. | 1975 | | // | 1976 | | // If `future_parent` is `Some`: | 1977 | | // | 1978 | | // | 1979 | | // +-+ | 1980 | | // `future_parent` +-+ <---------+ | 1981 | | // ^ | | 1982 | | // | + | 1983 | | // +-+ (0 or more existing children) | 1984 | | // New node +-+ | 1985 | | // ^ | 1986 | | // | | 1987 | | // +-+ | 1988 | | // `existing_node_index` +-+ | 1989 | | // ^ | 1990 | | // | | 1991 | | // + | 1992 | | // (0 or more existing children) | 1993 | | // | 1994 | | // | 1995 | | // | 1996 | | // If `future_parent` is `None`: | 1997 | | // | 1998 | | // | 1999 | | // New node +-+ | 2000 | | // (becomes the root) +-+ | 2001 | | // ^ | 2002 | | // | | 2003 | | // `existing_node_index` +-+ | 2004 | | // (current root) +-+ | 2005 | | // ^ | 2006 | | // | | 2007 | | // + | 2008 | | // (0 or more existing children) | 2009 | | // | 2010 | | | 2011 | 2 | let mut new_node_children = [None; 16]; | 2012 | 2 | let existing_node_new_child_index = | 2013 | 2 | existing_node_partial_key[new_node_partial_key.len()]; | 2014 | 2 | new_node_children[usize::from(u8::from(existing_node_new_child_index))] = | 2015 | 2 | Some(existing_node_index); | 2016 | 2 | | 2017 | 2 | return PrepareInsert::One(PrepareInsertOne { | 2018 | 2 | trie: self.trie, | 2019 | 2 | parent: if let Some((future_parent_index, future_parent_key_len)) = future_parent { | 2020 | 2 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2021 | 2 | Some((future_parent_index, new_child_index)) | 2022 | | } else { | 2023 | 0 | None | 2024 | | }, | 2025 | 2 | partial_key: new_node_partial_key, | 2026 | 2 | children: new_node_children, | 2027 | | }); | 2028 | 145 | } | 2029 | | | 2030 | | // If we reach here, we know that we will need to create a new branch node in addition to | 2031 | | // the new storage node. | 2032 | | // | 2033 | | // If `future_parent` is `Some`: | 2034 | | // | 2035 | | // | 2036 | | // `future_parent` | 2037 | | // | 2038 | | // +-+ | 2039 | | // +-+ <--------+ (0 or more existing children) | 2040 | | // ^ | 2041 | | // | | 2042 | | // New branch node +-+ | 2043 | | // +-+ <-------+ | 2044 | | // ^ | | 2045 | | // | | | 2046 | | // +-+ +-+ | 2047 | | // `existing_node_index` +-+ +-+ New storage node | 2048 | | // ^ | 2049 | | // | | 2050 | | // | 2051 | | // (0 or more existing children) | 2052 | | // | 2053 | | // | 2054 | | // | 2055 | | // If `future_parent` is `None`: | 2056 | | // | 2057 | | // | 2058 | | // New branch node +-+ | 2059 | | // (becomes root) +-+ <-------+ | 2060 | | // ^ | | 2061 | | // | | | 2062 | | // `existing_node_index` +-+ +-+ | 2063 | | // (current root) +-+ +-+ New storage node | 2064 | | // ^ | 2065 | | // | | 2066 | | // | 2067 | | // (0 or more existing children) | 2068 | | // | 2069 | | // | 2070 | | | 2071 | | // Find the common ancestor between `new_node_partial_key` and `existing_node_partial_key`. | 2072 | 145 | let branch_partial_key_len = { | 2073 | 145 | debug_assert_ne!(new_node_partial_key, &**existing_node_partial_key); | 2074 | 145 | let mut len = 0; | 2075 | 145 | let mut k1 = new_node_partial_key.iter(); | 2076 | 145 | let mut k2 = existing_node_partial_key.iter(); | 2077 | | // Since `new_node_partial_key` is different from `existing_node_partial_key`, we know | 2078 | | // that `k1.next()` and `k2.next()` won't both be `None`. | 2079 | 149 | while k1.next() == k2.next() { | 2080 | 4 | len += 1; | 2081 | 4 | } | 2082 | 145 | debug_assert!(len < new_node_partial_key.len()); | 2083 | 145 | debug_assert!(len < existing_node_partial_key.len()); | 2084 | 145 | len | 2085 | | }; | 2086 | | | 2087 | | // Table of children for the new branch node, not including the new storage node. | 2088 | | // It therefore contains only one entry: `existing_node_index`. | 2089 | 145 | let branch_children = { | 2090 | 145 | let mut branch_children = [None; 16]; | 2091 | 145 | let existing_node_new_child_index = existing_node_partial_key[branch_partial_key_len]; | 2092 | 145 | debug_assert_ne!( | 2093 | | existing_node_new_child_index, | 2094 | 145 | new_node_partial_key[branch_partial_key_len] | 2095 | | ); | 2096 | 145 | branch_children[usize::from(u8::from(existing_node_new_child_index))] = | 2097 | 145 | Some(existing_node_index); | 2098 | 145 | branch_children | 2099 | 145 | }; | 2100 | 145 | | 2101 | 145 | // Success! | 2102 | 145 | PrepareInsert::Two(PrepareInsertTwo { | 2103 | 145 | trie: self.trie, | 2104 | 145 | | 2105 | 145 | storage_child_index: new_node_partial_key[branch_partial_key_len], | 2106 | 145 | storage_partial_key: new_node_partial_key[branch_partial_key_len + 1..].to_owned(), | 2107 | | | 2108 | 145 | branch_parent: if let Some((future_parent_index, future_parent_key_len)) = future_parent | 2109 | | { | 2110 | 145 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2111 | 145 | Some((future_parent_index, new_child_index)) | 2112 | | } else { | 2113 | 0 | None | 2114 | | }, | 2115 | 145 | branch_partial_key: new_node_partial_key[..branch_partial_key_len].to_owned(), | 2116 | 145 | branch_children, | 2117 | | }) | 2118 | 5.23k | } |
_RNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_6VacantuINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB7_6nibble6NibbleEE20insert_storage_valueB9_ Line | Count | Source | 1889 | 746k | pub fn insert_storage_value(mut self) -> PrepareInsert<'a, TUd> { | 1890 | | // Retrieve what will be the parent after we insert the new node, not taking branching | 1891 | | // into account yet. | 1892 | | // If `Some`, contains its index and number of nibbles in its key. | 1893 | 746k | let future_parent740k = match (self.closest_ancestor, self.trie.root_index) { | 1894 | 0 | (Some(_), None) => unreachable!(), | 1895 | 731k | (Some(ancestor), Some(_)) => { | 1896 | 731k | // TODO: could be optimized by passing in the Vacant the key remainder | 1897 | 731k | let key_len = self.trie.node_full_key(ancestor).count(); | 1898 | 731k | debug_assert!(self.key.clone().count() > key_len); | 1899 | 731k | Some((ancestor, key_len)) | 1900 | | } | 1901 | 8.69k | (None, Some(_)) => None, | 1902 | | (None, None) => { | 1903 | | // Situation where the trie is empty. This is kind of a special case that we | 1904 | | // handle by returning early. | 1905 | 6.21k | return PrepareInsert::One(PrepareInsertOne { | 1906 | 6.21k | trie: self.trie, | 1907 | 6.21k | parent: None, | 1908 | 6.21k | partial_key: self.key.collect(), | 1909 | 6.21k | children: [None; 16], | 1910 | 6.21k | }); | 1911 | | } | 1912 | | }; | 1913 | | | 1914 | | // Get the existing child of `future_parent` that points towards the newly-inserted node, | 1915 | | // or a successful early-return if none. | 1916 | 253k | let existing_node_index = | 1917 | 740k | if let Some((future_parent_index, future_parent_key_len731k )) = future_parent { | 1918 | 731k | let new_child_index = self.key.clone().nth(future_parent_key_len).unwrap(); | 1919 | 731k | let future_parent = self.trie.nodes.get(future_parent_index).unwrap(); | 1920 | 731k | match future_parent.children[usize::from(u8::from(new_child_index))] { | 1921 | 244k | Some(i) => { | 1922 | 244k | debug_assert_eq!( | 1923 | 244k | self.trie.nodes.get(i).unwrap().parent.unwrap().0, | 1924 | | future_parent_index | 1925 | | ); | 1926 | 244k | i | 1927 | | } | 1928 | | None => { | 1929 | | // There is an empty slot in `future_parent` for our new node. | 1930 | | // | 1931 | | // | 1932 | | // `future_parent` | 1933 | | // +-+ | 1934 | | // +-> +-+ <---------+ | 1935 | | // | <----+ | | 1936 | | // | ^ | | | 1937 | | // +-+ | | | | 1938 | | // New node +-+ +-+-+ +-+ +-+ 0 or more existing children | 1939 | | // +-+ +-+ +-+ | 1940 | | // | 1941 | | // | 1942 | 487k | return PrepareInsert::One(PrepareInsertOne { | 1943 | 487k | trie: self.trie, | 1944 | 487k | parent: Some((future_parent_index, new_child_index)), | 1945 | 487k | partial_key: self.key.skip(future_parent_key_len + 1).collect(), | 1946 | 487k | children: [None; 16], | 1947 | 487k | }); | 1948 | | } | 1949 | | } | 1950 | | } else { | 1951 | 8.69k | self.trie.root_index.unwrap() | 1952 | | }; | 1953 | | | 1954 | | // `existing_node_idx` and the new node are known to either have the same parent and the | 1955 | | // same child index, or to both have no parent. Now let's compare their partial key. | 1956 | 253k | let existing_node_partial_key = &self | 1957 | 253k | .trie | 1958 | 253k | .nodes | 1959 | 253k | .get(existing_node_index) | 1960 | 253k | .unwrap() | 1961 | 253k | .partial_key; | 1962 | 253k | let new_node_partial_key = self | 1963 | 253k | .key | 1964 | 253k | .clone() | 1965 | 253k | .skip(future_parent.map_or(0, |(_, n)| n + 1)) | 1966 | 253k | .collect::<Vec<_>>(); | 1967 | 253k | debug_assert_ne!(*existing_node_partial_key, new_node_partial_key); | 1968 | 253k | debug_assert!(!new_node_partial_key.starts_with(existing_node_partial_key)); | 1969 | | | 1970 | | // If `existing_node_partial_key` starts with `new_node_partial_key`, then the new node | 1971 | | // will be inserted in-between the parent and the existing node. | 1972 | 253k | if existing_node_partial_key.starts_with(&new_node_partial_key) { | 1973 | | // The new node is to be inserted in-between `future_parent` and | 1974 | | // `existing_node_index`. | 1975 | | // | 1976 | | // If `future_parent` is `Some`: | 1977 | | // | 1978 | | // | 1979 | | // +-+ | 1980 | | // `future_parent` +-+ <---------+ | 1981 | | // ^ | | 1982 | | // | + | 1983 | | // +-+ (0 or more existing children) | 1984 | | // New node +-+ | 1985 | | // ^ | 1986 | | // | | 1987 | | // +-+ | 1988 | | // `existing_node_index` +-+ | 1989 | | // ^ | 1990 | | // | | 1991 | | // + | 1992 | | // (0 or more existing children) | 1993 | | // | 1994 | | // | 1995 | | // | 1996 | | // If `future_parent` is `None`: | 1997 | | // | 1998 | | // | 1999 | | // New node +-+ | 2000 | | // (becomes the root) +-+ | 2001 | | // ^ | 2002 | | // | | 2003 | | // `existing_node_index` +-+ | 2004 | | // (current root) +-+ | 2005 | | // ^ | 2006 | | // | | 2007 | | // + | 2008 | | // (0 or more existing children) | 2009 | | // | 2010 | | | 2011 | 87.2k | let mut new_node_children = [None; 16]; | 2012 | 87.2k | let existing_node_new_child_index = | 2013 | 87.2k | existing_node_partial_key[new_node_partial_key.len()]; | 2014 | 87.2k | new_node_children[usize::from(u8::from(existing_node_new_child_index))] = | 2015 | 87.2k | Some(existing_node_index); | 2016 | 87.2k | | 2017 | 87.2k | return PrepareInsert::One(PrepareInsertOne { | 2018 | 87.2k | trie: self.trie, | 2019 | 87.2k | parent: if let Some((future_parent_index, future_parent_key_len86.9k )) = future_parent { | 2020 | 86.9k | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2021 | 86.9k | Some((future_parent_index, new_child_index)) | 2022 | | } else { | 2023 | 362 | None | 2024 | | }, | 2025 | 87.2k | partial_key: new_node_partial_key, | 2026 | 87.2k | children: new_node_children, | 2027 | | }); | 2028 | 165k | } | 2029 | | | 2030 | | // If we reach here, we know that we will need to create a new branch node in addition to | 2031 | | // the new storage node. | 2032 | | // | 2033 | | // If `future_parent` is `Some`: | 2034 | | // | 2035 | | // | 2036 | | // `future_parent` | 2037 | | // | 2038 | | // +-+ | 2039 | | // +-+ <--------+ (0 or more existing children) | 2040 | | // ^ | 2041 | | // | | 2042 | | // New branch node +-+ | 2043 | | // +-+ <-------+ | 2044 | | // ^ | | 2045 | | // | | | 2046 | | // +-+ +-+ | 2047 | | // `existing_node_index` +-+ +-+ New storage node | 2048 | | // ^ | 2049 | | // | | 2050 | | // | 2051 | | // (0 or more existing children) | 2052 | | // | 2053 | | // | 2054 | | // | 2055 | | // If `future_parent` is `None`: | 2056 | | // | 2057 | | // | 2058 | | // New branch node +-+ | 2059 | | // (becomes root) +-+ <-------+ | 2060 | | // ^ | | 2061 | | // | | | 2062 | | // `existing_node_index` +-+ +-+ | 2063 | | // (current root) +-+ +-+ New storage node | 2064 | | // ^ | 2065 | | // | | 2066 | | // | 2067 | | // (0 or more existing children) | 2068 | | // | 2069 | | // | 2070 | | | 2071 | | // Find the common ancestor between `new_node_partial_key` and `existing_node_partial_key`. | 2072 | 165k | let branch_partial_key_len = { | 2073 | 165k | debug_assert_ne!(new_node_partial_key, &**existing_node_partial_key); | 2074 | 165k | let mut len = 0; | 2075 | 165k | let mut k1 = new_node_partial_key.iter(); | 2076 | 165k | let mut k2 = existing_node_partial_key.iter(); | 2077 | | // Since `new_node_partial_key` is different from `existing_node_partial_key`, we know | 2078 | | // that `k1.next()` and `k2.next()` won't both be `None`. | 2079 | 283k | while k1.next() == k2.next() { | 2080 | 117k | len += 1; | 2081 | 117k | } | 2082 | 165k | debug_assert!(len < new_node_partial_key.len()); | 2083 | 165k | debug_assert!(len < existing_node_partial_key.len()); | 2084 | 165k | len | 2085 | | }; | 2086 | | | 2087 | | // Table of children for the new branch node, not including the new storage node. | 2088 | | // It therefore contains only one entry: `existing_node_index`. | 2089 | 165k | let branch_children = { | 2090 | 165k | let mut branch_children = [None; 16]; | 2091 | 165k | let existing_node_new_child_index = existing_node_partial_key[branch_partial_key_len]; | 2092 | 165k | debug_assert_ne!( | 2093 | | existing_node_new_child_index, | 2094 | 165k | new_node_partial_key[branch_partial_key_len] | 2095 | | ); | 2096 | 165k | branch_children[usize::from(u8::from(existing_node_new_child_index))] = | 2097 | 165k | Some(existing_node_index); | 2098 | 165k | branch_children | 2099 | 165k | }; | 2100 | 165k | | 2101 | 165k | // Success! | 2102 | 165k | PrepareInsert::Two(PrepareInsertTwo { | 2103 | 165k | trie: self.trie, | 2104 | 165k | | 2105 | 165k | storage_child_index: new_node_partial_key[branch_partial_key_len], | 2106 | 165k | storage_partial_key: new_node_partial_key[branch_partial_key_len + 1..].to_owned(), | 2107 | | | 2108 | 165k | branch_parent: if let Some((future_parent_index, future_parent_key_len157k )) = future_parent | 2109 | | { | 2110 | 157k | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2111 | 157k | Some((future_parent_index, new_child_index)) | 2112 | | } else { | 2113 | 8.33k | None | 2114 | | }, | 2115 | 165k | branch_partial_key: new_node_partial_key[..branch_partial_key_len].to_owned(), | 2116 | 165k | branch_children, | 2117 | | }) | 2118 | 746k | } |
_RNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_6VacantuINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6cloned6ClonedINtNtNtB1c_5slice4iter4IterNtNtB7_6nibble6NibbleEEE20insert_storage_valueB9_ Line | Count | Source | 1889 | 30 | pub fn insert_storage_value(mut self) -> PrepareInsert<'a, TUd> { | 1890 | | // Retrieve what will be the parent after we insert the new node, not taking branching | 1891 | | // into account yet. | 1892 | | // If `Some`, contains its index and number of nibbles in its key. | 1893 | 30 | let future_parent19 = match (self.closest_ancestor, self.trie.root_index) { | 1894 | 0 | (Some(_), None) => unreachable!(), | 1895 | 14 | (Some(ancestor), Some(_)) => { | 1896 | 14 | // TODO: could be optimized by passing in the Vacant the key remainder | 1897 | 14 | let key_len = self.trie.node_full_key(ancestor).count(); | 1898 | 14 | debug_assert!(self.key.clone().count() > key_len); | 1899 | 14 | Some((ancestor, key_len)) | 1900 | | } | 1901 | 5 | (None, Some(_)) => None, | 1902 | | (None, None) => { | 1903 | | // Situation where the trie is empty. This is kind of a special case that we | 1904 | | // handle by returning early. | 1905 | 11 | return PrepareInsert::One(PrepareInsertOne { | 1906 | 11 | trie: self.trie, | 1907 | 11 | parent: None, | 1908 | 11 | partial_key: self.key.collect(), | 1909 | 11 | children: [None; 16], | 1910 | 11 | }); | 1911 | | } | 1912 | | }; | 1913 | | | 1914 | | // Get the existing child of `future_parent` that points towards the newly-inserted node, | 1915 | | // or a successful early-return if none. | 1916 | 9 | let existing_node_index = | 1917 | 19 | if let Some((future_parent_index, future_parent_key_len14 )) = future_parent { | 1918 | 14 | let new_child_index = self.key.clone().nth(future_parent_key_len).unwrap(); | 1919 | 14 | let future_parent = self.trie.nodes.get(future_parent_index).unwrap(); | 1920 | 14 | match future_parent.children[usize::from(u8::from(new_child_index))] { | 1921 | 4 | Some(i) => { | 1922 | 4 | debug_assert_eq!( | 1923 | 4 | self.trie.nodes.get(i).unwrap().parent.unwrap().0, | 1924 | | future_parent_index | 1925 | | ); | 1926 | 4 | i | 1927 | | } | 1928 | | None => { | 1929 | | // There is an empty slot in `future_parent` for our new node. | 1930 | | // | 1931 | | // | 1932 | | // `future_parent` | 1933 | | // +-+ | 1934 | | // +-> +-+ <---------+ | 1935 | | // | <----+ | | 1936 | | // | ^ | | | 1937 | | // +-+ | | | | 1938 | | // New node +-+ +-+-+ +-+ +-+ 0 or more existing children | 1939 | | // +-+ +-+ +-+ | 1940 | | // | 1941 | | // | 1942 | 10 | return PrepareInsert::One(PrepareInsertOne { | 1943 | 10 | trie: self.trie, | 1944 | 10 | parent: Some((future_parent_index, new_child_index)), | 1945 | 10 | partial_key: self.key.skip(future_parent_key_len + 1).collect(), | 1946 | 10 | children: [None; 16], | 1947 | 10 | }); | 1948 | | } | 1949 | | } | 1950 | | } else { | 1951 | 5 | self.trie.root_index.unwrap() | 1952 | | }; | 1953 | | | 1954 | | // `existing_node_idx` and the new node are known to either have the same parent and the | 1955 | | // same child index, or to both have no parent. Now let's compare their partial key. | 1956 | 9 | let existing_node_partial_key = &self | 1957 | 9 | .trie | 1958 | 9 | .nodes | 1959 | 9 | .get(existing_node_index) | 1960 | 9 | .unwrap() | 1961 | 9 | .partial_key; | 1962 | 9 | let new_node_partial_key = self | 1963 | 9 | .key | 1964 | 9 | .clone() | 1965 | 9 | .skip(future_parent.map_or(0, |(_, n)| n + 1)) | 1966 | 9 | .collect::<Vec<_>>(); | 1967 | 9 | debug_assert_ne!(*existing_node_partial_key, new_node_partial_key); | 1968 | 9 | debug_assert!(!new_node_partial_key.starts_with(existing_node_partial_key)); | 1969 | | | 1970 | | // If `existing_node_partial_key` starts with `new_node_partial_key`, then the new node | 1971 | | // will be inserted in-between the parent and the existing node. | 1972 | 9 | if existing_node_partial_key.starts_with(&new_node_partial_key) { | 1973 | | // The new node is to be inserted in-between `future_parent` and | 1974 | | // `existing_node_index`. | 1975 | | // | 1976 | | // If `future_parent` is `Some`: | 1977 | | // | 1978 | | // | 1979 | | // +-+ | 1980 | | // `future_parent` +-+ <---------+ | 1981 | | // ^ | | 1982 | | // | + | 1983 | | // +-+ (0 or more existing children) | 1984 | | // New node +-+ | 1985 | | // ^ | 1986 | | // | | 1987 | | // +-+ | 1988 | | // `existing_node_index` +-+ | 1989 | | // ^ | 1990 | | // | | 1991 | | // + | 1992 | | // (0 or more existing children) | 1993 | | // | 1994 | | // | 1995 | | // | 1996 | | // If `future_parent` is `None`: | 1997 | | // | 1998 | | // | 1999 | | // New node +-+ | 2000 | | // (becomes the root) +-+ | 2001 | | // ^ | 2002 | | // | | 2003 | | // `existing_node_index` +-+ | 2004 | | // (current root) +-+ | 2005 | | // ^ | 2006 | | // | | 2007 | | // + | 2008 | | // (0 or more existing children) | 2009 | | // | 2010 | | | 2011 | 4 | let mut new_node_children = [None; 16]; | 2012 | 4 | let existing_node_new_child_index = | 2013 | 4 | existing_node_partial_key[new_node_partial_key.len()]; | 2014 | 4 | new_node_children[usize::from(u8::from(existing_node_new_child_index))] = | 2015 | 4 | Some(existing_node_index); | 2016 | 4 | | 2017 | 4 | return PrepareInsert::One(PrepareInsertOne { | 2018 | 4 | trie: self.trie, | 2019 | 4 | parent: if let Some((future_parent_index, future_parent_key_len1 )) = future_parent { | 2020 | 1 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2021 | 1 | Some((future_parent_index, new_child_index)) | 2022 | | } else { | 2023 | 3 | None | 2024 | | }, | 2025 | 4 | partial_key: new_node_partial_key, | 2026 | 4 | children: new_node_children, | 2027 | | }); | 2028 | 5 | } | 2029 | | | 2030 | | // If we reach here, we know that we will need to create a new branch node in addition to | 2031 | | // the new storage node. | 2032 | | // | 2033 | | // If `future_parent` is `Some`: | 2034 | | // | 2035 | | // | 2036 | | // `future_parent` | 2037 | | // | 2038 | | // +-+ | 2039 | | // +-+ <--------+ (0 or more existing children) | 2040 | | // ^ | 2041 | | // | | 2042 | | // New branch node +-+ | 2043 | | // +-+ <-------+ | 2044 | | // ^ | | 2045 | | // | | | 2046 | | // +-+ +-+ | 2047 | | // `existing_node_index` +-+ +-+ New storage node | 2048 | | // ^ | 2049 | | // | | 2050 | | // | 2051 | | // (0 or more existing children) | 2052 | | // | 2053 | | // | 2054 | | // | 2055 | | // If `future_parent` is `None`: | 2056 | | // | 2057 | | // | 2058 | | // New branch node +-+ | 2059 | | // (becomes root) +-+ <-------+ | 2060 | | // ^ | | 2061 | | // | | | 2062 | | // `existing_node_index` +-+ +-+ | 2063 | | // (current root) +-+ +-+ New storage node | 2064 | | // ^ | 2065 | | // | | 2066 | | // | 2067 | | // (0 or more existing children) | 2068 | | // | 2069 | | // | 2070 | | | 2071 | | // Find the common ancestor between `new_node_partial_key` and `existing_node_partial_key`. | 2072 | 5 | let branch_partial_key_len = { | 2073 | 5 | debug_assert_ne!(new_node_partial_key, &**existing_node_partial_key); | 2074 | 5 | let mut len = 0; | 2075 | 5 | let mut k1 = new_node_partial_key.iter(); | 2076 | 5 | let mut k2 = existing_node_partial_key.iter(); | 2077 | | // Since `new_node_partial_key` is different from `existing_node_partial_key`, we know | 2078 | | // that `k1.next()` and `k2.next()` won't both be `None`. | 2079 | 11 | while k1.next() == k2.next() { | 2080 | 6 | len += 1; | 2081 | 6 | } | 2082 | 5 | debug_assert!(len < new_node_partial_key.len()); | 2083 | 5 | debug_assert!(len < existing_node_partial_key.len()); | 2084 | 5 | len | 2085 | | }; | 2086 | | | 2087 | | // Table of children for the new branch node, not including the new storage node. | 2088 | | // It therefore contains only one entry: `existing_node_index`. | 2089 | 5 | let branch_children = { | 2090 | 5 | let mut branch_children = [None; 16]; | 2091 | 5 | let existing_node_new_child_index = existing_node_partial_key[branch_partial_key_len]; | 2092 | 5 | debug_assert_ne!( | 2093 | | existing_node_new_child_index, | 2094 | 5 | new_node_partial_key[branch_partial_key_len] | 2095 | | ); | 2096 | 5 | branch_children[usize::from(u8::from(existing_node_new_child_index))] = | 2097 | 5 | Some(existing_node_index); | 2098 | 5 | branch_children | 2099 | 5 | }; | 2100 | 5 | | 2101 | 5 | // Success! | 2102 | 5 | PrepareInsert::Two(PrepareInsertTwo { | 2103 | 5 | trie: self.trie, | 2104 | 5 | | 2105 | 5 | storage_child_index: new_node_partial_key[branch_partial_key_len], | 2106 | 5 | storage_partial_key: new_node_partial_key[branch_partial_key_len + 1..].to_owned(), | 2107 | | | 2108 | 5 | branch_parent: if let Some((future_parent_index, future_parent_key_len3 )) = future_parent | 2109 | | { | 2110 | 3 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2111 | 3 | Some((future_parent_index, new_child_index)) | 2112 | | } else { | 2113 | 2 | None | 2114 | | }, | 2115 | 5 | branch_partial_key: new_node_partial_key[..branch_partial_key_len].to_owned(), | 2116 | 5 | branch_children, | 2117 | | }) | 2118 | 30 | } |
_RNvMs7_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_6VacantuINtNtNtNtCsaYZPK01V26L_4core4iter8adapters6copied6CopiedINtNtNtB1c_5slice4iter4IterNtNtB7_6nibble6NibbleEEE20insert_storage_valueB9_ Line | Count | Source | 1889 | 245k | pub fn insert_storage_value(mut self) -> PrepareInsert<'a, TUd> { | 1890 | | // Retrieve what will be the parent after we insert the new node, not taking branching | 1891 | | // into account yet. | 1892 | | // If `Some`, contains its index and number of nibbles in its key. | 1893 | 245k | let future_parent241k = match (self.closest_ancestor, self.trie.root_index) { | 1894 | 0 | (Some(_), None) => unreachable!(), | 1895 | 240k | (Some(ancestor), Some(_)) => { | 1896 | 240k | // TODO: could be optimized by passing in the Vacant the key remainder | 1897 | 240k | let key_len = self.trie.node_full_key(ancestor).count(); | 1898 | 240k | debug_assert!(self.key.clone().count() > key_len); | 1899 | 240k | Some((ancestor, key_len)) | 1900 | | } | 1901 | 610 | (None, Some(_)) => None, | 1902 | | (None, None) => { | 1903 | | // Situation where the trie is empty. This is kind of a special case that we | 1904 | | // handle by returning early. | 1905 | 4.09k | return PrepareInsert::One(PrepareInsertOne { | 1906 | 4.09k | trie: self.trie, | 1907 | 4.09k | parent: None, | 1908 | 4.09k | partial_key: self.key.collect(), | 1909 | 4.09k | children: [None; 16], | 1910 | 4.09k | }); | 1911 | | } | 1912 | | }; | 1913 | | | 1914 | | // Get the existing child of `future_parent` that points towards the newly-inserted node, | 1915 | | // or a successful early-return if none. | 1916 | 13.5k | let existing_node_index = | 1917 | 241k | if let Some((future_parent_index, future_parent_key_len240k )) = future_parent { | 1918 | 240k | let new_child_index = self.key.clone().nth(future_parent_key_len).unwrap(); | 1919 | 240k | let future_parent = self.trie.nodes.get(future_parent_index).unwrap(); | 1920 | 240k | match future_parent.children[usize::from(u8::from(new_child_index))] { | 1921 | 12.9k | Some(i) => { | 1922 | 12.9k | debug_assert_eq!( | 1923 | 12.9k | self.trie.nodes.get(i).unwrap().parent.unwrap().0, | 1924 | | future_parent_index | 1925 | | ); | 1926 | 12.9k | i | 1927 | | } | 1928 | | None => { | 1929 | | // There is an empty slot in `future_parent` for our new node. | 1930 | | // | 1931 | | // | 1932 | | // `future_parent` | 1933 | | // +-+ | 1934 | | // +-> +-+ <---------+ | 1935 | | // | <----+ | | 1936 | | // | ^ | | | 1937 | | // +-+ | | | | 1938 | | // New node +-+ +-+-+ +-+ +-+ 0 or more existing children | 1939 | | // +-+ +-+ +-+ | 1940 | | // | 1941 | | // | 1942 | 227k | return PrepareInsert::One(PrepareInsertOne { | 1943 | 227k | trie: self.trie, | 1944 | 227k | parent: Some((future_parent_index, new_child_index)), | 1945 | 227k | partial_key: self.key.skip(future_parent_key_len + 1).collect(), | 1946 | 227k | children: [None; 16], | 1947 | 227k | }); | 1948 | | } | 1949 | | } | 1950 | | } else { | 1951 | 610 | self.trie.root_index.unwrap() | 1952 | | }; | 1953 | | | 1954 | | // `existing_node_idx` and the new node are known to either have the same parent and the | 1955 | | // same child index, or to both have no parent. Now let's compare their partial key. | 1956 | 13.5k | let existing_node_partial_key = &self | 1957 | 13.5k | .trie | 1958 | 13.5k | .nodes | 1959 | 13.5k | .get(existing_node_index) | 1960 | 13.5k | .unwrap() | 1961 | 13.5k | .partial_key; | 1962 | 13.5k | let new_node_partial_key = self | 1963 | 13.5k | .key | 1964 | 13.5k | .clone() | 1965 | 13.5k | .skip(future_parent.map_or(0, |(_, n)| n + 1)) | 1966 | 13.5k | .collect::<Vec<_>>(); | 1967 | 13.5k | debug_assert_ne!(*existing_node_partial_key, new_node_partial_key); | 1968 | 13.5k | debug_assert!(!new_node_partial_key.starts_with(existing_node_partial_key)); | 1969 | | | 1970 | | // If `existing_node_partial_key` starts with `new_node_partial_key`, then the new node | 1971 | | // will be inserted in-between the parent and the existing node. | 1972 | 13.5k | if existing_node_partial_key.starts_with(&new_node_partial_key) { | 1973 | | // The new node is to be inserted in-between `future_parent` and | 1974 | | // `existing_node_index`. | 1975 | | // | 1976 | | // If `future_parent` is `Some`: | 1977 | | // | 1978 | | // | 1979 | | // +-+ | 1980 | | // `future_parent` +-+ <---------+ | 1981 | | // ^ | | 1982 | | // | + | 1983 | | // +-+ (0 or more existing children) | 1984 | | // New node +-+ | 1985 | | // ^ | 1986 | | // | | 1987 | | // +-+ | 1988 | | // `existing_node_index` +-+ | 1989 | | // ^ | 1990 | | // | | 1991 | | // + | 1992 | | // (0 or more existing children) | 1993 | | // | 1994 | | // | 1995 | | // | 1996 | | // If `future_parent` is `None`: | 1997 | | // | 1998 | | // | 1999 | | // New node +-+ | 2000 | | // (becomes the root) +-+ | 2001 | | // ^ | 2002 | | // | | 2003 | | // `existing_node_index` +-+ | 2004 | | // (current root) +-+ | 2005 | | // ^ | 2006 | | // | | 2007 | | // + | 2008 | | // (0 or more existing children) | 2009 | | // | 2010 | | | 2011 | 0 | let mut new_node_children = [None; 16]; | 2012 | 0 | let existing_node_new_child_index = | 2013 | 0 | existing_node_partial_key[new_node_partial_key.len()]; | 2014 | 0 | new_node_children[usize::from(u8::from(existing_node_new_child_index))] = | 2015 | 0 | Some(existing_node_index); | 2016 | 0 |
| 2017 | 0 | return PrepareInsert::One(PrepareInsertOne { | 2018 | 0 | trie: self.trie, | 2019 | 0 | parent: if let Some((future_parent_index, future_parent_key_len)) = future_parent { | 2020 | 0 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2021 | 0 | Some((future_parent_index, new_child_index)) | 2022 | | } else { | 2023 | 0 | None | 2024 | | }, | 2025 | 0 | partial_key: new_node_partial_key, | 2026 | 0 | children: new_node_children, | 2027 | | }); | 2028 | 13.5k | } | 2029 | | | 2030 | | // If we reach here, we know that we will need to create a new branch node in addition to | 2031 | | // the new storage node. | 2032 | | // | 2033 | | // If `future_parent` is `Some`: | 2034 | | // | 2035 | | // | 2036 | | // `future_parent` | 2037 | | // | 2038 | | // +-+ | 2039 | | // +-+ <--------+ (0 or more existing children) | 2040 | | // ^ | 2041 | | // | | 2042 | | // New branch node +-+ | 2043 | | // +-+ <-------+ | 2044 | | // ^ | | 2045 | | // | | | 2046 | | // +-+ +-+ | 2047 | | // `existing_node_index` +-+ +-+ New storage node | 2048 | | // ^ | 2049 | | // | | 2050 | | // | 2051 | | // (0 or more existing children) | 2052 | | // | 2053 | | // | 2054 | | // | 2055 | | // If `future_parent` is `None`: | 2056 | | // | 2057 | | // | 2058 | | // New branch node +-+ | 2059 | | // (becomes root) +-+ <-------+ | 2060 | | // ^ | | 2061 | | // | | | 2062 | | // `existing_node_index` +-+ +-+ | 2063 | | // (current root) +-+ +-+ New storage node | 2064 | | // ^ | 2065 | | // | | 2066 | | // | 2067 | | // (0 or more existing children) | 2068 | | // | 2069 | | // | 2070 | | | 2071 | | // Find the common ancestor between `new_node_partial_key` and `existing_node_partial_key`. | 2072 | 13.5k | let branch_partial_key_len = { | 2073 | 13.5k | debug_assert_ne!(new_node_partial_key, &**existing_node_partial_key); | 2074 | 13.5k | let mut len = 0; | 2075 | 13.5k | let mut k1 = new_node_partial_key.iter(); | 2076 | 13.5k | let mut k2 = existing_node_partial_key.iter(); | 2077 | | // Since `new_node_partial_key` is different from `existing_node_partial_key`, we know | 2078 | | // that `k1.next()` and `k2.next()` won't both be `None`. | 2079 | 13.8k | while k1.next() == k2.next() { | 2080 | 233 | len += 1; | 2081 | 233 | } | 2082 | 13.5k | debug_assert!(len < new_node_partial_key.len()); | 2083 | 13.5k | debug_assert!(len < existing_node_partial_key.len()); | 2084 | 13.5k | len | 2085 | | }; | 2086 | | | 2087 | | // Table of children for the new branch node, not including the new storage node. | 2088 | | // It therefore contains only one entry: `existing_node_index`. | 2089 | 13.5k | let branch_children = { | 2090 | 13.5k | let mut branch_children = [None; 16]; | 2091 | 13.5k | let existing_node_new_child_index = existing_node_partial_key[branch_partial_key_len]; | 2092 | 13.5k | debug_assert_ne!( | 2093 | | existing_node_new_child_index, | 2094 | 13.5k | new_node_partial_key[branch_partial_key_len] | 2095 | | ); | 2096 | 13.5k | branch_children[usize::from(u8::from(existing_node_new_child_index))] = | 2097 | 13.5k | Some(existing_node_index); | 2098 | 13.5k | branch_children | 2099 | 13.5k | }; | 2100 | 13.5k | | 2101 | 13.5k | // Success! | 2102 | 13.5k | PrepareInsert::Two(PrepareInsertTwo { | 2103 | 13.5k | trie: self.trie, | 2104 | 13.5k | | 2105 | 13.5k | storage_child_index: new_node_partial_key[branch_partial_key_len], | 2106 | 13.5k | storage_partial_key: new_node_partial_key[branch_partial_key_len + 1..].to_owned(), | 2107 | | | 2108 | 13.5k | branch_parent: if let Some((future_parent_index, future_parent_key_len12.9k )) = future_parent | 2109 | | { | 2110 | 12.9k | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2111 | 12.9k | Some((future_parent_index, new_child_index)) | 2112 | | } else { | 2113 | 610 | None | 2114 | | }, | 2115 | 13.5k | branch_partial_key: new_node_partial_key[..branch_partial_key_len].to_owned(), | 2116 | 13.5k | branch_children, | 2117 | | }) | 2118 | 245k | } |
Unexecuted instantiation: _RNvMs7_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_6VacantINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEINtNtNtNtB18_4iter8adapters6copied6CopiedINtNtNtB18_5slice4iter4IterNtNtB7_6nibble6NibbleEEE20insert_storage_valueB9_ _RNvMs7_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_6VacantTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB15_NtNtB7_9trie_node17MerkleValueOutputEEINtNtB7_6nibble14BytesToNibblesINtNtNtNtB19_4iter8adapters6copied6CopiedINtNtNtB19_5slice4iter4IterhEEEE20insert_storage_valueCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1889 | 70 | pub fn insert_storage_value(mut self) -> PrepareInsert<'a, TUd> { | 1890 | | // Retrieve what will be the parent after we insert the new node, not taking branching | 1891 | | // into account yet. | 1892 | | // If `Some`, contains its index and number of nibbles in its key. | 1893 | 70 | let future_parent68 = match (self.closest_ancestor, self.trie.root_index) { | 1894 | 0 | (Some(_), None) => unreachable!(), | 1895 | 66 | (Some(ancestor), Some(_)) => { | 1896 | 66 | // TODO: could be optimized by passing in the Vacant the key remainder | 1897 | 66 | let key_len = self.trie.node_full_key(ancestor).count(); | 1898 | 66 | debug_assert!(self.key.clone().count() > key_len); | 1899 | 66 | Some((ancestor, key_len)) | 1900 | | } | 1901 | 2 | (None, Some(_)) => None, | 1902 | | (None, None) => { | 1903 | | // Situation where the trie is empty. This is kind of a special case that we | 1904 | | // handle by returning early. | 1905 | 2 | return PrepareInsert::One(PrepareInsertOne { | 1906 | 2 | trie: self.trie, | 1907 | 2 | parent: None, | 1908 | 2 | partial_key: self.key.collect(), | 1909 | 2 | children: [None; 16], | 1910 | 2 | }); | 1911 | | } | 1912 | | }; | 1913 | | | 1914 | | // Get the existing child of `future_parent` that points towards the newly-inserted node, | 1915 | | // or a successful early-return if none. | 1916 | 26 | let existing_node_index = | 1917 | 68 | if let Some((future_parent_index, future_parent_key_len66 )) = future_parent { | 1918 | 66 | let new_child_index = self.key.clone().nth(future_parent_key_len).unwrap(); | 1919 | 66 | let future_parent = self.trie.nodes.get(future_parent_index).unwrap(); | 1920 | 66 | match future_parent.children[usize::from(u8::from(new_child_index))] { | 1921 | 24 | Some(i) => { | 1922 | 24 | debug_assert_eq!( | 1923 | 24 | self.trie.nodes.get(i).unwrap().parent.unwrap().0, | 1924 | | future_parent_index | 1925 | | ); | 1926 | 24 | i | 1927 | | } | 1928 | | None => { | 1929 | | // There is an empty slot in `future_parent` for our new node. | 1930 | | // | 1931 | | // | 1932 | | // `future_parent` | 1933 | | // +-+ | 1934 | | // +-> +-+ <---------+ | 1935 | | // | <----+ | | 1936 | | // | ^ | | | 1937 | | // +-+ | | | | 1938 | | // New node +-+ +-+-+ +-+ +-+ 0 or more existing children | 1939 | | // +-+ +-+ +-+ | 1940 | | // | 1941 | | // | 1942 | 42 | return PrepareInsert::One(PrepareInsertOne { | 1943 | 42 | trie: self.trie, | 1944 | 42 | parent: Some((future_parent_index, new_child_index)), | 1945 | 42 | partial_key: self.key.skip(future_parent_key_len + 1).collect(), | 1946 | 42 | children: [None; 16], | 1947 | 42 | }); | 1948 | | } | 1949 | | } | 1950 | | } else { | 1951 | 2 | self.trie.root_index.unwrap() | 1952 | | }; | 1953 | | | 1954 | | // `existing_node_idx` and the new node are known to either have the same parent and the | 1955 | | // same child index, or to both have no parent. Now let's compare their partial key. | 1956 | 26 | let existing_node_partial_key = &self | 1957 | 26 | .trie | 1958 | 26 | .nodes | 1959 | 26 | .get(existing_node_index) | 1960 | 26 | .unwrap() | 1961 | 26 | .partial_key; | 1962 | 26 | let new_node_partial_key = self | 1963 | 26 | .key | 1964 | 26 | .clone() | 1965 | 26 | .skip(future_parent.map_or(0, |(_, n)| n + 1)) | 1966 | 26 | .collect::<Vec<_>>(); | 1967 | 26 | debug_assert_ne!(*existing_node_partial_key, new_node_partial_key); | 1968 | 26 | debug_assert!(!new_node_partial_key.starts_with(existing_node_partial_key)); | 1969 | | | 1970 | | // If `existing_node_partial_key` starts with `new_node_partial_key`, then the new node | 1971 | | // will be inserted in-between the parent and the existing node. | 1972 | 26 | if existing_node_partial_key.starts_with(&new_node_partial_key) { | 1973 | | // The new node is to be inserted in-between `future_parent` and | 1974 | | // `existing_node_index`. | 1975 | | // | 1976 | | // If `future_parent` is `Some`: | 1977 | | // | 1978 | | // | 1979 | | // +-+ | 1980 | | // `future_parent` +-+ <---------+ | 1981 | | // ^ | | 1982 | | // | + | 1983 | | // +-+ (0 or more existing children) | 1984 | | // New node +-+ | 1985 | | // ^ | 1986 | | // | | 1987 | | // +-+ | 1988 | | // `existing_node_index` +-+ | 1989 | | // ^ | 1990 | | // | | 1991 | | // + | 1992 | | // (0 or more existing children) | 1993 | | // | 1994 | | // | 1995 | | // | 1996 | | // If `future_parent` is `None`: | 1997 | | // | 1998 | | // | 1999 | | // New node +-+ | 2000 | | // (becomes the root) +-+ | 2001 | | // ^ | 2002 | | // | | 2003 | | // `existing_node_index` +-+ | 2004 | | // (current root) +-+ | 2005 | | // ^ | 2006 | | // | | 2007 | | // + | 2008 | | // (0 or more existing children) | 2009 | | // | 2010 | | | 2011 | 0 | let mut new_node_children = [None; 16]; | 2012 | 0 | let existing_node_new_child_index = | 2013 | 0 | existing_node_partial_key[new_node_partial_key.len()]; | 2014 | 0 | new_node_children[usize::from(u8::from(existing_node_new_child_index))] = | 2015 | 0 | Some(existing_node_index); | 2016 | 0 |
| 2017 | 0 | return PrepareInsert::One(PrepareInsertOne { | 2018 | 0 | trie: self.trie, | 2019 | 0 | parent: if let Some((future_parent_index, future_parent_key_len)) = future_parent { | 2020 | 0 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2021 | 0 | Some((future_parent_index, new_child_index)) | 2022 | | } else { | 2023 | 0 | None | 2024 | | }, | 2025 | 0 | partial_key: new_node_partial_key, | 2026 | 0 | children: new_node_children, | 2027 | | }); | 2028 | 26 | } | 2029 | | | 2030 | | // If we reach here, we know that we will need to create a new branch node in addition to | 2031 | | // the new storage node. | 2032 | | // | 2033 | | // If `future_parent` is `Some`: | 2034 | | // | 2035 | | // | 2036 | | // `future_parent` | 2037 | | // | 2038 | | // +-+ | 2039 | | // +-+ <--------+ (0 or more existing children) | 2040 | | // ^ | 2041 | | // | | 2042 | | // New branch node +-+ | 2043 | | // +-+ <-------+ | 2044 | | // ^ | | 2045 | | // | | | 2046 | | // +-+ +-+ | 2047 | | // `existing_node_index` +-+ +-+ New storage node | 2048 | | // ^ | 2049 | | // | | 2050 | | // | 2051 | | // (0 or more existing children) | 2052 | | // | 2053 | | // | 2054 | | // | 2055 | | // If `future_parent` is `None`: | 2056 | | // | 2057 | | // | 2058 | | // New branch node +-+ | 2059 | | // (becomes root) +-+ <-------+ | 2060 | | // ^ | | 2061 | | // | | | 2062 | | // `existing_node_index` +-+ +-+ | 2063 | | // (current root) +-+ +-+ New storage node | 2064 | | // ^ | 2065 | | // | | 2066 | | // | 2067 | | // (0 or more existing children) | 2068 | | // | 2069 | | // | 2070 | | | 2071 | | // Find the common ancestor between `new_node_partial_key` and `existing_node_partial_key`. | 2072 | 26 | let branch_partial_key_len = { | 2073 | 26 | debug_assert_ne!(new_node_partial_key, &**existing_node_partial_key); | 2074 | 26 | let mut len = 0; | 2075 | 26 | let mut k1 = new_node_partial_key.iter(); | 2076 | 26 | let mut k2 = existing_node_partial_key.iter(); | 2077 | | // Since `new_node_partial_key` is different from `existing_node_partial_key`, we know | 2078 | | // that `k1.next()` and `k2.next()` won't both be `None`. | 2079 | 398 | while k1.next() == k2.next() { | 2080 | 372 | len += 1; | 2081 | 372 | } | 2082 | 26 | debug_assert!(len < new_node_partial_key.len()); | 2083 | 26 | debug_assert!(len < existing_node_partial_key.len()); | 2084 | 26 | len | 2085 | | }; | 2086 | | | 2087 | | // Table of children for the new branch node, not including the new storage node. | 2088 | | // It therefore contains only one entry: `existing_node_index`. | 2089 | 26 | let branch_children = { | 2090 | 26 | let mut branch_children = [None; 16]; | 2091 | 26 | let existing_node_new_child_index = existing_node_partial_key[branch_partial_key_len]; | 2092 | 26 | debug_assert_ne!( | 2093 | | existing_node_new_child_index, | 2094 | 26 | new_node_partial_key[branch_partial_key_len] | 2095 | | ); | 2096 | 26 | branch_children[usize::from(u8::from(existing_node_new_child_index))] = | 2097 | 26 | Some(existing_node_index); | 2098 | 26 | branch_children | 2099 | 26 | }; | 2100 | 26 | | 2101 | 26 | // Success! | 2102 | 26 | PrepareInsert::Two(PrepareInsertTwo { | 2103 | 26 | trie: self.trie, | 2104 | 26 | | 2105 | 26 | storage_child_index: new_node_partial_key[branch_partial_key_len], | 2106 | 26 | storage_partial_key: new_node_partial_key[branch_partial_key_len + 1..].to_owned(), | 2107 | | | 2108 | 26 | branch_parent: if let Some((future_parent_index, future_parent_key_len24 )) = future_parent | 2109 | | { | 2110 | 24 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2111 | 24 | Some((future_parent_index, new_child_index)) | 2112 | | } else { | 2113 | 2 | None | 2114 | | }, | 2115 | 26 | branch_partial_key: new_node_partial_key[..branch_partial_key_len].to_owned(), | 2116 | 26 | branch_children, | 2117 | | }) | 2118 | 70 | } |
Unexecuted instantiation: _RNvMs7_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_6VacantTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB15_NtNtB7_9trie_node17MerkleValueOutputEEINtNtB7_6nibble14BytesToNibblesINtNtNtNtB19_4iter8adapters6copied6CopiedINtNtNtB19_5slice4iter4IterhEEEE20insert_storage_valueCscDgN54JpMGG_6author _RNvMs7_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_6VacantTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB15_NtNtB7_9trie_node17MerkleValueOutputEEINtNtB7_6nibble14BytesToNibblesINtNtNtNtB19_4iter8adapters6copied6CopiedINtNtNtB19_5slice4iter4IterhEEEE20insert_storage_valueCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1889 | 665 | pub fn insert_storage_value(mut self) -> PrepareInsert<'a, TUd> { | 1890 | | // Retrieve what will be the parent after we insert the new node, not taking branching | 1891 | | // into account yet. | 1892 | | // If `Some`, contains its index and number of nibbles in its key. | 1893 | 665 | let future_parent646 = match (self.closest_ancestor, self.trie.root_index) { | 1894 | 0 | (Some(_), None) => unreachable!(), | 1895 | 627 | (Some(ancestor), Some(_)) => { | 1896 | 627 | // TODO: could be optimized by passing in the Vacant the key remainder | 1897 | 627 | let key_len = self.trie.node_full_key(ancestor).count(); | 1898 | 627 | debug_assert!(self.key.clone().count() > key_len); | 1899 | 627 | Some((ancestor, key_len)) | 1900 | | } | 1901 | 19 | (None, Some(_)) => None, | 1902 | | (None, None) => { | 1903 | | // Situation where the trie is empty. This is kind of a special case that we | 1904 | | // handle by returning early. | 1905 | 19 | return PrepareInsert::One(PrepareInsertOne { | 1906 | 19 | trie: self.trie, | 1907 | 19 | parent: None, | 1908 | 19 | partial_key: self.key.collect(), | 1909 | 19 | children: [None; 16], | 1910 | 19 | }); | 1911 | | } | 1912 | | }; | 1913 | | | 1914 | | // Get the existing child of `future_parent` that points towards the newly-inserted node, | 1915 | | // or a successful early-return if none. | 1916 | 247 | let existing_node_index = | 1917 | 646 | if let Some((future_parent_index, future_parent_key_len627 )) = future_parent { | 1918 | 627 | let new_child_index = self.key.clone().nth(future_parent_key_len).unwrap(); | 1919 | 627 | let future_parent = self.trie.nodes.get(future_parent_index).unwrap(); | 1920 | 627 | match future_parent.children[usize::from(u8::from(new_child_index))] { | 1921 | 228 | Some(i) => { | 1922 | 228 | debug_assert_eq!( | 1923 | 228 | self.trie.nodes.get(i).unwrap().parent.unwrap().0, | 1924 | | future_parent_index | 1925 | | ); | 1926 | 228 | i | 1927 | | } | 1928 | | None => { | 1929 | | // There is an empty slot in `future_parent` for our new node. | 1930 | | // | 1931 | | // | 1932 | | // `future_parent` | 1933 | | // +-+ | 1934 | | // +-> +-+ <---------+ | 1935 | | // | <----+ | | 1936 | | // | ^ | | | 1937 | | // +-+ | | | | 1938 | | // New node +-+ +-+-+ +-+ +-+ 0 or more existing children | 1939 | | // +-+ +-+ +-+ | 1940 | | // | 1941 | | // | 1942 | 399 | return PrepareInsert::One(PrepareInsertOne { | 1943 | 399 | trie: self.trie, | 1944 | 399 | parent: Some((future_parent_index, new_child_index)), | 1945 | 399 | partial_key: self.key.skip(future_parent_key_len + 1).collect(), | 1946 | 399 | children: [None; 16], | 1947 | 399 | }); | 1948 | | } | 1949 | | } | 1950 | | } else { | 1951 | 19 | self.trie.root_index.unwrap() | 1952 | | }; | 1953 | | | 1954 | | // `existing_node_idx` and the new node are known to either have the same parent and the | 1955 | | // same child index, or to both have no parent. Now let's compare their partial key. | 1956 | 247 | let existing_node_partial_key = &self | 1957 | 247 | .trie | 1958 | 247 | .nodes | 1959 | 247 | .get(existing_node_index) | 1960 | 247 | .unwrap() | 1961 | 247 | .partial_key; | 1962 | 247 | let new_node_partial_key = self | 1963 | 247 | .key | 1964 | 247 | .clone() | 1965 | 247 | .skip(future_parent.map_or(0, |(_, n)| n + 1)) | 1966 | 247 | .collect::<Vec<_>>(); | 1967 | 247 | debug_assert_ne!(*existing_node_partial_key, new_node_partial_key); | 1968 | 247 | debug_assert!(!new_node_partial_key.starts_with(existing_node_partial_key)); | 1969 | | | 1970 | | // If `existing_node_partial_key` starts with `new_node_partial_key`, then the new node | 1971 | | // will be inserted in-between the parent and the existing node. | 1972 | 247 | if existing_node_partial_key.starts_with(&new_node_partial_key) { | 1973 | | // The new node is to be inserted in-between `future_parent` and | 1974 | | // `existing_node_index`. | 1975 | | // | 1976 | | // If `future_parent` is `Some`: | 1977 | | // | 1978 | | // | 1979 | | // +-+ | 1980 | | // `future_parent` +-+ <---------+ | 1981 | | // ^ | | 1982 | | // | + | 1983 | | // +-+ (0 or more existing children) | 1984 | | // New node +-+ | 1985 | | // ^ | 1986 | | // | | 1987 | | // +-+ | 1988 | | // `existing_node_index` +-+ | 1989 | | // ^ | 1990 | | // | | 1991 | | // + | 1992 | | // (0 or more existing children) | 1993 | | // | 1994 | | // | 1995 | | // | 1996 | | // If `future_parent` is `None`: | 1997 | | // | 1998 | | // | 1999 | | // New node +-+ | 2000 | | // (becomes the root) +-+ | 2001 | | // ^ | 2002 | | // | | 2003 | | // `existing_node_index` +-+ | 2004 | | // (current root) +-+ | 2005 | | // ^ | 2006 | | // | | 2007 | | // + | 2008 | | // (0 or more existing children) | 2009 | | // | 2010 | | | 2011 | 0 | let mut new_node_children = [None; 16]; | 2012 | 0 | let existing_node_new_child_index = | 2013 | 0 | existing_node_partial_key[new_node_partial_key.len()]; | 2014 | 0 | new_node_children[usize::from(u8::from(existing_node_new_child_index))] = | 2015 | 0 | Some(existing_node_index); | 2016 | 0 |
| 2017 | 0 | return PrepareInsert::One(PrepareInsertOne { | 2018 | 0 | trie: self.trie, | 2019 | 0 | parent: if let Some((future_parent_index, future_parent_key_len)) = future_parent { | 2020 | 0 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2021 | 0 | Some((future_parent_index, new_child_index)) | 2022 | | } else { | 2023 | 0 | None | 2024 | | }, | 2025 | 0 | partial_key: new_node_partial_key, | 2026 | 0 | children: new_node_children, | 2027 | | }); | 2028 | 247 | } | 2029 | | | 2030 | | // If we reach here, we know that we will need to create a new branch node in addition to | 2031 | | // the new storage node. | 2032 | | // | 2033 | | // If `future_parent` is `Some`: | 2034 | | // | 2035 | | // | 2036 | | // `future_parent` | 2037 | | // | 2038 | | // +-+ | 2039 | | // +-+ <--------+ (0 or more existing children) | 2040 | | // ^ | 2041 | | // | | 2042 | | // New branch node +-+ | 2043 | | // +-+ <-------+ | 2044 | | // ^ | | 2045 | | // | | | 2046 | | // +-+ +-+ | 2047 | | // `existing_node_index` +-+ +-+ New storage node | 2048 | | // ^ | 2049 | | // | | 2050 | | // | 2051 | | // (0 or more existing children) | 2052 | | // | 2053 | | // | 2054 | | // | 2055 | | // If `future_parent` is `None`: | 2056 | | // | 2057 | | // | 2058 | | // New branch node +-+ | 2059 | | // (becomes root) +-+ <-------+ | 2060 | | // ^ | | 2061 | | // | | | 2062 | | // `existing_node_index` +-+ +-+ | 2063 | | // (current root) +-+ +-+ New storage node | 2064 | | // ^ | 2065 | | // | | 2066 | | // | 2067 | | // (0 or more existing children) | 2068 | | // | 2069 | | // | 2070 | | | 2071 | | // Find the common ancestor between `new_node_partial_key` and `existing_node_partial_key`. | 2072 | 247 | let branch_partial_key_len = { | 2073 | 247 | debug_assert_ne!(new_node_partial_key, &**existing_node_partial_key); | 2074 | 247 | let mut len = 0; | 2075 | 247 | let mut k1 = new_node_partial_key.iter(); | 2076 | 247 | let mut k2 = existing_node_partial_key.iter(); | 2077 | | // Since `new_node_partial_key` is different from `existing_node_partial_key`, we know | 2078 | | // that `k1.next()` and `k2.next()` won't both be `None`. | 2079 | 3.78k | while k1.next() == k2.next() { | 2080 | 3.53k | len += 1; | 2081 | 3.53k | } | 2082 | 247 | debug_assert!(len < new_node_partial_key.len()); | 2083 | 247 | debug_assert!(len < existing_node_partial_key.len()); | 2084 | 247 | len | 2085 | | }; | 2086 | | | 2087 | | // Table of children for the new branch node, not including the new storage node. | 2088 | | // It therefore contains only one entry: `existing_node_index`. | 2089 | 247 | let branch_children = { | 2090 | 247 | let mut branch_children = [None; 16]; | 2091 | 247 | let existing_node_new_child_index = existing_node_partial_key[branch_partial_key_len]; | 2092 | 247 | debug_assert_ne!( | 2093 | | existing_node_new_child_index, | 2094 | 247 | new_node_partial_key[branch_partial_key_len] | 2095 | | ); | 2096 | 247 | branch_children[usize::from(u8::from(existing_node_new_child_index))] = | 2097 | 247 | Some(existing_node_index); | 2098 | 247 | branch_children | 2099 | 247 | }; | 2100 | 247 | | 2101 | 247 | // Success! | 2102 | 247 | PrepareInsert::Two(PrepareInsertTwo { | 2103 | 247 | trie: self.trie, | 2104 | 247 | | 2105 | 247 | storage_child_index: new_node_partial_key[branch_partial_key_len], | 2106 | 247 | storage_partial_key: new_node_partial_key[branch_partial_key_len + 1..].to_owned(), | 2107 | | | 2108 | 247 | branch_parent: if let Some((future_parent_index, future_parent_key_len228 )) = future_parent | 2109 | | { | 2110 | 228 | let new_child_index = self.key.nth(future_parent_key_len).unwrap(); | 2111 | 228 | Some((future_parent_index, new_child_index)) | 2112 | | } else { | 2113 | 19 | None | 2114 | | }, | 2115 | 247 | branch_partial_key: new_node_partial_key[..branch_partial_key_len].to_owned(), | 2116 | 247 | branch_children, | 2117 | | }) | 2118 | 665 | } |
|
2119 | | } |
2120 | | |
2121 | | /// Preparation for a new node insertion. |
2122 | | /// |
2123 | | /// The trie hasn't been modified yet and you can safely drop this object. |
2124 | | #[must_use] |
2125 | | pub enum PrepareInsert<'a, TUd> { |
2126 | | /// One node will be inserted in the trie. |
2127 | | One(PrepareInsertOne<'a, TUd>), |
2128 | | /// Two nodes will be inserted in the trie. |
2129 | | Two(PrepareInsertTwo<'a, TUd>), |
2130 | | } |
2131 | | |
2132 | | impl<'a, TUd> PrepareInsert<'a, TUd> { |
2133 | | /// Insert the new node. `branch_node_user_data` is discarded if `self` is |
2134 | | /// a [`PrepareInsert::One`]. |
2135 | 1.33M | pub fn insert( |
2136 | 1.33M | self, |
2137 | 1.33M | storage_node_user_data: TUd, |
2138 | 1.33M | branch_node_user_data: TUd, |
2139 | 1.33M | ) -> StorageNodeAccess<'a, TUd> { |
2140 | 1.33M | match self { |
2141 | 1.09M | PrepareInsert::One(n) => n.insert(storage_node_user_data), |
2142 | 243k | PrepareInsert::Two(n) => n.insert(storage_node_user_data, branch_node_user_data), |
2143 | | } |
2144 | 1.33M | } _RNvMs8_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13PrepareInsertTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEE6insertB9_ Line | Count | Source | 2135 | 2.51k | pub fn insert( | 2136 | 2.51k | self, | 2137 | 2.51k | storage_node_user_data: TUd, | 2138 | 2.51k | branch_node_user_data: TUd, | 2139 | 2.51k | ) -> StorageNodeAccess<'a, TUd> { | 2140 | 2.51k | match self { | 2141 | 2.44k | PrepareInsert::One(n) => n.insert(storage_node_user_data), | 2142 | 68 | PrepareInsert::Two(n) => n.insert(storage_node_user_data, branch_node_user_data), | 2143 | | } | 2144 | 2.51k | } |
_RNvMs8_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13PrepareInsertTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1c_NtNtB7_9trie_node17MerkleValueOutputEEE6insertB9_ Line | Count | Source | 2135 | 335k | pub fn insert( | 2136 | 335k | self, | 2137 | 335k | storage_node_user_data: TUd, | 2138 | 335k | branch_node_user_data: TUd, | 2139 | 335k | ) -> StorageNodeAccess<'a, TUd> { | 2140 | 335k | match self { | 2141 | 271k | PrepareInsert::One(n) => n.insert(storage_node_user_data), | 2142 | 63.7k | PrepareInsert::Two(n) => n.insert(storage_node_user_data, branch_node_user_data), | 2143 | | } | 2144 | 335k | } |
_RNvMs8_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_13PrepareInsertuE6insertB9_ Line | Count | Source | 2135 | 997k | pub fn insert( | 2136 | 997k | self, | 2137 | 997k | storage_node_user_data: TUd, | 2138 | 997k | branch_node_user_data: TUd, | 2139 | 997k | ) -> StorageNodeAccess<'a, TUd> { | 2140 | 997k | match self { | 2141 | 817k | PrepareInsert::One(n) => n.insert(storage_node_user_data), | 2142 | 179k | PrepareInsert::Two(n) => n.insert(storage_node_user_data, branch_node_user_data), | 2143 | | } | 2144 | 997k | } |
Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13PrepareInsertpE6insertB9_ _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13PrepareInsertTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1d_NtNtB7_9trie_node17MerkleValueOutputEEE6insertCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 2135 | 70 | pub fn insert( | 2136 | 70 | self, | 2137 | 70 | storage_node_user_data: TUd, | 2138 | 70 | branch_node_user_data: TUd, | 2139 | 70 | ) -> StorageNodeAccess<'a, TUd> { | 2140 | 70 | match self { | 2141 | 44 | PrepareInsert::One(n) => n.insert(storage_node_user_data), | 2142 | 26 | PrepareInsert::Two(n) => n.insert(storage_node_user_data, branch_node_user_data), | 2143 | | } | 2144 | 70 | } |
Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13PrepareInsertTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1d_NtNtB7_9trie_node17MerkleValueOutputEEE6insertCscDgN54JpMGG_6author _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_13PrepareInsertTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1d_NtNtB7_9trie_node17MerkleValueOutputEEE6insertCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 2135 | 665 | pub fn insert( | 2136 | 665 | self, | 2137 | 665 | storage_node_user_data: TUd, | 2138 | 665 | branch_node_user_data: TUd, | 2139 | 665 | ) -> StorageNodeAccess<'a, TUd> { | 2140 | 665 | match self { | 2141 | 418 | PrepareInsert::One(n) => n.insert(storage_node_user_data), | 2142 | 247 | PrepareInsert::Two(n) => n.insert(storage_node_user_data, branch_node_user_data), | 2143 | | } | 2144 | 665 | } |
|
2145 | | } |
2146 | | |
2147 | | /// One node will be inserted in the trie. |
2148 | | pub struct PrepareInsertOne<'a, TUd> { |
2149 | | trie: &'a mut TrieStructure<TUd>, |
2150 | | |
2151 | | /// Value of [`Node::parent`] for the newly-created node. |
2152 | | /// If `None`, we also set the root of the trie to the new node. |
2153 | | parent: Option<(usize, Nibble)>, |
2154 | | /// Value of [`Node::partial_key`] for the newly-created node. |
2155 | | partial_key: Vec<Nibble>, |
2156 | | /// Value of [`Node::children`] for the newly-created node. |
2157 | | children: [Option<usize>; 16], |
2158 | | } |
2159 | | |
2160 | | impl<'a, TUd> PrepareInsertOne<'a, TUd> { |
2161 | | /// Insert the new node. |
2162 | 1.12M | pub fn insert(self, user_data: TUd) -> StorageNodeAccess<'a, TUd> { |
2163 | 1.12M | let new_node_partial_key_len = self.partial_key.len(); |
2164 | 1.12M | |
2165 | 1.12M | let new_node_index = self.trie.nodes.insert(Node { |
2166 | 1.12M | parent: self.parent, |
2167 | 1.12M | partial_key: self.partial_key, |
2168 | 1.12M | children: self.children, |
2169 | 1.12M | has_storage_value: true, |
2170 | 1.12M | user_data, |
2171 | 1.12M | }); |
2172 | | |
2173 | | // Update the children node to point to their new parent. |
2174 | 17.9M | for (child_index, child) in self.children.iter().enumerate()1.12M { |
2175 | 17.9M | let child = match child { |
2176 | 101k | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), |
2177 | 17.8M | None => continue, |
2178 | | }; |
2179 | | |
2180 | 101k | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); |
2181 | 101k | child.parent = Some((new_node_index, child_index)); |
2182 | 101k | truncate_first_elems(&mut child.partial_key, new_node_partial_key_len + 1); |
2183 | | } |
2184 | | |
2185 | | // Update the parent to point to its new child. |
2186 | 1.12M | if let Some((parent_index, child_index1.05M )) = self.parent { |
2187 | 1.05M | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); |
2188 | 1.05M | parent.children[usize::from(u8::from(child_index))] = Some(new_node_index); |
2189 | 1.05M | } else { |
2190 | 61.6k | self.trie.root_index = Some(new_node_index); |
2191 | 61.6k | } |
2192 | | |
2193 | | // Success! |
2194 | 1.12M | StorageNodeAccess { |
2195 | 1.12M | trie: self.trie, |
2196 | 1.12M | node_index: new_node_index, |
2197 | 1.12M | } |
2198 | 1.12M | } _RNvMs9_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16PrepareInsertOneINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE6insertB9_ Line | Count | Source | 2162 | 28.8k | pub fn insert(self, user_data: TUd) -> StorageNodeAccess<'a, TUd> { | 2163 | 28.8k | let new_node_partial_key_len = self.partial_key.len(); | 2164 | 28.8k | | 2165 | 28.8k | let new_node_index = self.trie.nodes.insert(Node { | 2166 | 28.8k | parent: self.parent, | 2167 | 28.8k | partial_key: self.partial_key, | 2168 | 28.8k | children: self.children, | 2169 | 28.8k | has_storage_value: true, | 2170 | 28.8k | user_data, | 2171 | 28.8k | }); | 2172 | | | 2173 | | // Update the children node to point to their new parent. | 2174 | 461k | for (child_index, child) in self.children.iter().enumerate()28.8k { | 2175 | 461k | let child = match child { | 2176 | 7.15k | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2177 | 454k | None => continue, | 2178 | | }; | 2179 | | | 2180 | 7.15k | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2181 | 7.15k | child.parent = Some((new_node_index, child_index)); | 2182 | 7.15k | truncate_first_elems(&mut child.partial_key, new_node_partial_key_len + 1); | 2183 | | } | 2184 | | | 2185 | | // Update the parent to point to its new child. | 2186 | 28.8k | if let Some((parent_index, child_index25.3k )) = self.parent { | 2187 | 25.3k | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2188 | 25.3k | parent.children[usize::from(u8::from(child_index))] = Some(new_node_index); | 2189 | 25.3k | } else { | 2190 | 3.51k | self.trie.root_index = Some(new_node_index); | 2191 | 3.51k | } | 2192 | | | 2193 | | // Success! | 2194 | 28.8k | StorageNodeAccess { | 2195 | 28.8k | trie: self.trie, | 2196 | 28.8k | node_index: new_node_index, | 2197 | 28.8k | } | 2198 | 28.8k | } |
_RNvMs9_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16PrepareInsertOneTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE6insertB9_ Line | Count | Source | 2162 | 2.44k | pub fn insert(self, user_data: TUd) -> StorageNodeAccess<'a, TUd> { | 2163 | 2.44k | let new_node_partial_key_len = self.partial_key.len(); | 2164 | 2.44k | | 2165 | 2.44k | let new_node_index = self.trie.nodes.insert(Node { | 2166 | 2.44k | parent: self.parent, | 2167 | 2.44k | partial_key: self.partial_key, | 2168 | 2.44k | children: self.children, | 2169 | 2.44k | has_storage_value: true, | 2170 | 2.44k | user_data, | 2171 | 2.44k | }); | 2172 | | | 2173 | | // Update the children node to point to their new parent. | 2174 | 39.1k | for (child_index, child) in self.children.iter().enumerate()2.44k { | 2175 | 39.1k | let child = match child { | 2176 | 1 | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2177 | 39.1k | None => continue, | 2178 | | }; | 2179 | | | 2180 | 1 | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2181 | 1 | child.parent = Some((new_node_index, child_index)); | 2182 | 1 | truncate_first_elems(&mut child.partial_key, new_node_partial_key_len + 1); | 2183 | | } | 2184 | | | 2185 | | // Update the parent to point to its new child. | 2186 | 2.44k | if let Some((parent_index, child_index1.42k )) = self.parent { | 2187 | 1.42k | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2188 | 1.42k | parent.children[usize::from(u8::from(child_index))] = Some(new_node_index); | 2189 | 1.42k | } else { | 2190 | 1.02k | self.trie.root_index = Some(new_node_index); | 2191 | 1.02k | } | 2192 | | | 2193 | | // Success! | 2194 | 2.44k | StorageNodeAccess { | 2195 | 2.44k | trie: self.trie, | 2196 | 2.44k | node_index: new_node_index, | 2197 | 2.44k | } | 2198 | 2.44k | } |
_RNvMs9_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16PrepareInsertOneTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE6insertB9_ Line | Count | Source | 2162 | 271k | pub fn insert(self, user_data: TUd) -> StorageNodeAccess<'a, TUd> { | 2163 | 271k | let new_node_partial_key_len = self.partial_key.len(); | 2164 | 271k | | 2165 | 271k | let new_node_index = self.trie.nodes.insert(Node { | 2166 | 271k | parent: self.parent, | 2167 | 271k | partial_key: self.partial_key, | 2168 | 271k | children: self.children, | 2169 | 271k | has_storage_value: true, | 2170 | 271k | user_data, | 2171 | 271k | }); | 2172 | | | 2173 | | // Update the children node to point to their new parent. | 2174 | 4.34M | for (child_index, child) in self.children.iter().enumerate()271k { | 2175 | 4.34M | let child = match child { | 2176 | 6.67k | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2177 | 4.33M | None => continue, | 2178 | | }; | 2179 | | | 2180 | 6.67k | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2181 | 6.67k | child.parent = Some((new_node_index, child_index)); | 2182 | 6.67k | truncate_first_elems(&mut child.partial_key, new_node_partial_key_len + 1); | 2183 | | } | 2184 | | | 2185 | | // Update the parent to point to its new child. | 2186 | 271k | if let Some((parent_index, child_index226k )) = self.parent { | 2187 | 226k | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2188 | 226k | parent.children[usize::from(u8::from(child_index))] = Some(new_node_index); | 2189 | 226k | } else { | 2190 | 44.3k | self.trie.root_index = Some(new_node_index); | 2191 | 44.3k | } | 2192 | | | 2193 | | // Success! | 2194 | 271k | StorageNodeAccess { | 2195 | 271k | trie: self.trie, | 2196 | 271k | node_index: new_node_index, | 2197 | 271k | } | 2198 | 271k | } |
_RNvMs9_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16PrepareInsertOneuE6insertB9_ Line | Count | Source | 2162 | 817k | pub fn insert(self, user_data: TUd) -> StorageNodeAccess<'a, TUd> { | 2163 | 817k | let new_node_partial_key_len = self.partial_key.len(); | 2164 | 817k | | 2165 | 817k | let new_node_index = self.trie.nodes.insert(Node { | 2166 | 817k | parent: self.parent, | 2167 | 817k | partial_key: self.partial_key, | 2168 | 817k | children: self.children, | 2169 | 817k | has_storage_value: true, | 2170 | 817k | user_data, | 2171 | 817k | }); | 2172 | | | 2173 | | // Update the children node to point to their new parent. | 2174 | 13.0M | for (child_index, child) in self.children.iter().enumerate()817k { | 2175 | 13.0M | let child = match child { | 2176 | 87.2k | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2177 | 12.9M | None => continue, | 2178 | | }; | 2179 | | | 2180 | 87.2k | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2181 | 87.2k | child.parent = Some((new_node_index, child_index)); | 2182 | 87.2k | truncate_first_elems(&mut child.partial_key, new_node_partial_key_len + 1); | 2183 | | } | 2184 | | | 2185 | | // Update the parent to point to its new child. | 2186 | 817k | if let Some((parent_index, child_index805k )) = self.parent { | 2187 | 805k | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2188 | 805k | parent.children[usize::from(u8::from(child_index))] = Some(new_node_index); | 2189 | 805k | } else { | 2190 | 12.7k | self.trie.root_index = Some(new_node_index); | 2191 | 12.7k | } | 2192 | | | 2193 | | // Success! | 2194 | 817k | StorageNodeAccess { | 2195 | 817k | trie: self.trie, | 2196 | 817k | node_index: new_node_index, | 2197 | 817k | } | 2198 | 817k | } |
Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16PrepareInsertOneINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE6insertB9_ _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16PrepareInsertOneTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE6insertCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 2162 | 44 | pub fn insert(self, user_data: TUd) -> StorageNodeAccess<'a, TUd> { | 2163 | 44 | let new_node_partial_key_len = self.partial_key.len(); | 2164 | 44 | | 2165 | 44 | let new_node_index = self.trie.nodes.insert(Node { | 2166 | 44 | parent: self.parent, | 2167 | 44 | partial_key: self.partial_key, | 2168 | 44 | children: self.children, | 2169 | 44 | has_storage_value: true, | 2170 | 44 | user_data, | 2171 | 44 | }); | 2172 | | | 2173 | | // Update the children node to point to their new parent. | 2174 | 704 | for (child_index, child) in self.children.iter().enumerate()44 { | 2175 | 704 | let child = match child { | 2176 | 0 | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2177 | 704 | None => continue, | 2178 | | }; | 2179 | | | 2180 | 0 | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2181 | 0 | child.parent = Some((new_node_index, child_index)); | 2182 | 0 | truncate_first_elems(&mut child.partial_key, new_node_partial_key_len + 1); | 2183 | | } | 2184 | | | 2185 | | // Update the parent to point to its new child. | 2186 | 44 | if let Some((parent_index, child_index42 )) = self.parent { | 2187 | 42 | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2188 | 42 | parent.children[usize::from(u8::from(child_index))] = Some(new_node_index); | 2189 | 42 | } else { | 2190 | 2 | self.trie.root_index = Some(new_node_index); | 2191 | 2 | } | 2192 | | | 2193 | | // Success! | 2194 | 44 | StorageNodeAccess { | 2195 | 44 | trie: self.trie, | 2196 | 44 | node_index: new_node_index, | 2197 | 44 | } | 2198 | 44 | } |
Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16PrepareInsertOneTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE6insertCscDgN54JpMGG_6author _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16PrepareInsertOneTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE6insertCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 2162 | 418 | pub fn insert(self, user_data: TUd) -> StorageNodeAccess<'a, TUd> { | 2163 | 418 | let new_node_partial_key_len = self.partial_key.len(); | 2164 | 418 | | 2165 | 418 | let new_node_index = self.trie.nodes.insert(Node { | 2166 | 418 | parent: self.parent, | 2167 | 418 | partial_key: self.partial_key, | 2168 | 418 | children: self.children, | 2169 | 418 | has_storage_value: true, | 2170 | 418 | user_data, | 2171 | 418 | }); | 2172 | | | 2173 | | // Update the children node to point to their new parent. | 2174 | 6.68k | for (child_index, child) in self.children.iter().enumerate()418 { | 2175 | 6.68k | let child = match child { | 2176 | 0 | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2177 | 6.68k | None => continue, | 2178 | | }; | 2179 | | | 2180 | 0 | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2181 | 0 | child.parent = Some((new_node_index, child_index)); | 2182 | 0 | truncate_first_elems(&mut child.partial_key, new_node_partial_key_len + 1); | 2183 | | } | 2184 | | | 2185 | | // Update the parent to point to its new child. | 2186 | 418 | if let Some((parent_index, child_index399 )) = self.parent { | 2187 | 399 | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2188 | 399 | parent.children[usize::from(u8::from(child_index))] = Some(new_node_index); | 2189 | 399 | } else { | 2190 | 19 | self.trie.root_index = Some(new_node_index); | 2191 | 19 | } | 2192 | | | 2193 | | // Success! | 2194 | 418 | StorageNodeAccess { | 2195 | 418 | trie: self.trie, | 2196 | 418 | node_index: new_node_index, | 2197 | 418 | } | 2198 | 418 | } |
|
2199 | | } |
2200 | | |
2201 | | /// Two nodes will be inserted in the trie. |
2202 | | pub struct PrepareInsertTwo<'a, TUd> { |
2203 | | trie: &'a mut TrieStructure<TUd>, |
2204 | | |
2205 | | /// Value of the child index in [`Node::parent`] for the newly-created storage node. |
2206 | | storage_child_index: Nibble, |
2207 | | /// Value of [`Node::partial_key`] for the newly-created storage node. |
2208 | | storage_partial_key: Vec<Nibble>, |
2209 | | |
2210 | | /// Value of [`Node::parent`] for the newly-created branch node. |
2211 | | /// If `None`, we also set the root of the trie to the new branch node. |
2212 | | branch_parent: Option<(usize, Nibble)>, |
2213 | | /// Value of [`Node::partial_key`] for the newly-created branch node. |
2214 | | branch_partial_key: Vec<Nibble>, |
2215 | | /// Value of [`Node::children`] for the newly-created branch node. Does not include the entry |
2216 | | /// that must be filled with the new storage node. |
2217 | | branch_children: [Option<usize>; 16], |
2218 | | } |
2219 | | |
2220 | | impl<'a, TUd> PrepareInsertTwo<'a, TUd> { |
2221 | | /// Key of the branch node that will be inserted. |
2222 | 0 | pub fn branch_node_key(&'_ self) -> impl Iterator<Item = Nibble> + '_ { |
2223 | 0 | if let Some((parent_index, child_index)) = self.branch_parent { |
2224 | 0 | let parent = self.trie.node_full_key(parent_index); |
2225 | 0 | let iter = parent |
2226 | 0 | .chain(iter::once(child_index)) |
2227 | 0 | .chain(self.branch_partial_key.iter().cloned()); |
2228 | 0 | Either::Left(iter) |
2229 | | } else { |
2230 | 0 | Either::Right(self.branch_partial_key.iter().cloned()) |
2231 | | } |
2232 | 0 | } Unexecuted instantiation: _RNvMsa_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16PrepareInsertTwoINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE15branch_node_keyB9_ Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16PrepareInsertTwoINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE15branch_node_keyB9_ |
2233 | | |
2234 | | /// Insert the new node. |
2235 | 243k | pub fn insert( |
2236 | 243k | self, |
2237 | 243k | storage_node_user_data: TUd, |
2238 | 243k | branch_node_user_data: TUd, |
2239 | 243k | ) -> StorageNodeAccess<'a, TUd> { |
2240 | 243k | let new_branch_node_partial_key_len = self.branch_partial_key.len(); |
2241 | 243k | |
2242 | 243k | debug_assert_eq!( |
2243 | 3.89M | self.branch_children.iter().filter(243k |c| c.is_some()).count()243k , Unexecuted instantiation: _RNCNvMsa_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_16PrepareInsertTwoINtNtCsaYZPK01V26L_4core6option6OptionNtNtB9_12proof_encode4NodeEE6insert0Bb_ _RNCNvMsa_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_16PrepareInsertTwoTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1h_NtNtB9_9trie_node17MerkleValueOutputEEE6insert0Bb_ Line | Count | Source | 2243 | 1.08k | self.branch_children.iter().filter(|c| c.is_some()).count(), |
_RNCNvMsa_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_16PrepareInsertTwoTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB9_16TrieEntryVersionEEIB1h_NtNtB9_9trie_node17MerkleValueOutputEEE6insert0Bb_ Line | Count | Source | 2243 | 1.01M | self.branch_children.iter().filter(|c| c.is_some()).count(), |
_RNCNvMsa_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB7_16PrepareInsertTwouE6insert0Bb_ Line | Count | Source | 2243 | 2.87M | self.branch_children.iter().filter(|c| c.is_some()).count(), |
Unexecuted instantiation: _RNCNvMsa_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_16PrepareInsertTwoINtNtCsaYZPK01V26L_4core6option6OptionNtNtB9_12proof_encode4NodeEE6insert0Bb_ _RNCNvMsa_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_16PrepareInsertTwoTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1i_NtNtB9_9trie_node17MerkleValueOutputEEE6insert0CsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 2243 | 416 | self.branch_children.iter().filter(|c| c.is_some()).count(), |
Unexecuted instantiation: _RNCNvMsa_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_16PrepareInsertTwoTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1i_NtNtB9_9trie_node17MerkleValueOutputEEE6insert0CscDgN54JpMGG_6author _RNCNvMsa_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB7_16PrepareInsertTwoTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1i_NtNtB9_9trie_node17MerkleValueOutputEEE6insert0CsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 2243 | 3.95k | self.branch_children.iter().filter(|c| c.is_some()).count(), |
|
2244 | | 1 |
2245 | | ); |
2246 | | |
2247 | 243k | let new_branch_node_index = self.trie.nodes.insert(Node { |
2248 | 243k | parent: self.branch_parent, |
2249 | 243k | partial_key: self.branch_partial_key, |
2250 | 243k | children: self.branch_children, |
2251 | 243k | has_storage_value: false, |
2252 | 243k | user_data: branch_node_user_data, |
2253 | 243k | }); |
2254 | 243k | |
2255 | 243k | let new_storage_node_index = self.trie.nodes.insert(Node { |
2256 | 243k | parent: Some((new_branch_node_index, self.storage_child_index)), |
2257 | 243k | partial_key: self.storage_partial_key, |
2258 | 243k | children: [None; 16], |
2259 | 243k | has_storage_value: true, |
2260 | 243k | user_data: storage_node_user_data, |
2261 | 243k | }); |
2262 | 243k | |
2263 | 243k | self.trie |
2264 | 243k | .nodes |
2265 | 243k | .get_mut(new_branch_node_index) |
2266 | 243k | .unwrap() |
2267 | 243k | .children[usize::from(u8::from(self.storage_child_index))] = |
2268 | 243k | Some(new_storage_node_index); |
2269 | | |
2270 | | // Update the branch node's children to point to their new parent. |
2271 | 3.89M | for (child_index, child) in self.branch_children.iter().enumerate()243k { |
2272 | 3.89M | let child = match child { |
2273 | 243k | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), |
2274 | 3.65M | None => continue, |
2275 | | }; |
2276 | | |
2277 | 243k | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); |
2278 | 243k | child.parent = Some((new_branch_node_index, child_index)); |
2279 | 243k | truncate_first_elems(&mut child.partial_key, new_branch_node_partial_key_len + 1); |
2280 | | } |
2281 | | |
2282 | | // Update the branch node's parent to point to its new child. |
2283 | 243k | if let Some((parent_index, child_index227k )) = self.branch_parent { |
2284 | 227k | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); |
2285 | 227k | parent.children[usize::from(u8::from(child_index))] = Some(new_branch_node_index); |
2286 | 227k | } else { |
2287 | 16.2k | self.trie.root_index = Some(new_branch_node_index); |
2288 | 16.2k | } |
2289 | | |
2290 | | // Success! |
2291 | 243k | StorageNodeAccess { |
2292 | 243k | trie: self.trie, |
2293 | 243k | node_index: new_storage_node_index, |
2294 | 243k | } |
2295 | 243k | } Unexecuted instantiation: _RNvMsa_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16PrepareInsertTwoINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE6insertB9_ _RNvMsa_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16PrepareInsertTwoTINtNtCsaYZPK01V26L_4core6option6OptionINtNtCsdZExvAaxgia_5alloc3vec3VechEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE6insertB9_ Line | Count | Source | 2235 | 68 | pub fn insert( | 2236 | 68 | self, | 2237 | 68 | storage_node_user_data: TUd, | 2238 | 68 | branch_node_user_data: TUd, | 2239 | 68 | ) -> StorageNodeAccess<'a, TUd> { | 2240 | 68 | let new_branch_node_partial_key_len = self.branch_partial_key.len(); | 2241 | 68 | | 2242 | 68 | debug_assert_eq!( | 2243 | 68 | self.branch_children.iter().filter(|c| c.is_some()).count(), | 2244 | | 1 | 2245 | | ); | 2246 | | | 2247 | 68 | let new_branch_node_index = self.trie.nodes.insert(Node { | 2248 | 68 | parent: self.branch_parent, | 2249 | 68 | partial_key: self.branch_partial_key, | 2250 | 68 | children: self.branch_children, | 2251 | 68 | has_storage_value: false, | 2252 | 68 | user_data: branch_node_user_data, | 2253 | 68 | }); | 2254 | 68 | | 2255 | 68 | let new_storage_node_index = self.trie.nodes.insert(Node { | 2256 | 68 | parent: Some((new_branch_node_index, self.storage_child_index)), | 2257 | 68 | partial_key: self.storage_partial_key, | 2258 | 68 | children: [None; 16], | 2259 | 68 | has_storage_value: true, | 2260 | 68 | user_data: storage_node_user_data, | 2261 | 68 | }); | 2262 | 68 | | 2263 | 68 | self.trie | 2264 | 68 | .nodes | 2265 | 68 | .get_mut(new_branch_node_index) | 2266 | 68 | .unwrap() | 2267 | 68 | .children[usize::from(u8::from(self.storage_child_index))] = | 2268 | 68 | Some(new_storage_node_index); | 2269 | | | 2270 | | // Update the branch node's children to point to their new parent. | 2271 | 1.08k | for (child_index, child) in self.branch_children.iter().enumerate()68 { | 2272 | 1.08k | let child = match child { | 2273 | 68 | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2274 | 1.02k | None => continue, | 2275 | | }; | 2276 | | | 2277 | 68 | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2278 | 68 | child.parent = Some((new_branch_node_index, child_index)); | 2279 | 68 | truncate_first_elems(&mut child.partial_key, new_branch_node_partial_key_len + 1); | 2280 | | } | 2281 | | | 2282 | | // Update the branch node's parent to point to its new child. | 2283 | 68 | if let Some((parent_index, child_index)) = self.branch_parent { | 2284 | 68 | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2285 | 68 | parent.children[usize::from(u8::from(child_index))] = Some(new_branch_node_index); | 2286 | 68 | } else { | 2287 | 0 | self.trie.root_index = Some(new_branch_node_index); | 2288 | 0 | } | 2289 | | | 2290 | | // Success! | 2291 | 68 | StorageNodeAccess { | 2292 | 68 | trie: self.trie, | 2293 | 68 | node_index: new_storage_node_index, | 2294 | 68 | } | 2295 | 68 | } |
_RNvMsa_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16PrepareInsertTwoTINtNtCsaYZPK01V26L_4core6option6OptionTINtNtCsdZExvAaxgia_5alloc3vec3VechENtB7_16TrieEntryVersionEEIB1f_NtNtB7_9trie_node17MerkleValueOutputEEE6insertB9_ Line | Count | Source | 2235 | 63.7k | pub fn insert( | 2236 | 63.7k | self, | 2237 | 63.7k | storage_node_user_data: TUd, | 2238 | 63.7k | branch_node_user_data: TUd, | 2239 | 63.7k | ) -> StorageNodeAccess<'a, TUd> { | 2240 | 63.7k | let new_branch_node_partial_key_len = self.branch_partial_key.len(); | 2241 | 63.7k | | 2242 | 63.7k | debug_assert_eq!( | 2243 | 63.7k | self.branch_children.iter().filter(|c| c.is_some()).count(), | 2244 | | 1 | 2245 | | ); | 2246 | | | 2247 | 63.7k | let new_branch_node_index = self.trie.nodes.insert(Node { | 2248 | 63.7k | parent: self.branch_parent, | 2249 | 63.7k | partial_key: self.branch_partial_key, | 2250 | 63.7k | children: self.branch_children, | 2251 | 63.7k | has_storage_value: false, | 2252 | 63.7k | user_data: branch_node_user_data, | 2253 | 63.7k | }); | 2254 | 63.7k | | 2255 | 63.7k | let new_storage_node_index = self.trie.nodes.insert(Node { | 2256 | 63.7k | parent: Some((new_branch_node_index, self.storage_child_index)), | 2257 | 63.7k | partial_key: self.storage_partial_key, | 2258 | 63.7k | children: [None; 16], | 2259 | 63.7k | has_storage_value: true, | 2260 | 63.7k | user_data: storage_node_user_data, | 2261 | 63.7k | }); | 2262 | 63.7k | | 2263 | 63.7k | self.trie | 2264 | 63.7k | .nodes | 2265 | 63.7k | .get_mut(new_branch_node_index) | 2266 | 63.7k | .unwrap() | 2267 | 63.7k | .children[usize::from(u8::from(self.storage_child_index))] = | 2268 | 63.7k | Some(new_storage_node_index); | 2269 | | | 2270 | | // Update the branch node's children to point to their new parent. | 2271 | 1.01M | for (child_index, child) in self.branch_children.iter().enumerate()63.7k { | 2272 | 1.01M | let child = match child { | 2273 | 63.7k | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2274 | 955k | None => continue, | 2275 | | }; | 2276 | | | 2277 | 63.7k | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2278 | 63.7k | child.parent = Some((new_branch_node_index, child_index)); | 2279 | 63.7k | truncate_first_elems(&mut child.partial_key, new_branch_node_partial_key_len + 1); | 2280 | | } | 2281 | | | 2282 | | // Update the branch node's parent to point to its new child. | 2283 | 63.7k | if let Some((parent_index, child_index56.3k )) = self.branch_parent { | 2284 | 56.3k | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2285 | 56.3k | parent.children[usize::from(u8::from(child_index))] = Some(new_branch_node_index); | 2286 | 56.3k | } else { | 2287 | 7.33k | self.trie.root_index = Some(new_branch_node_index); | 2288 | 7.33k | } | 2289 | | | 2290 | | // Success! | 2291 | 63.7k | StorageNodeAccess { | 2292 | 63.7k | trie: self.trie, | 2293 | 63.7k | node_index: new_storage_node_index, | 2294 | 63.7k | } | 2295 | 63.7k | } |
_RNvMsa_NtNtCsN16ciHI6Qf_7smoldot4trie14trie_structureINtB5_16PrepareInsertTwouE6insertB9_ Line | Count | Source | 2235 | 179k | pub fn insert( | 2236 | 179k | self, | 2237 | 179k | storage_node_user_data: TUd, | 2238 | 179k | branch_node_user_data: TUd, | 2239 | 179k | ) -> StorageNodeAccess<'a, TUd> { | 2240 | 179k | let new_branch_node_partial_key_len = self.branch_partial_key.len(); | 2241 | 179k | | 2242 | 179k | debug_assert_eq!( | 2243 | 179k | self.branch_children.iter().filter(|c| c.is_some()).count(), | 2244 | | 1 | 2245 | | ); | 2246 | | | 2247 | 179k | let new_branch_node_index = self.trie.nodes.insert(Node { | 2248 | 179k | parent: self.branch_parent, | 2249 | 179k | partial_key: self.branch_partial_key, | 2250 | 179k | children: self.branch_children, | 2251 | 179k | has_storage_value: false, | 2252 | 179k | user_data: branch_node_user_data, | 2253 | 179k | }); | 2254 | 179k | | 2255 | 179k | let new_storage_node_index = self.trie.nodes.insert(Node { | 2256 | 179k | parent: Some((new_branch_node_index, self.storage_child_index)), | 2257 | 179k | partial_key: self.storage_partial_key, | 2258 | 179k | children: [None; 16], | 2259 | 179k | has_storage_value: true, | 2260 | 179k | user_data: storage_node_user_data, | 2261 | 179k | }); | 2262 | 179k | | 2263 | 179k | self.trie | 2264 | 179k | .nodes | 2265 | 179k | .get_mut(new_branch_node_index) | 2266 | 179k | .unwrap() | 2267 | 179k | .children[usize::from(u8::from(self.storage_child_index))] = | 2268 | 179k | Some(new_storage_node_index); | 2269 | | | 2270 | | // Update the branch node's children to point to their new parent. | 2271 | 2.87M | for (child_index, child) in self.branch_children.iter().enumerate()179k { | 2272 | 2.87M | let child = match child { | 2273 | 179k | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2274 | 2.69M | None => continue, | 2275 | | }; | 2276 | | | 2277 | 179k | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2278 | 179k | child.parent = Some((new_branch_node_index, child_index)); | 2279 | 179k | truncate_first_elems(&mut child.partial_key, new_branch_node_partial_key_len + 1); | 2280 | | } | 2281 | | | 2282 | | // Update the branch node's parent to point to its new child. | 2283 | 179k | if let Some((parent_index, child_index170k )) = self.branch_parent { | 2284 | 170k | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2285 | 170k | parent.children[usize::from(u8::from(child_index))] = Some(new_branch_node_index); | 2286 | 170k | } else { | 2287 | 8.94k | self.trie.root_index = Some(new_branch_node_index); | 2288 | 8.94k | } | 2289 | | | 2290 | | // Success! | 2291 | 179k | StorageNodeAccess { | 2292 | 179k | trie: self.trie, | 2293 | 179k | node_index: new_storage_node_index, | 2294 | 179k | } | 2295 | 179k | } |
Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16PrepareInsertTwoINtNtCsaYZPK01V26L_4core6option6OptionNtNtB7_12proof_encode4NodeEE6insertB9_ _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16PrepareInsertTwoTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE6insertCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 2235 | 26 | pub fn insert( | 2236 | 26 | self, | 2237 | 26 | storage_node_user_data: TUd, | 2238 | 26 | branch_node_user_data: TUd, | 2239 | 26 | ) -> StorageNodeAccess<'a, TUd> { | 2240 | 26 | let new_branch_node_partial_key_len = self.branch_partial_key.len(); | 2241 | 26 | | 2242 | 26 | debug_assert_eq!( | 2243 | 26 | self.branch_children.iter().filter(|c| c.is_some()).count(), | 2244 | | 1 | 2245 | | ); | 2246 | | | 2247 | 26 | let new_branch_node_index = self.trie.nodes.insert(Node { | 2248 | 26 | parent: self.branch_parent, | 2249 | 26 | partial_key: self.branch_partial_key, | 2250 | 26 | children: self.branch_children, | 2251 | 26 | has_storage_value: false, | 2252 | 26 | user_data: branch_node_user_data, | 2253 | 26 | }); | 2254 | 26 | | 2255 | 26 | let new_storage_node_index = self.trie.nodes.insert(Node { | 2256 | 26 | parent: Some((new_branch_node_index, self.storage_child_index)), | 2257 | 26 | partial_key: self.storage_partial_key, | 2258 | 26 | children: [None; 16], | 2259 | 26 | has_storage_value: true, | 2260 | 26 | user_data: storage_node_user_data, | 2261 | 26 | }); | 2262 | 26 | | 2263 | 26 | self.trie | 2264 | 26 | .nodes | 2265 | 26 | .get_mut(new_branch_node_index) | 2266 | 26 | .unwrap() | 2267 | 26 | .children[usize::from(u8::from(self.storage_child_index))] = | 2268 | 26 | Some(new_storage_node_index); | 2269 | | | 2270 | | // Update the branch node's children to point to their new parent. | 2271 | 416 | for (child_index, child) in self.branch_children.iter().enumerate()26 { | 2272 | 416 | let child = match child { | 2273 | 26 | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2274 | 390 | None => continue, | 2275 | | }; | 2276 | | | 2277 | 26 | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2278 | 26 | child.parent = Some((new_branch_node_index, child_index)); | 2279 | 26 | truncate_first_elems(&mut child.partial_key, new_branch_node_partial_key_len + 1); | 2280 | | } | 2281 | | | 2282 | | // Update the branch node's parent to point to its new child. | 2283 | 26 | if let Some((parent_index, child_index24 )) = self.branch_parent { | 2284 | 24 | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2285 | 24 | parent.children[usize::from(u8::from(child_index))] = Some(new_branch_node_index); | 2286 | 24 | } else { | 2287 | 2 | self.trie.root_index = Some(new_branch_node_index); | 2288 | 2 | } | 2289 | | | 2290 | | // Success! | 2291 | 26 | StorageNodeAccess { | 2292 | 26 | trie: self.trie, | 2293 | 26 | node_index: new_storage_node_index, | 2294 | 26 | } | 2295 | 26 | } |
Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16PrepareInsertTwoTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE6insertCscDgN54JpMGG_6author _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4trie14trie_structureINtB5_16PrepareInsertTwoTINtNtCsaYZPK01V26L_4core6option6OptionRShEIB1g_NtNtB7_9trie_node17MerkleValueOutputEEE6insertCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 2235 | 247 | pub fn insert( | 2236 | 247 | self, | 2237 | 247 | storage_node_user_data: TUd, | 2238 | 247 | branch_node_user_data: TUd, | 2239 | 247 | ) -> StorageNodeAccess<'a, TUd> { | 2240 | 247 | let new_branch_node_partial_key_len = self.branch_partial_key.len(); | 2241 | 247 | | 2242 | 247 | debug_assert_eq!( | 2243 | 247 | self.branch_children.iter().filter(|c| c.is_some()).count(), | 2244 | | 1 | 2245 | | ); | 2246 | | | 2247 | 247 | let new_branch_node_index = self.trie.nodes.insert(Node { | 2248 | 247 | parent: self.branch_parent, | 2249 | 247 | partial_key: self.branch_partial_key, | 2250 | 247 | children: self.branch_children, | 2251 | 247 | has_storage_value: false, | 2252 | 247 | user_data: branch_node_user_data, | 2253 | 247 | }); | 2254 | 247 | | 2255 | 247 | let new_storage_node_index = self.trie.nodes.insert(Node { | 2256 | 247 | parent: Some((new_branch_node_index, self.storage_child_index)), | 2257 | 247 | partial_key: self.storage_partial_key, | 2258 | 247 | children: [None; 16], | 2259 | 247 | has_storage_value: true, | 2260 | 247 | user_data: storage_node_user_data, | 2261 | 247 | }); | 2262 | 247 | | 2263 | 247 | self.trie | 2264 | 247 | .nodes | 2265 | 247 | .get_mut(new_branch_node_index) | 2266 | 247 | .unwrap() | 2267 | 247 | .children[usize::from(u8::from(self.storage_child_index))] = | 2268 | 247 | Some(new_storage_node_index); | 2269 | | | 2270 | | // Update the branch node's children to point to their new parent. | 2271 | 3.95k | for (child_index, child) in self.branch_children.iter().enumerate()247 { | 2272 | 3.95k | let child = match child { | 2273 | 247 | Some(c) => self.trie.nodes.get_mut(*c).unwrap(), | 2274 | 3.70k | None => continue, | 2275 | | }; | 2276 | | | 2277 | 247 | let child_index = Nibble::try_from(u8::try_from(child_index).unwrap()).unwrap(); | 2278 | 247 | child.parent = Some((new_branch_node_index, child_index)); | 2279 | 247 | truncate_first_elems(&mut child.partial_key, new_branch_node_partial_key_len + 1); | 2280 | | } | 2281 | | | 2282 | | // Update the branch node's parent to point to its new child. | 2283 | 247 | if let Some((parent_index, child_index228 )) = self.branch_parent { | 2284 | 228 | let parent = self.trie.nodes.get_mut(parent_index).unwrap(); | 2285 | 228 | parent.children[usize::from(u8::from(child_index))] = Some(new_branch_node_index); | 2286 | 228 | } else { | 2287 | 19 | self.trie.root_index = Some(new_branch_node_index); | 2288 | 19 | } | 2289 | | | 2290 | | // Success! | 2291 | 247 | StorageNodeAccess { | 2292 | 247 | trie: self.trie, | 2293 | 247 | node_index: new_storage_node_index, | 2294 | 247 | } | 2295 | 247 | } |
|
2296 | | } |
2297 | | |
2298 | | /// Inserts `first` and `second` at the beginning of `vec`. |
2299 | 25.1k | fn insert_front(vec: &mut Vec<Nibble>, first: Vec<Nibble>, next: Nibble) { |
2300 | 25.1k | let shift = first.len() + 1; |
2301 | 25.1k | let previous_len = vec.len(); |
2302 | 25.1k | vec.resize(vec.len() + shift, Nibble::try_from(0).unwrap()); |
2303 | 51.1k | for n in (0..previous_len).rev()25.1k { |
2304 | 51.1k | vec[n + shift] = vec[n]; |
2305 | 51.1k | } |
2306 | 25.1k | vec[0..first.len()].copy_from_slice(&first); |
2307 | 25.1k | vec[first.len()] = next; |
2308 | 25.1k | } _RNvNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structure12insert_front Line | Count | Source | 2299 | 25.1k | fn insert_front(vec: &mut Vec<Nibble>, first: Vec<Nibble>, next: Nibble) { | 2300 | 25.1k | let shift = first.len() + 1; | 2301 | 25.1k | let previous_len = vec.len(); | 2302 | 25.1k | vec.resize(vec.len() + shift, Nibble::try_from(0).unwrap()); | 2303 | 51.1k | for n in (0..previous_len).rev()25.1k { | 2304 | 51.1k | vec[n + shift] = vec[n]; | 2305 | 51.1k | } | 2306 | 25.1k | vec[0..first.len()].copy_from_slice(&first); | 2307 | 25.1k | vec[first.len()] = next; | 2308 | 25.1k | } |
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot4trie14trie_structure12insert_front |
2309 | | |
2310 | | /// Removes the first `num` elements of `vec`. |
2311 | 344k | fn truncate_first_elems(vec: &mut Vec<Nibble>, num: usize) { |
2312 | 344k | debug_assert!(num <= vec.len()); |
2313 | 573k | for n in num..vec.len()344k { |
2314 | 573k | vec[n - num] = vec[n]; |
2315 | 573k | } |
2316 | 344k | vec.truncate(vec.len() - num); |
2317 | 344k | } _RNvNtNtCsN16ciHI6Qf_7smoldot4trie14trie_structure20truncate_first_elems Line | Count | Source | 2311 | 344k | fn truncate_first_elems(vec: &mut Vec<Nibble>, num: usize) { | 2312 | 344k | debug_assert!(num <= vec.len()); | 2313 | 561k | for n in num..vec.len()344k { | 2314 | 561k | vec[n - num] = vec[n]; | 2315 | 561k | } | 2316 | 344k | vec.truncate(vec.len() - num); | 2317 | 344k | } |
_RNvNtNtCseuYC0Zibziv_7smoldot4trie14trie_structure20truncate_first_elems Line | Count | Source | 2311 | 273 | fn truncate_first_elems(vec: &mut Vec<Nibble>, num: usize) { | 2312 | 273 | debug_assert!(num <= vec.len()); | 2313 | 12.4k | for n in num..vec.len()273 { | 2314 | 12.4k | vec[n - num] = vec[n]; | 2315 | 12.4k | } | 2316 | 273 | vec.truncate(vec.len() - num); | 2317 | 273 | } |
|