fn search_zero_layer(&self, q: &T, searcher: &mut Searcher<Met::Unit>, cap: usize) {
        while let Some(Neighbor { index, .. }) = searcher.candidates.pop() {
            for neighbor in self.zero[index as usize].neighbors() {
                // 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) {
                    // Compute the distance of this neighbor.
                    let distance = self.metric.distance(q, &self.features[neighbor 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 the zero layer.
Greedily finds the approximate nearest neighbors to `q` in the zero layer.
Greedily finds the approximate nearest neighbors to ` q ` in the zero layer .
fn search_zero_layer(&self, q: &T, searcher: &mut Searcher<Met::Unit>, cap: usize) {
        while let Some(Neighbor { index, .. }) = searcher.candidates.pop() {
            for neighbor in self.zero[index as usize].neighbors() {
                // 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) {
                    // Compute the distance of this neighbor.
                    let distance = self.metric.distance(q, &self.features[neighbor 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_zero_layer ( & self , q : & T , searcher : & mut Searcher < Met :: Unit > , cap : usize ) { while let Some ( Neighbor { index , .. } ) = searcher . candidates . pop ( ) { for neighbor in self . zero [ index as usize ] . neighbors ( ) { // 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 ) { // Compute the distance of this neighbor. let distance = self . metric . distance ( q , & self . features [ neighbor 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 the zero layer.
Greedily finds the approximate nearest neighbors to ` q ` in the zero layer .
&self
q
&T
searcher
&mut Searcher<Met::Unit>
cap
usize
&self
q
&T
searcher
&mut Searcher<Met::Unit>
cap
usize