Mercurial > hg
comparison rust/hg-core/src/dirstate_tree/dirstate_map.rs @ 47099:3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Differential Revision: https://phab.mercurial-scm.org/D10369
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 06 Apr 2021 14:35:39 +0200 |
parents | d7631d55da3e |
children | caa3031c9ed5 |
comparison
equal
deleted
inserted
replaced
47098:d7631d55da3e | 47099:3da19db33cbc |
---|---|
47 pub fn new() -> Self { | 47 pub fn new() -> Self { |
48 Self { | 48 Self { |
49 parents: None, | 49 parents: None, |
50 dirty_parents: false, | 50 dirty_parents: false, |
51 root: ChildNodes::new(), | 51 root: ChildNodes::new(), |
52 } | |
53 } | |
54 | |
55 fn get_node(&self, path: &HgPath) -> Option<&Node> { | |
56 let mut children = &self.root; | |
57 let mut components = path.components(); | |
58 let mut component = | |
59 components.next().expect("expected at least one components"); | |
60 loop { | |
61 let child = children.get(component)?; | |
62 if let Some(next_component) = components.next() { | |
63 component = next_component; | |
64 children = &child.children; | |
65 } else { | |
66 return Some(child); | |
67 } | |
52 } | 68 } |
53 } | 69 } |
54 | 70 |
55 fn get_or_insert_node(&mut self, path: &HgPath) -> &mut Node { | 71 fn get_or_insert_node(&mut self, path: &HgPath) -> &mut Node { |
56 let mut child_nodes = &mut self.root; | 72 let mut child_nodes = &mut self.root; |
263 | 279 |
264 fn copy_map_iter(&self) -> CopyMapIter<'_> { | 280 fn copy_map_iter(&self) -> CopyMapIter<'_> { |
265 todo!() | 281 todo!() |
266 } | 282 } |
267 | 283 |
268 fn copy_map_contains_key(&self, _key: &HgPath) -> bool { | 284 fn copy_map_contains_key(&self, key: &HgPath) -> bool { |
269 todo!() | 285 if let Some(node) = self.get_node(key) { |
270 } | 286 node.copy_source.is_some() |
271 | 287 } else { |
272 fn copy_map_get(&self, _key: &HgPath) -> Option<&HgPathBuf> { | 288 false |
273 todo!() | 289 } |
290 } | |
291 | |
292 fn copy_map_get(&self, key: &HgPath) -> Option<&HgPathBuf> { | |
293 self.get_node(key)?.copy_source.as_ref() | |
274 } | 294 } |
275 | 295 |
276 fn copy_map_remove(&mut self, _key: &HgPath) -> Option<HgPathBuf> { | 296 fn copy_map_remove(&mut self, _key: &HgPath) -> Option<HgPathBuf> { |
277 todo!() | 297 todo!() |
278 } | 298 } |
287 | 307 |
288 fn len(&self) -> usize { | 308 fn len(&self) -> usize { |
289 todo!() | 309 todo!() |
290 } | 310 } |
291 | 311 |
292 fn contains_key(&self, _key: &HgPath) -> bool { | 312 fn contains_key(&self, key: &HgPath) -> bool { |
293 todo!() | 313 self.get(key).is_some() |
294 } | 314 } |
295 | 315 |
296 fn get(&self, _key: &HgPath) -> Option<&DirstateEntry> { | 316 fn get(&self, key: &HgPath) -> Option<&DirstateEntry> { |
297 todo!() | 317 self.get_node(key)?.entry.as_ref() |
298 } | 318 } |
299 | 319 |
300 fn iter(&self) -> StateMapIter<'_> { | 320 fn iter(&self) -> StateMapIter<'_> { |
301 todo!() | 321 todo!() |
302 } | 322 } |