Rework reading from device and clean up.

This commit is contained in:
Olivia Brooks
2025-12-29 11:02:13 -05:00
parent 824d01be95
commit e08e2a0017
10 changed files with 628 additions and 536 deletions

56
src/mapping/cluster.rs Normal file
View File

@@ -0,0 +1,56 @@
use super::{Domain, Stage};
use serde::{Deserialize, Serialize};
/// A map for data stored in memory for processing and saving to disk.
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
pub struct Cluster {
pub domain: Domain,
pub stage: Stage,
}
impl Default for Cluster {
fn default() -> Self {
Cluster {
domain: Domain::default(),
stage: Stage::default(),
}
}
}
impl Cluster {
/// Breaks apart into a vec of clusters,
/// each of cluster_size, excepting last.
pub fn subdivide(&mut self, cluster_len: usize) -> Vec<Cluster> {
let domain_len = self.domain.len();
let mut start = self.domain.start;
let mut clusters: Vec<Cluster> = vec![];
for _ in 0..(domain_len / cluster_len) {
clusters.push(Cluster {
domain: Domain {
start,
end: start + cluster_len,
},
stage: self.stage,
});
start += cluster_len;
}
clusters.push(Cluster {
domain: Domain {
start,
end: self.domain.end,
},
stage: self.stage,
});
clusters
}
pub fn set_stage(&mut self, stage: Stage) -> &mut Self {
self.stage = stage;
self
}
}