Skip to main content

Hipster

Description

Hipster provides a thread-safe implementation of the MinHeap and MaxHeap. Each collection type exposes a simple API to push, pop, peek and clear. 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.heap import *

max_heap = MaxHeap()           # creates an empty max heap
max_heap.push(item)            # pushes a new item on the heap
item = max_heap.peek()         # returns the largest item from the heap without removing it
item = max_heap.pop()          # pops an item off the max heap
max_heap.clear()               # Removes all items from the heap

License

MIT

Changelog

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 2.0.2

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 2.0.2
File Size Uploaded
hipster-2.0.2.tar.gz 2.4 kB Details

Built distribution (wheel)

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

Total release size: 6.0 kB

Release files / hipster-2.0.2.tar.gz

Download URL hipster-2.0.2.tar.gz
Size 2.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b748d882da7111310cc5e6d25991bba5581c3a24c7917bfe768823e9244fd476
BLAKE2b-256 checksum
How to use checksums
e2222f3b1adb7424433162beb62eb0da8974d0e09f82d62bc0d7ebf1ab066405
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-2.0.2-py3-none-any.whl

Download URL hipster-2.0.2-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0944d3b4260f3d4083699407a3540d956f6e673f8b93201cc9397005371e737
BLAKE2b-256 checksum
How to use checksums
6c7c0b74fce5a8ea437239cc87fc49cd401441d0233fbe361f5ee9ff4f77ced7
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 history Release notifications | RSS feed

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

This release

2.0.2 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.6

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.5

2 release files

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