Last active
August 29, 2015 14:25
-
-
Save derricw/c288930547ab82b12549 to your computer and use it in GitHub Desktop.
simple ring buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque as dq | |
class RingBuffer(dq): | |
""" | |
Simple ring buffer. | |
Args: | |
size (int): number of items | |
""" | |
def __init__(self, size): | |
dq.__init__(self) | |
self.size = size | |
self.full = False | |
def append(self,item): | |
dq.append(self,item) | |
if len(self) == self.size: | |
self.append = self.full_append | |
self.full = True | |
def full_append(self,item): | |
dq.append(self,item) | |
self.popleft() | |
def get(self): | |
return list(self) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment