fn insert_sorted_node(
    nodes: &mut Vec<(Distance, NodeHandle, bool)>,
    target: InfoHash,
    node: NodeHandle,
    pinged: bool,
) {
    let node_id = node.id;
    let node_dist = target ^ node_id;

    // Perform a search by distance from the target id
    let search_result = nodes.binary_search_by(|(dist, _, _)| dist.cmp(&node_dist));
    match search_result {
        Ok(dup_index) => {
            // TODO: Bug here, what happens when multiple nodes with the same distance are
            // present, but we dont get the index of the duplicate node (its in the list) from
            // the search, then we would have a duplicate node in the list!
            // Insert only if this node is different (it is ok if they have the same id)
            if nodes[dup_index].1 != node {
                nodes.insert(dup_index, (node_dist, node, pinged));
            }
        }
        Err(ins_index) => nodes.insert(ins_index, (node_dist, node, pinged)),
    };
}
/// Inserts the Node into the list of nodes based on its distance from the target node.
///
/// Nodes at the start of the list are closer to the target node than nodes at the end.
Inserts the Node into the list of nodes based on its distance from the target node.
Nodes at the start of the list are closer to the target node than nodes at the end.
Inserts the Node into the list of nodes based on its distance from the target node . Nodes at the start of the list are closer to the target node than nodes at the end .
fn insert_sorted_node(
    nodes: &mut Vec<(Distance, NodeHandle, bool)>,
    target: InfoHash,
    node: NodeHandle,
    pinged: bool,
) {
    let node_id = node.id;
    let node_dist = target ^ node_id;
    // Perform a search by distance from the target id
    let search_result = nodes.binary_search_by(|(dist, _, _)| dist.cmp(&node_dist));
    match search_result {
        Ok(dup_index) => {
            // TODO: Bug here, what happens when multiple nodes with the same distance are
            // present, but we dont get the index of the duplicate node (its in the list) from
            // the search, then we would have a duplicate node in the list!
            // Insert only if this node is different (it is ok if they have the same id)
            if nodes[dup_index].1 != node {
                nodes.insert(dup_index, (node_dist, node, pinged));
            }
        }
        Err(ins_index) => nodes.insert(ins_index, (node_dist, node, pinged)),
    };
}
fn insert_sorted_node ( nodes : & mut Vec < ( Distance , NodeHandle , bool ) > , target : InfoHash , node : NodeHandle , pinged : bool , ) { let node_id = node . id ; let node_dist = target ^ node_id ; // Perform a search by distance from the target id let search_result = nodes . binary_search_by ( | ( dist , _ , _ ) | dist . cmp ( & node_dist ) ) ; match search_result { Ok ( dup_index ) => { // TODO: Bug here, what happens when multiple nodes with the same distance are // present, but we dont get the index of the duplicate node (its in the list) from // the search, then we would have a duplicate node in the list! // Insert only if this node is different (it is ok if they have the same id) if nodes [ dup_index ] . 1 != node { nodes . insert ( dup_index , ( node_dist , node , pinged ) ) ; } } Err ( ins_index ) => nodes . insert ( ins_index , ( node_dist , node , pinged ) ) , } ; }
Inserts the Node into the list of nodes based on its distance from the target node.
Inserts the Node into the list of nodes based on its distance from the target node .
nodes
&mut Vec<(Distance, NodeHandle, bool)>
target
InfoHash
node
NodeHandle
pinged
bool
nodes
&mut Vec<(Distance, NodeHandle, bool)>
target
InfoHash
node
NodeHandle
pinged
bool