Source code for simple_rl.utils.additional_datastructures
''' additional_datastructures.py: File containing custom utility data structures for use in simple_rl. '''
[docs]class SimpleRLStack(object):
''' Implementation for a basic Stack data structure '''
def __init__(self, _list=None):
'''
Args:
_list (list) : underlying elements in the stack
'''
self._list = _list if _list is not None else []
def __repr__(self):
r = ''
for element in self._list:
r += str(element) + ', '
return r
[docs] def push(self, element):
return self._list.append(element)
[docs] def pop(self):
if len(self._list) > 0:
return self._list.pop()
return None
[docs] def peek(self):
if len(self._list) > 0:
return self._list[-1]
return None
[docs] def is_empty(self):
return len(self._list) == 0
[docs] def size(self):
return len(self._list)