Skip to content
Snippets Groups Projects
Commit 1efb5948 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

heap fix

parent 48285374
No related branches found
No related tags found
No related merge requests found
......@@ -184,20 +184,6 @@ class Heap(object):
while heap:
yield heapq.heappop(heap)
@returns_iterable
def pop_less_than(self, less):
"""
Return all elements less (sharp inequality) than particular value.
This changes state of the heap
:param less: value to compare against
:return: Iterator
"""
while self:
if self.heap[0] < less:
return
yield self.pop()
@returns_iterable
def iter_descending(self):
"""
......@@ -254,16 +240,21 @@ class TimeBasedHeap(Heap):
:param timestamp: timestamp for this item
:param item: object
"""
self.push(timestamp, item)
self.push((timestamp, item))
def pop_less_than(self, timestamp):
@returns_iterable
def pop_less_than(self, less):
"""
Return a list of items with timestamps less than your value.
Return all elements less (sharp inequality) than particular value.
Items will be removed from heap
:return: list of tuple(timestamp::float, item)
This changes state of the heap
:param less: value to compare against
:return: Iterator
"""
return list(Heap.pop_less_than(self, timestamp))
while self:
if self.heap[0] < less:
return
yield self.pop()
def remove(self, item):
"""
......
......@@ -23,6 +23,13 @@ class TestTimeBasedHeap(unittest.TestCase):
class TestHeap(unittest.TestCase):
def test_push(self):
tbh = Heap()
tbh.push(10, 'A')
self.assertEquals((10, 'A'), tbh.pop())
tbh.push((10, 'A'))
self.assertEquals((10, 'A'), tbh.pop())
def test_tbh_iter(self):
tbh = Heap()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment