fn search_single_layer(
        &self,
        q: &T,
        searcher: &mut Searcher<Met::Unit>,
        layer: &[Node<M>],
        cap: usize,
    ) {
        while let Some(Neighbor { index, .. }) = searcher.candidates.pop() {
            for neighbor in layer[index as usize].neighbors() {
                let neighbor_node = &layer[neighbor as usize];
                // Don't visit previously visited things. We use the zero node to allow reusing the seen filter
                // across all layers since zero nodes are consistent among all layers.
                // TODO: Use Cuckoo Filter or Bloom Filter to speed this up/take less memory.
                if searcher.seen.insert(neighbor_node.zero_node) {
                    // Compute the distance of this neighbor.
                    let distance = self
                        .metric
                        .distance(q, &self.features[neighbor_node.zero_node as usize]);
                    // Attempt to insert into nearest queue.
                    let pos = searcher.nearest.partition_point(|n| n.distance <= distance);
                    if pos != cap {
                        // It was successful. Now we need to know if its full.
                        if searcher.nearest.len() == cap {
                            // In this case remove the worst item.
                            searcher.nearest.pop();
                        }
                        // Either way, add the new item.
                        let candidate = Neighbor {
                            index: neighbor as usize,
                            distance,
                        };
                        searcher.nearest.insert(pos, candidate);
                        searcher.candidates.push(candidate);
                    }
                }
            }
        }
    }
/// Greedily finds the approximate nearest neighbors to `q` in a non-zero layer.
/// This corresponds to Algorithm 2 in the paper.
Greedily finds the approximate nearest neighbors to `q` in a non-zero layer.
This corresponds to Algorithm 2 in the paper.
Greedily finds the approximate nearest neighbors to ` q ` in a non - zero layer . This corresponds to Algorithm 2 in the paper .
fn search_single_layer(
        &self,
        q: &T,
        searcher: &mut Searcher<Met::Unit>,
        layer: &[Node<M>],
        cap: usize,
    ) {
        while let Some(Neighbor { index, .. }) = searcher.candidates.pop() {
            for neighbor in layer[index as usize].neighbors() {
                let neighbor_node = &layer[neighbor as usize];
                // Don't visit previously visited things. We use the zero node to allow reusing the seen filter
                // across all layers since zero nodes are consistent among all layers.
                // TODO: Use Cuckoo Filter or Bloom Filter to speed this up/take less memory.
                if searcher.seen.insert(neighbor_node.zero_node) {
                    // Compute the distance of this neighbor.
                    let distance = self
                        .metric
                        .distance(q, &self.features[neighbor_node.zero_node as usize]);
                    // Attempt to insert into nearest queue.
                    let pos = searcher.nearest.partition_point(|n| n.distance <= distance);
                    if pos != cap {
                        // It was successful. Now we need to know if its full.
                        if searcher.nearest.len() == cap {
                            // In this case remove the worst item.
                            searcher.nearest.pop();
                        }
                        // Either way, add the new item.
                        let candidate = Neighbor {
                            index: neighbor as usize,
                            distance,
                        };
                        searcher.nearest.insert(pos, candidate);
                        searcher.candidates.push(candidate);
                    }
                }
            }
        }
    }
fn search_single_layer ( & self , q : & T , searcher : & mut Searcher < Met :: Unit > , layer : & [ Node < M > ] , cap : usize , ) { while let Some ( Neighbor { index , .. } ) = searcher . candidates . pop ( ) { for neighbor in layer [ index as usize ] . neighbors ( ) { let neighbor_node = & layer [ neighbor as usize ] ; // Don't visit previously visited things. We use the zero node to allow reusing the seen filter // across all layers since zero nodes are consistent among all layers. // TODO: Use Cuckoo Filter or Bloom Filter to speed this up/take less memory. if searcher . seen . insert ( neighbor_node . zero_node ) { // Compute the distance of this neighbor. let distance = self . metric . distance ( q , & self . features [ neighbor_node . zero_node as usize ] ) ; // Attempt to insert into nearest queue. let pos = searcher . nearest . partition_point ( | n | n . distance <= distance ) ; if pos != cap { // It was successful. Now we need to know if its full. if searcher . nearest . len ( ) == cap { // In this case remove the worst item. searcher . nearest . pop ( ) ; } // Either way, add the new item. let candidate = Neighbor { index : neighbor as usize , distance , } ; searcher . nearest . insert ( pos , candidate ) ; searcher . candidates . push ( candidate ) ; } } } } }
Greedily finds the approximate nearest neighbors to `q` in a non-zero layer.
Greedily finds the approximate nearest neighbors to ` q ` in a non - zero layer .
&self
q
&T
searcher
&mut Searcher<Met::Unit>
layer
&[Node<M>]
cap
usize
&self
q
&T
searcher
&mut Searcher<Met::Unit>
layer
&[Node<M>]
cap
usize