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