Skip to content

Commit

Permalink
Cut config alignment impl
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Oct 28, 2024
1 parent 9080954 commit 779739e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
28 changes: 9 additions & 19 deletions src/reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,6 @@ struct Config {
prev: Option<Rc<Config>>,
}

impl Alignment for Config {
fn head(&self) -> Pos {
self.tape.head
}

fn aligns_with(
&self,
prev: &Self,
leftmost: Pos,
rightmost: Pos,
) -> bool {
self.state == prev.state
&& self.tape.aligns_with(&prev.tape, leftmost, rightmost)
}
}

impl Config {
const fn new(state: State, tape: Backstepper) -> Self {
Self {
Expand All @@ -65,23 +49,29 @@ impl Config {
}

fn lin_rec(&self) -> bool {
let head = self.head();
let head = self.tape.head();
let mut leftmost = head;
let mut rightmost = head;

let mut current = self.prev.clone();

#[expect(clippy::assigning_clones)]
while let Some(config) = current {
let pos = config.head();
let pos = config.tape.head();

if pos < leftmost {
leftmost = pos;
} else if rightmost < pos {
rightmost = pos;
}

if self.aligns_with(&config, leftmost, rightmost) {
if self.state == config.state
&& self.tape.aligns_with(
&config.tape,
leftmost,
rightmost,
)
{
return true;
}

Expand Down
10 changes: 2 additions & 8 deletions src/tape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,9 @@ impl HeadTape {

pub trait Alignment {
fn head(&self) -> Pos;
fn scan(&self) -> Color;

fn scan(&self) -> Color {
unimplemented!()
}

#[expect(unused_variables)]
fn get_slice(&self, start: Pos, ltr: bool) -> TapeSlice {
unimplemented!()
}
fn get_slice(&self, start: Pos, ltr: bool) -> TapeSlice;

fn aligns_with(
&self,
Expand Down

0 comments on commit 779739e

Please sign in to comment.