pub fn find_longest_branch(&self, most_valuable: Option<bool>) -> K {
        // We take the nodes that correspond to the greatest available
        // height stored in the system as the heads of the tree.
        // This should not fail for we always store every node by their height.
        let heads = self
            .nodes_by_height
            .get(&self.height)
            .expect("there in no node stored corresponding to the greatest logged height");
        let mut lead_branches: HashMap<K, u64> = HashMap::new();
        // We check each head of the tree
        for head in heads {
            let mut worth = 0;
            let mut root = head;
            // We count the lineage number of each branch from head to root
            while let Some(node) = self.nodes_by_key.get(root) {
                if node.parent != self.root.key {
                    root = &node.parent;
                    worth += if most_valuable.unwrap_or(self.value_based) {
                        node.value
                    } else {
                        1
                    };
                } else {
                    // When we reached the roots immidiate child we break out of the loop
                    break;
                }
            }
            // Insert the height of the branch with the branches root (the system roots child)
            // as the key.
            lead_branches.insert(*root, worth);
        }
        let (mut most_valuable_key, mut greatest_worth) = (K::default(), 0);
        // After the parsed every branch corresponding to a head, we determine the longest and return
        // its key
        for (key, worth) in lead_branches {
            if worth > greatest_worth {
                greatest_worth = worth;
                most_valuable_key = key;
            }
        }
        most_valuable_key
    }
/// Returns the key of the node that is the immidiate child of the current root,
/// and has the longest available lineage.
/// # Panics
/// If this function call fails that means that at least one node was not stored in the memory.
Returns the key of the node that is the immidiate child of the current root,
and has the longest available lineage.
Returns the key of the node that is the immidiate child of the current root and has the longest available lineage .
pub fn find_longest_branch(&self, most_valuable: Option<bool>) -> K {
        // We take the nodes that correspond to the greatest available
        // height stored in the system as the heads of the tree.
        // This should not fail for we always store every node by their height.
        let heads = self
            .nodes_by_height
            .get(&self.height)
            .expect("there in no node stored corresponding to the greatest logged height");
        let mut lead_branches: HashMap<K, u64> = HashMap::new();
        // We check each head of the tree
        for head in heads {
            let mut worth = 0;
            let mut root = head;
            // We count the lineage number of each branch from head to root
            while let Some(node) = self.nodes_by_key.get(root) {
                if node.parent != self.root.key {
                    root = &node.parent;
                    worth += if most_valuable.unwrap_or(self.value_based) {
                        node.value
                    } else {
                        1
                    };
                } else {
                    // When we reached the roots immidiate child we break out of the loop
                    break;
                }
            }
            // Insert the height of the branch with the branches root (the system roots child)
            // as the key.
            lead_branches.insert(*root, worth);
        }
        let (mut most_valuable_key, mut greatest_worth) = (K::default(), 0);
        // After the parsed every branch corresponding to a head, we determine the longest and return
        // its key
        for (key, worth) in lead_branches {
            if worth > greatest_worth {
                greatest_worth = worth;
                most_valuable_key = key;
            }
        }
        most_valuable_key
    }
pub fn find_longest_branch ( & self , most_valuable : Option < bool > ) -> K { // We take the nodes that correspond to the greatest available // height stored in the system as the heads of the tree. // This should not fail for we always store every node by their height. let heads = self . nodes_by_height . get ( & self . height ) . expect ( " " ) ; let mut lead_branches : HashMap < K , u64 > = HashMap :: new ( ) ; // We check each head of the tree for head in heads { let mut worth = 0 ; let mut root = head ; // We count the lineage number of each branch from head to root while let Some ( node ) = self . nodes_by_key . get ( root ) { if node . parent != self . root . key { root = & node . parent ; worth += if most_valuable . unwrap_or ( self . value_based ) { node . value } else { 1 } ; } else { // When we reached the roots immidiate child we break out of the loop break ; } } // Insert the height of the branch with the branches root (the system roots child) // as the key. lead_branches . insert ( * root , worth ) ; } let ( mut most_valuable_key , mut greatest_worth ) = ( K :: default ( ) , 0 ) ; // After the parsed every branch corresponding to a head, we determine the longest and return // its key for ( key , worth ) in lead_branches { if worth > greatest_worth { greatest_worth = worth ; most_valuable_key = key ; } } most_valuable_key }
Returns the key of the node that is the immidiate child of the current root,
and has the longest available lineage.
Returns the key of the node that is the immidiate child of the current root and has the longest available lineage .
&self
most_valuable
Option<bool>
&self
most_valuable
Option<bool>
panics
If this function call fails that means that at least one node was not stored in the memory.
If this function call fails that means that at least one node was not stored in the memory .