diff --git a/CHANGELOG.md b/CHANGELOG.md index f0e1359e9ec8f8b12d14e1339185a11a8ead0d2e..74314ef9fdfd9e923b2bfb4ce51e7b03103c749d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # v2.25.5 - +* slight optimization for Heap.push_many # v2.25.4 diff --git a/satella/__init__.py b/satella/__init__.py index 73e64ddf45815a3fd3d939e9de5863e97213dfd4..3406069a523a8431c21a9f52b6be3025aed750f2 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.25.5a1' +__version__ = '2.25.5a2' diff --git a/satella/coding/structures/heaps/base.py b/satella/coding/structures/heaps/base.py index 745fca71039bbdb6b9c03d86cab63f919f602589..6d25f107999a3f20795c5370c6822d7c9d42ef7d 100644 --- a/satella/coding/structures/heaps/base.py +++ b/satella/coding/structures/heaps/base.py @@ -30,8 +30,17 @@ class Heap(collections.UserList, tp.Generic[T]): heapq.heapify(self.data) 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: """ diff --git a/tests/test_coding/test_structures.py b/tests/test_coding/test_structures.py index 40526c1326d1a2b3464ae9102d106b3613601dce..bb01d1b3db6c4b74ece687bb5756eff63c057e51 100644 --- a/tests/test_coding/test_structures.py +++ b/tests/test_coding/test_structures.py @@ -37,6 +37,13 @@ def continue_testing_omni(self, omni_class): 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): class MyEnum(OnStrOnlyName, Enum):