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

slight optimization for heap.push_many

parent 828e5888
No related branches found
No related tags found
No related merge requests found
Pipeline #62039 failed with stages
in 1 minute and 22 seconds
# v2.25.5 # v2.25.5
* slight optimization for Heap.push_many
# v2.25.4 # v2.25.4
......
__version__ = '2.25.5a1' __version__ = '2.25.5a2'
...@@ -30,8 +30,17 @@ class Heap(collections.UserList, tp.Generic[T]): ...@@ -30,8 +30,17 @@ class Heap(collections.UserList, tp.Generic[T]):
heapq.heapify(self.data) heapq.heapify(self.data)
def push_many(self, items: tp.Iterable[T]) -> None: def push_many(self, items: tp.Iterable[T]) -> None:
for item in items: """
self.push(item) Put multiple items on the heap.
Faster than
>>> for item in items:
>>> heap.push(item)
:param: an iterable with items to put
"""
self.data.extend(items)
heapq.heapify(self.data)
def pop_item(self, item: T) -> T: def pop_item(self, item: T) -> T:
""" """
......
...@@ -37,6 +37,13 @@ def continue_testing_omni(self, omni_class): ...@@ -37,6 +37,13 @@ def continue_testing_omni(self, omni_class):
class TestStructures(unittest.TestCase): class TestStructures(unittest.TestCase):
def test_heap_bugfix(self):
heap = Heap()
heap.push_many([(1, object()), (2, object())])
item = heap.pop()
self.assertEqual(item[0], 1)
def test_onstronlyname(self): def test_onstronlyname(self):
class MyEnum(OnStrOnlyName, Enum): class MyEnum(OnStrOnlyName, Enum):
......
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