Skip to content

Commit

Permalink
Reuse config on last branch
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Nov 23, 2024
1 parent 66833da commit 7fe9df5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
46 changes: 30 additions & 16 deletions src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,9 @@ impl Configs {
reached.len() == self.seg
}

fn branch(
&mut self,
Config { state, tape, .. }: Config,
prog: &AnalyzedProg,
) {
for &next_state in &prog.diffs[&state] {
let Some(init) = self.check_seen(next_state, &tape) else {
continue;
};

let next_tape = tape.clone();

let config = Config::new(next_state, next_tape, init);

self.add_todo(config);
}
fn branch(&mut self, mut config: Config, prog: &AnalyzedProg) {
let tape = &config.tape;
let state = config.state;

let shift = !tape.side();

Expand All @@ -208,6 +195,33 @@ impl Configs {

self.add_todo(config);
}

let Some((last_next, diffs)) = prog.diffs[&state].split_last()
else {
return;
};

for &next_state in diffs {
let Some(init) = self.check_seen(next_state, tape) else {
continue;
};

let next_tape = tape.clone();

let config = Config::new(next_state, next_tape, init);

self.add_todo(config);
}

if let Some(init) = self.check_seen(*last_next, tape) {
config.state = *last_next;

if init {
config.init = init;
}

self.add_todo(config);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,12 @@ fn test_segment() {
assert_segment_results![
((2, 2), 1, (10, 36)),
//
((3, 2), 1, (1_035, 3_140)),
((3, 2), 1, (1_034, 3_140)),
//
((2, 3), 1, (690, 2_447)),
//
((4, 2), 1, (145_473, 467_142)),
((4, 2), 1, (145_395, 467_142)),
//
((2, 4), 1, (119_092, 312_642)),
((2, 4), 1, (119_027, 312_642)),
];
}
1 change: 0 additions & 1 deletion test/prog_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,6 @@
"1RB ... 1LC 1RA 1LA 0LC",
"1RB 0LB 1LC 1RB ... 1LA",
"1RB 0LC 0LC 1RA ... 1LA",
"1RB 0LC 0RC ... 1LC 0RA",
"1RB 1LC 0LA 0RB 1LA ...",

"1RB 2LA 3RB 0RB 0LB 1LA 2RB ...",
Expand Down

0 comments on commit 7fe9df5

Please sign in to comment.