This commit is contained in:
2025-09-10 13:33:15 +10:00
parent 2c058a654f
commit c41d5487a9
6 changed files with 118 additions and 37 deletions

View File

@@ -23,8 +23,13 @@ impl Grid {
&mut self,
cell_ref: CellRef,
raw_val: String,
do_propagation: bool,
force_propagation: bool,
) -> Result<Vec<CellRef>, String> {
if self.cells.contains_key(&cell_ref) && self.cells[&cell_ref].raw() == raw_val {
if self.cells.contains_key(&cell_ref)
&& self.cells[&cell_ref].raw() == raw_val
&& !force_propagation
{
return Ok(Vec::new());
}
@@ -43,7 +48,14 @@ impl Grid {
if self.cells.contains_key(&cell_ref) {
updated_cells = self
.update_exisiting_cell(raw_val, eval, precs, cell_ref)?
.update_exisiting_cell(
raw_val,
eval,
precs,
cell_ref,
do_propagation,
force_propagation,
)?
.into_iter()
.chain(updated_cells)
.collect();
@@ -156,6 +168,8 @@ impl Grid {
new_eval: Eval,
new_precs: HashSet<CellRef>,
cell_ref: CellRef,
do_propagation: bool,
force_propagation: bool,
) -> Result<Vec<CellRef>, String> {
let (old_precs, old_eval) = match self.cells.get_mut(&cell_ref) {
Some(cell) => {
@@ -197,7 +211,7 @@ impl Grid {
cell.set_precs(new_precs);
cell.set_eval(new_eval);
if eval_changed {
if (eval_changed && do_propagation) || force_propagation {
self.propagate(cell_ref)
} else {
Ok(Vec::new())

View File

@@ -62,8 +62,16 @@ async fn accept_connection(stream: TcpStream) {
MsgType::Set => {
let Some(cell_ref) = req.cell else { continue };
let Some(raw) = req.raw else { continue };
let Some(config) = req.eval_config else {
continue;
};
match grid.update_cell(cell_ref.clone(), raw.to_owned()) {
match grid.update_cell(
cell_ref.clone(),
raw.to_owned(),
config.do_propagation,
config.force_propagation,
) {
Ok(updates) => {
let mut msgs = Vec::new();
@@ -75,6 +83,7 @@ async fn accept_connection(stream: TcpStream) {
raw: Some(cell.raw()),
eval: Some(cell.eval()),
bulk_msgs: None,
eval_config: None,
});
}
}
@@ -88,6 +97,7 @@ async fn accept_connection(stream: TcpStream) {
cell: None,
raw: None,
eval: None,
eval_config: None,
bulk_msgs: Some(msgs),
msg_type: MsgType::Bulk,
};
@@ -103,6 +113,7 @@ async fn accept_connection(stream: TcpStream) {
cell: Some(cell_ref),
raw: Some(e.to_string()),
eval: None,
eval_config: None,
bulk_msgs: None,
};
let _ = write

View File

@@ -11,11 +11,18 @@ pub enum MsgType {
Bulk,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EvalConfig {
pub do_propagation: bool,
pub force_propagation: bool,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LeadMsg {
pub msg_type: MsgType,
pub cell: Option<CellRef>,
pub raw: Option<String>,
pub eval: Option<Eval>,
pub eval_config: Option<EvalConfig>,
pub bulk_msgs: Option<Vec<LeadMsg>>,
}