Skip to main content

Hipster [Heap*]

Description

Hipster provides a thread-safe implementation of the MinHeap and MaxHeap. Each collection type exposes a simple API to push, pop, peek, remove, clear and copy. The data structure is built on top of the heapq algorithm.

Object Usage

For adding an object to the heap, the object needs to implement it's comparator logic.

class GitRepo:
    def __init__(self, url, stars, forks):
        self.url = url
        self.stars = stars
        self.forks = forks

    # The object needs to implement the following methods
    def __eq__(self, other):
        return self.name == other.name and self.stars == other.stars and self.forks == other.forks

    def __ne__(self, other):
        return self.name != other.name or self.stars != other.stars or self.forks != other.forks

    def __lt__(self, other):
        # The two repos are first compared based on stars then forks and then sorted lexically based on url
        if self.stars == other.stars and self.forks == other.forks return self.url < other.url

    def __le__(self, other):
        if self.stars == other.stars and self.forks == other.forks return self.url <= other.url

    def __gt__(self, other):
        if self.stars == other.stars and self.forks == other.forks return self.url > other.url

    def __ge__(self, other):
        if self.stars == other.stars and self.forks == other.forks return self.url >= other.url


Dependencies

Python 3

Installation

pip install --upgrade hipster

Usage

from hipster.max_heap import MaxHeap
from hipster.min_heap import MinHeap

max_heap = MaxHeap()           # Creates an empty MaxHeap
max_heap.push(item)            # Pushes a new item on the MaxHeap
item = max_heap.peek()         # Returns the largest item from the heap without removing it, throws HeapError when called on an empty Heap
item = max_heap.pop()          # Pops an item off the MaxHeap, throws HeapError when called on an empty Heap
max_heap.remove(item)          # Removes the item from the heap if its present, or throws HeapError if the item is not present
max_heap.clear()               # Removes all items from the heap
new_heap = max_heap.copy()     # Copies all items to the new heap


min_heap = MinHeap()           # Creates an empty MinHeap
min_heap.push(item)            # Pushes a new item on the MinHeap
item = min_heap.peek()         # Returns the samllest item from the heap without removing it, throws HeapError when called on an empty Heap
item = min_heap.pop()          # Pops an item off the MinHeap, throws HeapError when called on an empty Heap
min_heap.remove(item)          # Removes the item from the heap if its present, or throws HeapError if the item is not present
min_heap.clear()               # Removes all items from the heap
new_heap = max_heap.copy()     # Copies all items to the new heap

License

MIT

Changelog

3.0.4

Fixed a bug with the copy method

3.0.3

Added copy method

3.0.1

Fixed a bug with thread safety on remove

3.0.0

Added remove, refactored duplicated code to base class, added more tests, updated README

2.0.2

fixed README

2.0.1

Updated object usage example, updated README

2.0.0

Added thread safety, added more tests

Metadata

Release files for hipster 3.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hipster 3.0.4
File Size Uploaded Provenance Actions
hipster-3.0.4.tar.gz 3.0 kB Without provenance Details for hipster-3.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hipster 3.0.4
File Interpreter ABI Platform Actions
hipster-3.0.4-py3-none-any.whl Python 3 none any Details for hipster-3.0.4-py3-none-any.whl

Total release size: 7.6 kB

Release files / hipster-3.0.4.tar.gz

Download URL hipster-3.0.4.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
02f206cc485516becd2091315119abad2f18a22f4529c9a0bc048302ce610f96
BLAKE2b-256 checksum
How to use checksums
817b6c7c29165572f3a52e2442b1e9f07863de078eba2b3c642bdcdd460e119c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.5rc1

Release files / hipster-3.0.4-py3-none-any.whl

Download URL hipster-3.0.4-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c7f49f03afacc04c9922d5f7c7913202082de06636c2c1c151658886ae00a6a
BLAKE2b-256 checksum
How to use checksums
51b315f2454a5b06e5bc33b9fe3d34bfe2720c201c9bdf7594652266ecef3789
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.5rc1

Security for hipster 3.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page