Show More
@@ -17,6 +17,7 b' use super::{' | |||
|
17 | 17 | }; |
|
18 | 18 | use std::fmt; |
|
19 | 19 | use std::ops::Deref; |
|
20 | use std::ops::Index; | |
|
20 | 21 | |
|
21 | 22 | #[derive(Debug, PartialEq)] |
|
22 | 23 | pub enum NodeMapError { |
@@ -195,6 +196,14 b' pub struct NodeTree {' | |||
|
195 | 196 | readonly: Box<dyn Deref<Target = [Block]> + Send>, |
|
196 | 197 | } |
|
197 | 198 | |
|
199 | impl Index<usize> for NodeTree { | |
|
200 | type Output = Block; | |
|
201 | ||
|
202 | fn index(&self, i: usize) -> &Block { | |
|
203 | &self.readonly[i] | |
|
204 | } | |
|
205 | } | |
|
206 | ||
|
198 | 207 | /// Return `None` unless the `Node` for `rev` has given prefix in `index`. |
|
199 | 208 | fn has_prefix_or_none<'p>( |
|
200 | 209 | idx: &impl RevlogIndex, |
@@ -213,6 +222,14 b" fn has_prefix_or_none<'p>(" | |||
|
213 | 222 | } |
|
214 | 223 | |
|
215 | 224 | impl NodeTree { |
|
225 | fn len(&self) -> usize { | |
|
226 | self.readonly.len() | |
|
227 | } | |
|
228 | ||
|
229 | fn is_empty(&self) -> bool { | |
|
230 | self.len() == 0 | |
|
231 | } | |
|
232 | ||
|
216 | 233 | /// Main working method for `NodeTree` searches |
|
217 | 234 | /// |
|
218 | 235 | /// This partial implementation lacks special cases for NULL_REVISION |
@@ -220,14 +237,13 b' impl NodeTree {' | |||
|
220 | 237 | &self, |
|
221 | 238 | prefix: NodePrefixRef<'p>, |
|
222 | 239 | ) -> Result<Option<Revision>, NodeMapError> { |
|
223 | let blocks: &[Block] = &*self.readonly; | |
|
224 | if blocks.is_empty() { | |
|
240 | if self.is_empty() { | |
|
225 | 241 | return Ok(None); |
|
226 | 242 | } |
|
227 |
let mut visit = |
|
|
243 | let mut visit = self.len() - 1; | |
|
228 | 244 | for i in 0..prefix.len() { |
|
229 | 245 | let nybble = prefix.get_nybble(i); |
|
230 |
match |
|
|
246 | match self[visit].get(nybble) { | |
|
231 | 247 | Element::None => return Ok(None), |
|
232 | 248 | Element::Rev(r) => return Ok(Some(r)), |
|
233 | 249 | Element::Block(idx) => visit = idx, |
General Comments 0
You need to be logged in to leave comments.
Login now