From 16c7608bcfb876866abd62b65276951ee2a81b54 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 9 May 2024 13:20:13 +0200 Subject: feat(pkgs/lf-make-map): Add de-serialization to lf mappings --- .../pkgs/lf-make-map/src/mapping/map_tree/mod.rs | 38 +++++----------------- 1 file changed, 8 insertions(+), 30 deletions(-) (limited to 'sys/nixpkgs/pkgs/lf-make-map/src/mapping/map_tree/mod.rs') diff --git a/sys/nixpkgs/pkgs/lf-make-map/src/mapping/map_tree/mod.rs b/sys/nixpkgs/pkgs/lf-make-map/src/mapping/map_tree/mod.rs index 44adc483..35e6d91d 100644 --- a/sys/nixpkgs/pkgs/lf-make-map/src/mapping/map_tree/mod.rs +++ b/sys/nixpkgs/pkgs/lf-make-map/src/mapping/map_tree/mod.rs @@ -9,6 +9,7 @@ use super::MapKey; pub mod display; pub mod iterator; +pub mod lf_mapping; /// A prefix tree #[derive(Debug)] @@ -38,22 +39,8 @@ impl MappingTree { &self.root } - pub fn iter(&self) -> MappingTreeIterator { - MappingTreeIterator::new(&self) - } - - /// Returns the node at the key, otherwise None - pub fn get(&self, key: &[MapKey]) -> Option<&Node> { - let mut current_node = &self.root; - for ch in key.iter() { - if let NodeValue::Parent { children } = ¤t_node.value { - current_node = children.get(&ch)? - } else { - return None; - } - } - - Some(current_node) + pub fn iter(&self, ignore_extendable: bool) -> MappingTreeIterator { + MappingTreeIterator::new(&self, ignore_extendable) } /// Returns the node at the key, otherwise None. The node can be changed @@ -126,7 +113,11 @@ impl MappingTree { } )); - let child_value = if let NodeValue::Child { path, extandable } = child_value { + let child_value = if let NodeValue::Child { + path, + extandable: _, + } = child_value + { NodeValue::Child { path, extandable: false, @@ -147,18 +138,6 @@ impl MappingTree { Ok(()) } - pub fn replace_node(&mut self, key: &[MapKey], node: Node) -> Node { - let parent = self.get_mut(&key[..key.len() - 1]).expect("Must be some"); - - if let NodeValue::Parent { children } = &mut parent.value { - children - .insert(key[key.len() - 1].clone(), node) - .expect("This must exist, otherwise insert would have been used") - } else { - unreachable!("All parent nodes should be parent nodes"); - } - } - pub fn insert_node(&mut self, key: &[MapKey], node: Node) -> Result<()> { let (_node, found_key) = self.try_get(key).clone(); @@ -348,7 +327,6 @@ Please rename the paths to fix this. foreign_key[0].part_path, ); } - assert_eq!(our_key.len(), foreign_key.len()); debug!( "Found a better one: '{}' ('{}') and '{}' ('{}')", -- cgit 1.4.1