use std::any::Any;
use std::fmt::Debug;
#[derive(Debug, Clone, PartialEq)]
pub struct StepResult {
pub comparisons_used: usize,
pub moves_made: usize,
pub continued: bool,
}
#[derive(Debug, Clone, Default)]
pub struct Markers {
pub pivot: Option<usize>,
pub heap_boundary: Option<usize>,
pub merge_runs: Vec<(usize, usize)>,
pub cursors: Vec<usize>,
pub gap: Option<usize>,
}
#[derive(Debug, Clone)]
pub struct Telemetry {
pub total_comparisons: u64,
pub total_moves: u64,
pub memory_current: usize,
pub memory_peak: usize,
pub highlights: Vec<usize>,
pub markers: Markers,
pub status_text: String,
pub progress_hint: f32,
}
pub trait Sorter: Debug + Send + Any {
fn step(&mut self, budget: usize) -> StepResult;
fn is_complete(&self) -> bool;
fn get_telemetry(&self) -> Telemetry;
fn reset(&mut self, data: Vec<i32>);
fn name(&self) -> &str;
fn get_array(&self) -> &[i32];
fn get_memory_usage(&self) -> usize;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}
pub trait FairnessModel: Debug {
fn allocate_budget(&self, algorithms: &[Box<dyn Sorter>]) -> Vec<usize>;
fn name(&self) -> &str;
}
pub trait MemoryTracker: Debug {
fn alloc(&mut self, bytes: usize);
fn free(&mut self, bytes: usize);
fn current(&self) -> usize;
fn peak(&self) -> usize;
fn reset(&mut self);
}