sorting_race/models/
markers.rs1pub use crate::models::traits::Markers;
7
8impl Markers {
10 pub fn new() -> Self {
12 Self::default()
13 }
14
15 pub fn clear(&mut self) {
17 self.pivot = None;
18 self.heap_boundary = None;
19 self.merge_runs.clear();
20 self.cursors.clear();
21 self.gap = None;
22 }
23
24 pub fn set_pivot(&mut self, index: usize) {
26 self.pivot = Some(index);
27 }
28
29 pub fn clear_pivot(&mut self) {
31 self.pivot = None;
32 }
33
34 pub fn set_heap_boundary(&mut self, boundary: usize) {
36 self.heap_boundary = Some(boundary);
37 }
38
39 pub fn clear_heap_boundary(&mut self) {
41 self.heap_boundary = None;
42 }
43
44 pub fn add_merge_run(&mut self, start: usize, end: usize) {
46 self.merge_runs.push((start, end));
47 }
48
49 pub fn clear_merge_runs(&mut self) {
51 self.merge_runs.clear();
52 }
53
54 pub fn set_cursors(&mut self, positions: Vec<usize>) {
56 self.cursors = positions;
57 }
58
59 pub fn add_cursor(&mut self, position: usize) {
61 self.cursors.push(position);
62 }
63
64 pub fn clear_cursors(&mut self) {
66 self.cursors.clear();
67 }
68
69 pub fn set_gap(&mut self, gap: usize) {
71 self.gap = Some(gap);
72 }
73
74 pub fn clear_gap(&mut self) {
76 self.gap = None;
77 }
78
79 pub fn has_active_markers(&self) -> bool {
81 self.pivot.is_some()
82 || self.heap_boundary.is_some()
83 || !self.merge_runs.is_empty()
84 || !self.cursors.is_empty()
85 || self.gap.is_some()
86 }
87
88 pub fn get_all_positions(&self) -> Vec<usize> {
90 let mut positions = Vec::new();
91
92 if let Some(pivot) = self.pivot {
93 positions.push(pivot);
94 }
95
96 if let Some(boundary) = self.heap_boundary {
97 positions.push(boundary);
98 }
99
100 positions.extend(self.cursors.iter().copied());
101
102 for (start, end) in &self.merge_runs {
103 positions.push(*start);
104 positions.push(*end);
105 }
106
107 positions.sort_unstable();
108 positions.dedup();
109 positions
110 }
111}