From a85ff90e279e9b16ebddf2789ac0d0800b3e315d Mon Sep 17 00:00:00 2001 From: sgoudham Date: Tue, 22 Feb 2022 02:23:41 +0000 Subject: [PATCH] Add height() documentation --- src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1711575..952706b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -177,9 +177,9 @@ pub trait BinarySearchTree { /// or `None` if element does not exist. fn retrieve_as_mut(&mut self, value: &T) -> Option<&mut T>; - /// Returns the **height.** + /// Returns the **height** or `None` if tree is empty. /// - /// This is the number of edges between the root and it's furthest leaf node. + /// The height is the number of edges between the root and it's furthest leaf node. /// /// # Example /// @@ -393,10 +393,9 @@ impl BinarySearchTree for IterativeBST { } fn height(&self) -> Option { - match self.root { - None => None, - Some(_) => Some(Node::iterative_height(&self.root)), - } + self.root + .as_ref() + .map(|_| Node::iterative_height(&self.root)) } fn min(&self) -> Option<&T> {