Skip to content

Instantly share code, notes, and snippets.

@svalleru
Last active October 16, 2015 19:40
Show Gist options
  • Save svalleru/d90a73214e32ebb0d74a to your computer and use it in GitHub Desktop.
Save svalleru/d90a73214e32ebb0d74a to your computer and use it in GitHub Desktop.
RingBuffer
class RingBuffer:
def __init__(self, size):
self.data = [None for i in xrange(size)]
def append(self, x):
self.data.pop(0)
self.data.append(x)
def get(self):
return self.data
rb = RingBuffer(2)
rb.append('one')
rb.append('two')
print rb.get()
rb.append('three')
print rb.get()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment