pub fn closest(&self, from: Rc<Route<ID>>, to: &HashSet<ID>) -> Option<Rc<Route<ID>>> {
        let mut visited = HashSet::new();
        let mut routes = Vec::new();
        routes.push(from);
        loop {
            let c_route = routes.pop()?;
            
            if to.contains(&c_route.pos) {
                return Some(c_route);
            }

            if visited.contains(&c_route.pos) {
                continue;
            }

            visited.insert(c_route.pos.clone());
            let exits = self.data.get(&c_route.pos)?;

            for eid in &exits.1 {
                let edge = self.edges.get(eid)?;
                let npos = if edge.1 == c_route.pos {
                    edge.2.clone()
                } else {
                    edge.1.clone()
                };
                let nlen = c_route.len + edge.0.weight();
                let nroute = Rc::new(Route{
                    pos: npos,
                    len: nlen,
                    path: Some(c_route.clone()), 
                });

                if routes.len() == 0 {
                    routes.push(nroute);
                    continue;
                }

                let mut iafer = routes.len() - 1;
                loop {
                    if routes[iafer].len > nlen {
                        routes.insert(iafer+1, nroute);
                        break;
                    }
                    if iafer == 0 {
                        routes.insert(0, nroute);
                        break;
                    }
                    iafer -= 1;
                }
            }
        }
    }
// modified to use hashset and direct route
modified to use hashset and direct route
modified to use hashset and direct route
pub fn closest(&self, from: Rc<Route<ID>>, to: &HashSet<ID>) -> Option<Rc<Route<ID>>> {
        let mut visited = HashSet::new();
        let mut routes = Vec::new();
        routes.push(from);
        loop {
            let c_route = routes.pop()?;
            if to.contains(&c_route.pos) {
                return Some(c_route);
            }
            if visited.contains(&c_route.pos) {
                continue;
            }
            visited.insert(c_route.pos.clone());
            let exits = self.data.get(&c_route.pos)?;
            for eid in &exits.1 {
                let edge = self.edges.get(eid)?;
                let npos = if edge.1 == c_route.pos {
                    edge.2.clone()
                } else {
                    edge.1.clone()
                };
                let nlen = c_route.len + edge.0.weight();
                let nroute = Rc::new(Route{
                    pos: npos,
                    len: nlen,
                    path: Some(c_route.clone()), 
                });
                if routes.len() == 0 {
                    routes.push(nroute);
                    continue;
                }
                let mut iafer = routes.len() - 1;
                loop {
                    if routes[iafer].len > nlen {
                        routes.insert(iafer+1, nroute);
                        break;
                    }
                    if iafer == 0 {
                        routes.insert(0, nroute);
                        break;
                    }
                    iafer -= 1;
                }
            }
        }
    }
pub fn closest ( & self , from : Rc < Route < ID > > , to : & HashSet < ID > ) -> Option < Rc < Route < ID > > > { let mut visited = HashSet :: new ( ) ; let mut routes = Vec :: new ( ) ; routes . push ( from ) ; loop { let c_route = routes . pop ( ) ? ; if to . contains ( & c_route . pos ) { return Some ( c_route ) ; } if visited . contains ( & c_route . pos ) { continue ; } visited . insert ( c_route . pos . clone ( ) ) ; let exits = self . data . get ( & c_route . pos ) ? ; for eid in & exits . 1 { let edge = self . edges . get ( eid ) ? ; let npos = if edge . 1 == c_route . pos { edge . 2 . clone ( ) } else { edge . 1 . clone ( ) } ; let nlen = c_route . len + edge . 0 . weight ( ) ; let nroute = Rc :: new ( Route { pos : npos , len : nlen , path : Some ( c_route . clone ( ) ) , } ) ; if routes . len ( ) == 0 { routes . push ( nroute ) ; continue ; } let mut iafer = routes . len ( ) - 1 ; loop { if routes [ iafer ] . len > nlen { routes . insert ( iafer + 1 , nroute ) ; break ; } if iafer == 0 { routes . insert ( 0 , nroute ) ; break ; } iafer -= 1 ; } } } }
modified to use hashset and direct route
modified to use hashset and direct route
&self
from
Rc<Route<ID>>
to
&HashSet<ID>
&self
from
Rc<Route<ID>>
to
&HashSet<ID>