use std::sync::{atomic::Ordering, Arc};
use crate::types::SharedState;
pub fn sorter_thread(app: Arc<SharedState>) {
let mut current_version = 0;
loop {
let matches = app.matches_channel_recv.recv().unwrap();
if matches.is_empty() {
continue;
}
let mut app_matches = app.matches.lock().unwrap();
let actual = app.search_version.load(Ordering::Relaxed);
if current_version < actual {
current_version = actual;
}
if matches[0].version != current_version {
continue;
}
app_matches.reserve(matches.len());
for m in matches.iter() {
let pos = app_matches.binary_search_by_key(&m.lineno, |m| m.lineno);
if let Err(pos) = pos {
app_matches.insert(pos, m.clone());
}
}
}
}