use std::collections::BinaryHeap;
use crate::common::fixed_length_priority_queue::FixedLengthPriorityQueue;
use crate::common::types::{ScoreType, ScoredPointOffset};
use num_traits::float::FloatCore;
pub struct SearchContext {
pub nearest: FixedLengthPriorityQueue<ScoredPointOffset>,
pub candidates: BinaryHeap<ScoredPointOffset>,
}
impl SearchContext {
pub fn new(ef: usize) -> Self {
SearchContext {
nearest: FixedLengthPriorityQueue::new(ef),
candidates: BinaryHeap::new(),
}
}
pub fn lower_bound(&self) -> ScoreType {
match self.nearest.top() {
None => ScoreType::min_value(),
Some(worst_of_the_best) => worst_of_the_best.score,
}
}
pub fn process_candidate(&mut self, score_point: ScoredPointOffset) {
let was_added = match self.nearest.push(score_point) {
None => true,
Some(removed) => removed.idx != score_point.idx,
};
if was_added {
self.candidates.push(score_point);
}
}
}