pub fn add_node(&mut self, new_node: Node) -> bool {
        let new_node_status = new_node.status();
        if new_node_status == NodeStatus::Bad {
            return true;
        }

        // See if this node is already in the table, in that case replace it if it
        // has a higher or equal status to the current node.
        if let Some(index) = self.nodes.iter().position(|node| *node == new_node) {
            // Note, we can't just compare the status and if it's better or equal then replace the
            // old node with the new one. Doing so would erase information already stored locally.
            self.nodes[index].update(new_node);

            return true;
        }

        // See if any lower priority nodes are present in the table, we cant do
        // nodes that have equal status because we have to prefer longer lasting
        // nodes in the case of a good status which helps with stability.
        let replace_index = self
            .nodes
            .iter()
            .position(|node| node.status() < new_node_status);
        if let Some(index) = replace_index {
            self.nodes[index] = new_node;

            true
        } else {
            false
        }
    }
/// Attempt to add the given Node to the bucket if it is not in a bad state.
///
/// Returns false if the Node could not be placed in the bucket because it is full.
Attempt to add the given Node to the bucket if it is not in a bad state.
Returns false if the Node could not be placed in the bucket because it is full.
Attempt to add the given Node to the bucket if it is not in a bad state . Returns false if the Node could not be placed in the bucket because it is full .
pub fn add_node(&mut self, new_node: Node) -> bool {
        let new_node_status = new_node.status();
        if new_node_status == NodeStatus::Bad {
            return true;
        }
        // See if this node is already in the table, in that case replace it if it
        // has a higher or equal status to the current node.
        if let Some(index) = self.nodes.iter().position(|node| *node == new_node) {
            // Note, we can't just compare the status and if it's better or equal then replace the
            // old node with the new one. Doing so would erase information already stored locally.
            self.nodes[index].update(new_node);
            return true;
        }
        // See if any lower priority nodes are present in the table, we cant do
        // nodes that have equal status because we have to prefer longer lasting
        // nodes in the case of a good status which helps with stability.
        let replace_index = self
            .nodes
            .iter()
            .position(|node| node.status() < new_node_status);
        if let Some(index) = replace_index {
            self.nodes[index] = new_node;
            true
        } else {
            false
        }
    }
pub fn add_node ( & mut self , new_node : Node ) -> bool { let new_node_status = new_node . status ( ) ; if new_node_status == NodeStatus :: Bad { return true ; } // See if this node is already in the table, in that case replace it if it // has a higher or equal status to the current node. if let Some ( index ) = self . nodes . iter ( ) . position ( | node | * node == new_node ) { // Note, we can't just compare the status and if it's better or equal then replace the // old node with the new one. Doing so would erase information already stored locally. self . nodes [ index ] . update ( new_node ) ; return true ; } // See if any lower priority nodes are present in the table, we cant do // nodes that have equal status because we have to prefer longer lasting // nodes in the case of a good status which helps with stability. let replace_index = self . nodes . iter ( ) . position ( | node | node . status ( ) < new_node_status ) ; if let Some ( index ) = replace_index { self . nodes [ index ] = new_node ; true } else { false } }
Attempt to add the given Node to the bucket if it is not in a bad state.
Attempt to add the given Node to the bucket if it is not in a bad state .
&mut self
new_node
Node
&mut self
new_node
Node