fn insert_closest_nodes(
    nodes: &mut [(NodeHandle, bool)],
    target_id: InfoHash,
    new_node: NodeHandle,
) {
    let new_distance = target_id ^ new_node.id;

    for &mut (ref mut old_node, ref mut used) in nodes.iter_mut() {
        if !*used {
            // Slot was not in use, go ahead and place the node
            *old_node = new_node;
            *used = true;
            return;
        } else {
            // Slot is in use, see if our node is closer to the target
            let old_distance = target_id ^ old_node.id;

            if new_distance < old_distance {
                *old_node = new_node;
                return;
            }
        }
    }
}
/// Inserts the node into the slice if a slot in the slice is unused or a node
/// in the slice is further from the target id than the node being inserted.
Inserts the node into the slice if a slot in the slice is unused or a node
in the slice is further from the target id than the node being inserted.
Inserts the node into the slice if a slot in the slice is unused or a node in the slice is further from the target id than the node being inserted .
fn insert_closest_nodes(
    nodes: &mut [(NodeHandle, bool)],
    target_id: InfoHash,
    new_node: NodeHandle,
) {
    let new_distance = target_id ^ new_node.id;
    for &mut (ref mut old_node, ref mut used) in nodes.iter_mut() {
        if !*used {
            // Slot was not in use, go ahead and place the node
            *old_node = new_node;
            *used = true;
            return;
        } else {
            // Slot is in use, see if our node is closer to the target
            let old_distance = target_id ^ old_node.id;
            if new_distance < old_distance {
                *old_node = new_node;
                return;
            }
        }
    }
}
fn insert_closest_nodes ( nodes : & mut [ ( NodeHandle , bool ) ] , target_id : InfoHash , new_node : NodeHandle , ) { let new_distance = target_id ^ new_node . id ; for & mut ( ref mut old_node , ref mut used ) in nodes . iter_mut ( ) { if ! * used { // Slot was not in use, go ahead and place the node * old_node = new_node ; * used = true ; return ; } else { // Slot is in use, see if our node is closer to the target let old_distance = target_id ^ old_node . id ; if new_distance < old_distance { * old_node = new_node ; return ; } } } }
Inserts the node into the slice if a slot in the slice is unused or a node
in the slice is further from the target id than the node being inserted.
Inserts the node into the slice if a slot in the slice is unused or a node in the slice is further from the target id than the node being inserted .
nodes
&mut [(NodeHandle, bool)]
target_id
InfoHash
new_node
NodeHandle
nodes
&mut [(NodeHandle, bool)]
target_id
InfoHash
new_node
NodeHandle