MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / prev

Method prev

cranelift/bforest/src/path.rs:133–159  ·  view source on GitHub ↗

Move this path to the previous key-value pair and return it. If the path is at the off-the-end position, go to the last key-value pair. If the path is already at the first key-value pair, leave it there and return `None`.

(&mut self, root: Node, pool: &NodePool<F>)

Source from the content-addressed store, hash-verified

131 ///
132 /// If the path is already at the first key-value pair, leave it there and return `None`.
133 pub fn prev(&mut self, root: Node, pool: &NodePool<F>) -> Option<(F::Key, F::Value)> {
134 // We use `size == 0` as a generic off-the-end position.
135 if self.size == 0 {
136 self.goto_subtree_last(0, root, pool);
137 let (node, entry) = self.leaf_pos().unwrap();
138 let (keys, vals) = pool[node].unwrap_leaf();
139 return Some((keys[entry], vals[entry]));
140 }
141
142 match self.leaf_pos() {
143 None => return None,
144 Some((node, entry)) => {
145 if entry > 0 {
146 self.entry[self.size - 1] -= 1;
147 let (keys, vals) = pool[node].unwrap_leaf();
148 return Some((keys[entry - 1], vals[entry - 1]));
149 }
150 }
151 }
152
153 // The current leaf node is exhausted. Move to the previous one.
154 self.prev_leaf(pool).map(|node| {
155 let (keys, vals) = pool[node].unwrap_leaf();
156 let e = self.leaf_entry();
157 (keys[e], vals[e])
158 })
159 }
160
161 /// Move path to the first entry of the next node at level, if one exists.
162 ///

Callers

nothing calls this directly

Calls 7

goto_subtree_lastMethod · 0.80
leaf_posMethod · 0.80
unwrap_leafMethod · 0.80
prev_leafMethod · 0.80
leaf_entryMethod · 0.80
unwrapMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected