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
ring buffer mvp
  • Loading branch information
jrloom committed Mar 27, 2020
commit 03660c82cf84687bb7a773c821e5c927fdf52ea1
29 changes: 28 additions & 1 deletion ring_buffer/ring_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,43 @@ def __init__(self, capacity):
self.storage = DoublyLinkedList()

def append(self, item):
pass
# print(f"cap: {self.capacity} | store: {self.storage.length} | item: {item}")
# if not at cap
if self.storage.length < self.capacity:
# add item
self.storage.add_to_tail(item)
# move older items
self.storage.head.prev = self.storage.tail
self.storage.tail.next = self.storage.head
# set current item to head
self.current = self.storage.head
# if at cap
else:
# set new val to current
self.current.value = item
# move current
self.current = self.current.next

def get(self):
# Note: This is the only [] allowed
list_buffer_contents = []

# TODO: Your code here

current = self.storage.head

while True:
if current.value is not None:
list_buffer_contents.append(current.value)

if current is self.storage.tail:
break

current = current.next

return list_buffer_contents


# ----------------Stretch Goal-------------------


Expand Down