diff --git a/src/common/succinct_tree.rs b/src/common/succinct_tree.rs index 74cd87192c87838d9f0a8a1050a8ceaeeb7d080b..d49a35ea11faf800613dbc7b7b9e02ee8e6bbe2a 100644 --- a/src/common/succinct_tree.rs +++ b/src/common/succinct_tree.rs @@ -10,7 +10,7 @@ pub trait SuccinctTree<T, Label>: Debug { fn first_child(&self, index: u64) -> Result<u64, NodeError>; fn next_sibling(&self, index: u64) -> Result<u64, NodeError>; fn from_id_tree(tree: Tree<i32>) -> Result<T, EmptyTreeError>; - fn child_label(&self, index: u64) -> Result<Label, NodeError>; + fn child_label(&self, index: u64) -> Result<&Label, NodeError>; fn labeled_child(&self, index: u64, label: Label) -> Result<u64, NodeError>; /// Prüft ob ein Bitvector ein gültiger SuccinctTree ist, anhand des gültigen Exzesses und diff --git a/src/trees/bp_tree.rs b/src/trees/bp_tree.rs index 3621c4f16ee032f41101da937845ab3797cdaad9..cecf07840d063ad4f7363e55c9ba960d3ee08168 100644 --- a/src/trees/bp_tree.rs +++ b/src/trees/bp_tree.rs @@ -138,9 +138,9 @@ impl<L> SuccinctTree<BPTree<L>, L> for BPTree<L> { /// # Arguments /// * `index` The index of the node to get the label of /// # Errors - /// * `NotANodeError` If `index` does not reference a node. - fn child_label(&self, index: u64) -> Result<L, NodeError> { - unimplemented!(); + /// * `NoLabelError` If `index` does not reference a node with a label. + fn child_label(&self, index: u64) -> Result<&L, NodeError> { + self.labels.get(index as usize).ok_or(NodeError::NoLabelError) } /// Returns the child from the specified node with that label @@ -151,6 +151,7 @@ impl<L> SuccinctTree<BPTree<L>, L> for BPTree<L> { /// * `NoSuchChildError` If there is no child which has this label fn labeled_child(&self, index: u64, label: L) -> Result<u64, NodeError> { unimplemented!(); + } } diff --git a/src/trees/louds_tree.rs b/src/trees/louds_tree.rs index bf6ed55178b4466b7fd6817df2379c50611c9450..4944a709580c2466f7e07d7331b6869db00e5d11 100644 --- a/src/trees/louds_tree.rs +++ b/src/trees/louds_tree.rs @@ -153,7 +153,7 @@ impl<L> SuccinctTree<LOUDSTree<L>, L> for LOUDSTree<L> { /// * `index` The index of the node to get the label of /// # Errors /// * `NotANodeError` If `index` does not reference a node. - fn child_label(&self, index: u64) -> Result<L, NodeError> { + fn child_label(&self, index: u64) -> Result<&L, NodeError> { unimplemented!(); } @@ -250,7 +250,8 @@ mod tests { let tree: LOUDSTree<String> = LOUDSTree::from_bitvec(bitvec.clone()).unwrap(); tree.save_to("testdata/loudstree.testdata".to_string()) .unwrap(); - let result: LOUDSTree<String> = LOUDSTree::from_file("testdata/loudstree.testdata".to_string()).unwrap(); + let result: LOUDSTree<String> = + LOUDSTree::from_file("testdata/loudstree.testdata".to_string()).unwrap(); assert_eq!( tree, result, "The loaded tree is not equal to the original one." @@ -388,7 +389,6 @@ mod tests { assert_ne!(tree_a, tree_c) } - #[test] fn from_id_tree() { let mut id_tree: Tree<i32> = TreeBuilder::new().with_node_capacity(5).build(); @@ -406,9 +406,6 @@ mod tests { fn from_empty_id_tree() { let id_tree: Tree<i32> = TreeBuilder::new().with_node_capacity(5).build(); let tree: Result<LOUDSTree<String>, EmptyTreeError> = LOUDSTree::from_id_tree(id_tree); - assert_eq!( - tree.unwrap_err(), - EmptyTreeError - ); + assert_eq!(tree.unwrap_err(), EmptyTreeError); } }