fn filter_duplicit_services(
    services: &[(MacAddr, SocketAddr)],
    port_priorities: &HashMap<u16, usize>) -> Vec<(MacAddr, SocketAddr)> {
    let mut svc_map = HashMap::new();

    for &(ref mac, ref saddr) in services {
        let mac  = *mac;
        let ip   = saddr.ip();
        let port = saddr.port();

        if svc_map.contains_key(&ip) {
            let old_port = svc_map.get(&ip)
                .map(|&(_, _, ref port)| *port)
                .unwrap_or(0);
            let old_priority = port_priorities.get(&old_port)
                .map(|priority| *priority)
                .unwrap_or(0);
            let new_priority = port_priorities.get(&port)
                .map(|priority| *priority)
                .unwrap_or(0);
            if new_priority > old_priority {
                svc_map.insert(ip, (mac, ip, port));
            }
        } else {
            svc_map.insert(ip, (mac, ip, port));
        }
    }

    svc_map.into_iter()
        .map(|(_, (mac, ip, port))| match ip {
            IpAddr::V4(ip) => (mac, SocketAddr::V4(SocketAddrV4::new(ip, port))),
            IpAddr::V6(ip) => (mac, SocketAddr::V6(SocketAddrV6::new(ip, port, 0, 0)))
        })
        .collect::<_>()
}
/// Filter out duplicit services from a given list using given priorities.
Filter out duplicit services from a given list using given priorities.
Filter out duplicit services from a given list using given priorities .
fn filter_duplicit_services(
    services: &[(MacAddr, SocketAddr)],
    port_priorities: &HashMap<u16, usize>) -> Vec<(MacAddr, SocketAddr)> {
    let mut svc_map = HashMap::new();
    for &(ref mac, ref saddr) in services {
        let mac  = *mac;
        let ip   = saddr.ip();
        let port = saddr.port();
        if svc_map.contains_key(&ip) {
            let old_port = svc_map.get(&ip)
                .map(|&(_, _, ref port)| *port)
                .unwrap_or(0);
            let old_priority = port_priorities.get(&old_port)
                .map(|priority| *priority)
                .unwrap_or(0);
            let new_priority = port_priorities.get(&port)
                .map(|priority| *priority)
                .unwrap_or(0);
            if new_priority > old_priority {
                svc_map.insert(ip, (mac, ip, port));
            }
        } else {
            svc_map.insert(ip, (mac, ip, port));
        }
    }
    svc_map.into_iter()
        .map(|(_, (mac, ip, port))| match ip {
            IpAddr::V4(ip) => (mac, SocketAddr::V4(SocketAddrV4::new(ip, port))),
            IpAddr::V6(ip) => (mac, SocketAddr::V6(SocketAddrV6::new(ip, port, 0, 0)))
        })
        .collect::<_>()
}
fn filter_duplicit_services ( services : & [ ( MacAddr , SocketAddr ) ] , port_priorities : & HashMap < u16 , usize > ) -> Vec < ( MacAddr , SocketAddr ) > { let mut svc_map = HashMap :: new ( ) ; for & ( ref mac , ref saddr ) in services { let mac = * mac ; let ip = saddr . ip ( ) ; let port = saddr . port ( ) ; if svc_map . contains_key ( & ip ) { let old_port = svc_map . get ( & ip ) . map ( | & ( _ , _ , ref port ) | * port ) . unwrap_or ( 0 ) ; let old_priority = port_priorities . get ( & old_port ) . map ( | priority | * priority ) . unwrap_or ( 0 ) ; let new_priority = port_priorities . get ( & port ) . map ( | priority | * priority ) . unwrap_or ( 0 ) ; if new_priority > old_priority { svc_map . insert ( ip , ( mac , ip , port ) ) ; } } else { svc_map . insert ( ip , ( mac , ip , port ) ) ; } } svc_map . into_iter ( ) . map ( | ( _ , ( mac , ip , port ) ) | match ip { IpAddr :: V4 ( ip ) => ( mac , SocketAddr :: V4 ( SocketAddrV4 :: new ( ip , port ) ) ) , IpAddr :: V6 ( ip ) => ( mac , SocketAddr :: V6 ( SocketAddrV6 :: new ( ip , port , 0 , 0 ) ) ) } ) . collect :: < _ > ( ) }
Filter out duplicit services from a given list using given priorities.
Filter out duplicit services from a given list using given priorities .
services
&[(MacAddr, SocketAddr)]
port_priorities
&HashMap<u16, usize>
services
&[(MacAddr, SocketAddr)]
port_priorities
&HashMap<u16, usize>