use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RoomSection {
pub room_id: String,
pub data: Vec<f64>,
pub restriction_maps: Vec<(String, Vec<f64>)>,
}
impl RoomSection {
pub fn new(room_id: impl Into<String>, data: Vec<f64>) -> Self {
Self {
room_id: room_id.into(),
data,
restriction_maps: Vec::new(),
}
}
pub fn with_restriction(mut self, neighbor: impl Into<String>, restricted: Vec<f64>) -> Self {
self.restriction_maps.push((neighbor.into(), restricted));
self
}
pub fn dimension(&self) -> usize {
self.data.len()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SheafSections {
pub sections: Vec<RoomSection>,
}
impl SheafSections {
pub fn new(sections: Vec<RoomSection>) -> Self {
Self { sections }
}
pub fn empty() -> Self {
Self { sections: Vec::new() }
}
pub fn get(&self, room_id: &str) -> Option<&RoomSection> {
self.sections.iter().find(|s| s.room_id == room_id)
}
pub fn get_mut(&mut self, room_id: &str) -> Option<&mut RoomSection> {
self.sections.iter_mut().find(|s| s.room_id == room_id)
}
pub fn room_ids(&self) -> Vec<String> {
self.sections.iter().map(|s| s.room_id.clone()).collect()
}
}