pub use crate::models::traits::Markers;
impl Markers {
pub fn new() -> Self {
Self::default()
}
pub fn clear(&mut self) {
self.pivot = None;
self.heap_boundary = None;
self.merge_runs.clear();
self.cursors.clear();
self.gap = None;
}
pub fn set_pivot(&mut self, index: usize) {
self.pivot = Some(index);
}
pub fn clear_pivot(&mut self) {
self.pivot = None;
}
pub fn set_heap_boundary(&mut self, boundary: usize) {
self.heap_boundary = Some(boundary);
}
pub fn clear_heap_boundary(&mut self) {
self.heap_boundary = None;
}
pub fn add_merge_run(&mut self, start: usize, end: usize) {
self.merge_runs.push((start, end));
}
pub fn clear_merge_runs(&mut self) {
self.merge_runs.clear();
}
pub fn set_cursors(&mut self, positions: Vec<usize>) {
self.cursors = positions;
}
pub fn add_cursor(&mut self, position: usize) {
self.cursors.push(position);
}
pub fn clear_cursors(&mut self) {
self.cursors.clear();
}
pub fn set_gap(&mut self, gap: usize) {
self.gap = Some(gap);
}
pub fn clear_gap(&mut self) {
self.gap = None;
}
pub fn has_active_markers(&self) -> bool {
self.pivot.is_some()
|| self.heap_boundary.is_some()
|| !self.merge_runs.is_empty()
|| !self.cursors.is_empty()
|| self.gap.is_some()
}
pub fn get_all_positions(&self) -> Vec<usize> {
let mut positions = Vec::new();
if let Some(pivot) = self.pivot {
positions.push(pivot);
}
if let Some(boundary) = self.heap_boundary {
positions.push(boundary);
}
positions.extend(self.cursors.iter().copied());
for (start, end) in &self.merge_runs {
positions.push(*start);
positions.push(*end);
}
positions.sort_unstable();
positions.dedup();
positions
}
}