diff --git a/src/tinySelf/shared/arrays.py b/src/tinySelf/shared/arrays.py index 52e90fe..7b5c76a 100644 --- a/src/tinySelf/shared/arrays.py +++ b/src/tinySelf/shared/arrays.py @@ -4,7 +4,7 @@ class TwoPointerArray(object): def __init__(self, length): - self._length = length + self._allocated_length = length self._array = [None for _ in xrange(length)] self._left_pointer = 0 self._right_pointer = 0 @@ -13,6 +13,9 @@ def __len__(self): return self._right_pointer - self._left_pointer def __getitem__(self, index): + if index >= self._right_pointer: + raise IndexError() + return self._array[self._left_pointer + index] def __setitem__(self, key, value): @@ -37,10 +40,10 @@ def pop_last(self): return rval def append(self, item): - if self._right_pointer >= self._length: + if self._right_pointer >= self._allocated_length: self._array.append(item) self._right_pointer += 1 - self._length += 1 + self._allocated_length += 1 return self._array[self._right_pointer] = item