Skip to content

Commit

Permalink
Revert "Switch from list to deque for internal TM tape"
Browse files Browse the repository at this point in the history
This reverts commit 3194bfc.
Deques indeed allow for efficient appendleft operations, however
item access performace is more important.
  • Loading branch information
caleb531 committed Jul 5, 2016
1 parent d44416f commit 4feec4d
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions automata/tm/tape.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python3
"""Classes and methods for working with Turing machine tapes."""

import collections


class TMTape(object):
"""A Turing machine tape."""
Expand All @@ -17,7 +15,7 @@ def __init__(self, tape, **kwargs):
def _init_from_tape_params(self, tape, *, blank_symbol, current_position=0,
position_offset=0):
"""Initialize a TM tape from the defined tape parameters."""
self.tape = collections.deque(tape)
self.tape = list(tape)
self.blank_symbol = blank_symbol
self.current_position = current_position
self.position_offset = position_offset
Expand All @@ -41,7 +39,7 @@ def write_symbol(self, new_tape_symbol):
"""Write the given symbol at the current position in the tape."""
actual_position = self.current_position + self.position_offset
if actual_position == -1:
self.tape.appendleft(new_tape_symbol)
self.tape.insert(0, new_tape_symbol)
self.position_offset += 1
elif actual_position == len(self.tape):
self.tape.append(new_tape_symbol)
Expand Down

0 comments on commit 4feec4d

Please sign in to comment.