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>)
| 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 | /// |
nothing calls this directly
no test coverage detected