RingBuffer.py 462 Bytes
Newer Older
1
class RingBuffer:
tihmels's avatar
tihmels committed
2 3 4
    """
    Simple fixed-size ringbuffer
    """
5 6 7 8
    def __init__(self, size):
        self.data = [None for i in range(size)]

    def append(self, x):
tihmels's avatar
tihmels committed
9 10 11 12 13
        """
        Append an element
        :param x: the element
        :return:
        """
14 15 16 17
        self.data.pop(0)
        self.data.append(x)

    def get(self):
tihmels's avatar
tihmels committed
18 19 20 21
        """
        return array with elements
        :return: array with elements
        """
Arne Gerdes's avatar
Arne Gerdes committed
22
        return self.data