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

v2.25.5

parent bdfacd06
No related branches found
No related tags found
No related merge requests found
Pipeline #62043 passed with stages
in 1 minute and 43 seconds
# v2.25.5
* slight optimization for Heap.push_many
* bugfix for Heap.push and a deprecation
# v2.25.4
......
__version__ = '2.25.5a2'
__version__ = '2.25.5'
......@@ -7,14 +7,6 @@ from satella.coding.decorators.decorators import wraps
from satella.coding.typing import T, Predicate
def _extras_to_one(fun):
@wraps(fun)
def inner(self, a, *args, **kwargs):
return fun(self, ((a,) + args) if len(args) > 0 else a, **kwargs)
return inner
class Heap(collections.UserList, tp.Generic[T]):
"""
Sane heap as object - not like heapq.
......@@ -52,8 +44,7 @@ class Heap(collections.UserList, tp.Generic[T]):
heapq.heapify(self.data)
return item
@_extras_to_one
def push(self, item: T) -> None:
def push(self, item: T, *args) -> None:
"""
Use it like:
......@@ -62,7 +53,14 @@ class Heap(collections.UserList, tp.Generic[T]):
or:
>>> heap.push(4, myobject)
However this syntax is
.. deprecated:: 2.25.5
It's not legible
"""
if args:
item = (item, *args)
heapq.heappush(self.data, item)
def __deepcopy__(self, memo={}) -> 'Heap':
......@@ -147,6 +145,13 @@ class SetHeap(Heap):
#notthreadsafe
"""
def push_many(self, items: tp.Iterable[T]) -> None:
"""
Not that much faster than inserting anything by hand
"""
for item in items:
self.push(item)
def __init__(self, from_list: tp.Optional[tp.Iterable[T]] = None):
super().__init__(from_list=from_list)
self.set = set(self.data)
......
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