Skip to main content

Python implementation of treaps

Project description

A set of python modules implementing treaps in pure python is provided.

See also my pyx_treap module, which implements treaps in Cython.

Treaps perform most operations in O(log2(n)) time, and are innately sorted. They’re very nice for keeping a collection of values that needs to always be sorted, or for optimization problems in which you need to find the p best values out of q, when p is much smaller than q.

A module is provided for treaps that enforce uniqueness.

Example use: .. code-block:: python

>>> import treap
>>> t = treap.treap()
>>> for i in range(6):
...     t[i] = 2**i
...
>>> list(t)
[0, 1, 2, 3, 4, 5]
>>> print(t)
0                                                         5/319487918/32_
1                         2/861020069/4__                                                 _______________
2         1/1135044777/2_                 3/1142319761/8_                 _______________                 _______________
3 0/1473918015/1_ _______________ _______________ 4/2019165697/16 _______________ _______________ _______________ _______________
>>> list(t.items())
[(0, 1), (1, 2), (2, 4), (3, 8), (4, 16), (5, 32)]
>>>

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

treap-2.0.8.tar.gz (8.1 kB view details)

Uploaded Source

File details

Details for the file treap-2.0.8.tar.gz.

File metadata

  • Download URL: treap-2.0.8.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.9

File hashes

Hashes for treap-2.0.8.tar.gz
Algorithm Hash digest
SHA256 0a8877836bde779c24f42934d468f8a3857f7b1a645059e1704cb5cc100db12c
MD5 07a19d38c857d7084be5feb6dd7c9f3b
BLAKE2b-256 66f5c26e7e8326645597be6137c00bcb9926f17da1f6ae9de02fca9ce1d8dd4e

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