Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Readme
XHEAP <https://pypi.python.org/pypi/xheap>
_It's like heapq <https://docs.python.org/3.5/library/heapq.html>
_ (blazingly fast) but object-oriented + more features.
Read more here for the background story <http://srkunze.blogspot.com/2016/01/fast-object-oriented-heap-implementation.html>
_.
Less code.
When you need the smallest item of a large list—fast and with no overhead.
Let's suppose you have a heap, you can use pop
to get its smallest item.
.. code:: python
from xheap import Heap
heap = Heap(['H', 'D', 'B', 'A', 'E', 'C', 'L', 'J', 'I'])
heap.pop() # returns A
heap.pop() # returns B
heap.pop() # returns C
heap.pop() # returns D
Heapsort <https://en.wikipedia.org/wiki/Heapsort>
_ works this way.
Indeed and it's as fast as pop. Use push
for insertion.
.. code:: python
heap = Heap(['A', 'D', 'B', 'H', 'E', 'C', 'L', 'J', 'I'])
heap.push('Z')
Yes, that's what RemovalHeap.remove
is supposed to do.
.. code:: python
from xheap import RemovalHeap
heap = RemovalHeap(['A', 'D', 'B', 'H', 'E', 'C', 'L', 'J', 'I'])
heap.remove('L')
Just imagine two heaps of the very same set of items but you need different sorting for each heap. Or
you need a max-heap instead of a min-heap. That is what OrderHeap
is designed for:
.. code:: python
from xheap import OrderHeap
items = [date(2016, 1, 1), date(2016, 1, 2), date(2016, 1, 3), date(2016, 1, 4)]
day_heap = OrderHeap(items, key=lambda date: date.day)
day_heap.peek() # returns date(2016, 1, 1)
weekday_heap = OrderHeap(items, key=lambda date: date.weekday())
weekday_heap.peek() # returns date(2016, 1, 4)
No problem. Use XHeap
.
If you wonder why there are 4 distinct heap implementations, it's a matter of speed. Each additional feature slows a heap down. Thus, you could always use XHeap but beware of the slowdown.
A heap is just a list. So, if you tinker with it, you can check whether its invariant still holds:
.. code:: python
heap = Heap([4, 3, 7, 6, 1, 2, 9, 8, 5])
heap[3] = 10 # I know what I am doing here
heap.check_invariant() # but better check... ooops
Good
Bad
no drawbacks discovered so far ;-)
needs fix/work:
heapq <https://docs.python.org/3.5/library/heapq.html>
_ideas are welcome :-)
FAQs
Heap Implementation for Python
We found that xheap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.