use crate::fact::MemoFact;
use crate::scoring::ScoringEngine;

/// Evict the lowest-scored facts from a list, keeping `keep_top` entries.
pub fn evict_to_limit(facts: &mut Vec<MemoFact>, keep_top: usize) {
    if facts.len() <= keep_top {
        return;
    }
    facts.sort_by(|a, b| {
        ScoringEngine::score(b)
            .partial_cmp(&ScoringEngine::score(a))
            .unwrap()
    });
    facts.truncate(keep_top);
}
