Skip to main content

A double ended priority queue implemented with a min-max-heap

Project description

DepqDict

PyPI version PyPI - Python Version Project Status: Active – The project has reached a stable, usable state and is being actively developed. Ruff License: GPL v3

DepqDict is an efficient double-ended priority queue implemented in Python. It allows efficient retrieval and extraction of the minimum and maximum priority elements, as well as updating priorities of arbitrary elements. Implemented using a min-max heap.

Features

  • Supports both min and max priority queue operations.
  • Efficient push and pop operations for both min and max elements.
  • Allows updating priorities of arbitrary keys.
  • Implements the MutableMapping interface, behaving like a dictionary.

Installation

You can install DepqDict from PyPI using pip:

pip install depqdict

Usage

from depqdict import DepqDict

pq = DepqDict()
pq['task1'] = 5
pq['task2'] = 2
pq['task3'] = 8

print(pq.min_item())  # ('task2', 2)
print(pq.max_item())  # ('task3', 8)

pq['task1'] = 1  # Update priority
print(pq.min_item())  # ('task1', 1)

pq.pop_min_item()  # Removes ('task1', 1)

API with Runtimes

Retrieve Min/Max Items

pq.min_item()  # O(1)
pq.max_item()  # O(1)

Returns the key-value pair with the lowest or highest priority.

Remove Min/Max Items

pq.pop_min_item()  # O(log n)
pq.pop_max_item()  # O(log n)

Removes and returns the key-value pair with the lowest or highest priority.

Push-Pop Operations

pq.push_pop_min_item('task4', 3)  # O(log n)
pq.push_pop_max_item('task5', 9)  # O(log n)

Pushes a new key-priority pair into the queue and returns the smallest or largest item. Faster than using two separate operations.

Insert or Update a Key

pq['task6'] = 4  # O(log n)

Inserts or updates the priority of a key.

Delete a Key

del pq['task3']  # O(log n)

Removes a key from the queue.

License

This project is licensed under the GPL-3.0 License, as it is based on heapdict by Evgeniy Selezniov, which is also licensed under GPL-3.0. See the LICENSE file for details.

Acknowledgments

This package is based on heapdict, originally developed by Evgeniy Selezniov.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

depqdict-0.1.1.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

depqdict-0.1.1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file depqdict-0.1.1.tar.gz.

File metadata

  • Download URL: depqdict-0.1.1.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.4

File hashes

Hashes for depqdict-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0073963c89f15da8e81086222ac4e47a5f22591877fdb73aaf911db293473e1d
MD5 0b9343ee3774915c8c542169b3ad58c8
BLAKE2b-256 5ab00a666363306520dee9b87812ef833eb3dbe9196ac5266779bae0c51733a8

See more details on using hashes here.

File details

Details for the file depqdict-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: depqdict-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.4

File hashes

Hashes for depqdict-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7ac1df4845fb72dcec9fbc53df7d272601ff4e27e552e0c0915fd6249578bb8c
MD5 fe205da91bbb68f200d0f1d903b89bd7
BLAKE2b-256 06799b62d12aa524d2a4cc7a9cef08688a819d11c568479f5043f924b453d142

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page