Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add RingBuffer append and get
  • Loading branch information
doc-jones committed Nov 15, 2019
commit 0bfac59878f5ffe7a307e74bd2f89c12df6b8f6d
9 changes: 7 additions & 2 deletions ring_buffer/ring_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ def __init__(self, capacity):
self.storage = [None]*capacity

def append(self, item):
pass
self.storage[self.current] = item # add an item in-place
self.current = self.current + 1 # move the pointer

if self.current >= self.capacity: # when met return to index 0 - oldest
self.current = 0


def get(self):
pass
return self.storage