fn create_node(&mut self, q: &T, nearest: &[Neighbor<Met::Unit>], layer: usize) {
        if layer == 0 {
            let new_index = self.zero.len();
            let mut neighbors: [usize; M0] = [!0; M0];
            for (d, s) in neighbors.iter_mut().zip(nearest.iter()) {
                *d = s.index as usize;
            }
            let node = NeighborNodes { neighbors };
            for neighbor in node.neighbors() {
                self.add_neighbor(q, new_index as usize, neighbor, layer);
            }
            self.zero.push(node);
        } else {
            let new_index = self.layers[layer - 1].len();
            let mut neighbors: [usize; M] = [!0; M];
            for (d, s) in neighbors.iter_mut().zip(nearest.iter()) {
                *d = s.index;
            }
            let node = Node {
                zero_node: self.zero.len(),
                next_node: if layer == 1 {
                    self.zero.len()
                } else {
                    self.layers[layer - 2].len()
                },
                neighbors: NeighborNodes { neighbors },
            };
            for neighbor in node.neighbors() {
                self.add_neighbor(q, new_index, neighbor, layer);
            }
            self.layers[layer - 1].push(node);
        }
    }
/// Creates a new node at a layer given its nearest neighbors in that layer.
/// This contains Algorithm 3 from the paper, but also includes some additional logic.
Creates a new node at a layer given its nearest neighbors in that layer.
This contains Algorithm 3 from the paper, but also includes some additional logic.
Creates a new node at a layer given its nearest neighbors in that layer . This contains Algorithm 3 from the paper but also includes some additional logic .
fn create_node(&mut self, q: &T, nearest: &[Neighbor<Met::Unit>], layer: usize) {
        if layer == 0 {
            let new_index = self.zero.len();
            let mut neighbors: [usize; M0] = [!0; M0];
            for (d, s) in neighbors.iter_mut().zip(nearest.iter()) {
                *d = s.index as usize;
            }
            let node = NeighborNodes { neighbors };
            for neighbor in node.neighbors() {
                self.add_neighbor(q, new_index as usize, neighbor, layer);
            }
            self.zero.push(node);
        } else {
            let new_index = self.layers[layer - 1].len();
            let mut neighbors: [usize; M] = [!0; M];
            for (d, s) in neighbors.iter_mut().zip(nearest.iter()) {
                *d = s.index;
            }
            let node = Node {
                zero_node: self.zero.len(),
                next_node: if layer == 1 {
                    self.zero.len()
                } else {
                    self.layers[layer - 2].len()
                },
                neighbors: NeighborNodes { neighbors },
            };
            for neighbor in node.neighbors() {
                self.add_neighbor(q, new_index, neighbor, layer);
            }
            self.layers[layer - 1].push(node);
        }
    }
fn create_node ( & mut self , q : & T , nearest : & [ Neighbor < Met :: Unit > ] , layer : usize ) { if layer == 0 { let new_index = self . zero . len ( ) ; let mut neighbors : [ usize ; M0 ] = [ ! 0 ; M0 ] ; for ( d , s ) in neighbors . iter_mut ( ) . zip ( nearest . iter ( ) ) { * d = s . index as usize ; } let node = NeighborNodes { neighbors } ; for neighbor in node . neighbors ( ) { self . add_neighbor ( q , new_index as usize , neighbor , layer ) ; } self . zero . push ( node ) ; } else { let new_index = self . layers [ layer - 1 ] . len ( ) ; let mut neighbors : [ usize ; M ] = [ ! 0 ; M ] ; for ( d , s ) in neighbors . iter_mut ( ) . zip ( nearest . iter ( ) ) { * d = s . index ; } let node = Node { zero_node : self . zero . len ( ) , next_node : if layer == 1 { self . zero . len ( ) } else { self . layers [ layer - 2 ] . len ( ) } , neighbors : NeighborNodes { neighbors } , } ; for neighbor in node . neighbors ( ) { self . add_neighbor ( q , new_index , neighbor , layer ) ; } self . layers [ layer - 1 ] . push ( node ) ; } }
Creates a new node at a layer given its nearest neighbors in that layer.
Creates a new node at a layer given its nearest neighbors in that layer .
&mut self
q
&T
nearest
&[Neighbor<Met::Unit>]
layer
usize
&mut self
q
&T
nearest
&[Neighbor<Met::Unit>]
layer
usize