Skip to main content

pytreemap Build Status codecov

Python implementation of the Java TreeMap/Tree.

Installation

Install with pip:

pip install pytreemap

Documentation

Click here to access the documentation

Basic Usage

This demo aims to show you the basic operations available in this package. Consult the documentation for more details.

Import and instantiate

>>> from pytreemap import TreeMap
>>> tm = TreeMap()

Insert key-value mappings

>>> tm[5] = 'Python is great!'
>>> print(tm)
{5=Python is great!}
>>> tm[10] = 'Java is also nice!'
>>> print(tm)
{5=Python is great!, 10=Java is also nice!}
>>> tm.put(-1,  'We love them both!')
>>> print(tm)
{-1=We love them both!, 5=Python is great!, 10=Java is also nice!}

Search for keys

>>> tm[5]
'Python is great!'
>>> tm[2]
KeyError: 'key not found'
>>> tm.get(2)  # No error is raised

Delete key-value mappings

>>> del tm[10]
>>> print(tm)
{-1=We love them both!, 5=Python is great!}
>>> del tm[2]
KeyError: 'key not found'
>>> tm.remove(2)  # No error is raised

Check whether some keys exist

>>> 2 in tm
False
>>> -1 in tm
True
>>> tm.contains_key(-1)
True

Iterate over keys/values/entries

>>> [key for key in tm]
[-1, 5]
>>> [key for key in tm.key_set()]
[-1, 5]
>>> [value for value in tm.values()]
['We love them both!', 'Python is great!']
>>> [entry for entry in tm.entry_set()]
[-1=We love them both!, 5=Python is great!]

Testing

Most of the tests from Java that concerned TreeMap are passed. Check out the tests/ directory for more details.

Benchmarks

All benchmarks are done on a laptop with Intel Core i7-7700HQ CPU and 16GB of RAM.

Since this package is an implementation of the Java TreeMap, the benchmarks are focused on comparing the performance between this package and Java’s TreeMap.

This package is currently written in pure Python and it should come at no surprise that it is much slower than Java, especially when the size of the tree is large.

A Cython version is in the works.

Benchmark procedure:

  1. Prepare n entries with distinct keys. (n ranges from 1000 to 60000 with 1000 interval.)

  2. Insert/Remove/Search them into the map in random order and record the completion time.

  3. Repeat step 1-2 two more times and average the result.

Here is result using Java TreeMap:

And here is the result using pytreemap:

Overlay the plots together, we can see that pytreemap is ~30x slower:

Metadata

Release files for pytreemap 0.6

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

Source distribution (sdist)

Source distribution for pytreemap 0.6
File Size Uploaded Provenance
pytreemap-0.6.tar.gz 22.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 55.2 kB

Release files / pytreemap-0.6.tar.gz

Download URL pytreemap-0.6.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
978af6c477a319bace967a4f8f0739ee22da9d8889ba3b8a94923c0aeb5ee900
BLAKE2b-256 checksum
How to use checksums
aae93721fab3eac7641fa204e68ba2f43aa70e5c915042713421b142c1bd8e49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.1

Release files / pytreemap-0.6-py3-none-any.whl

Download URL pytreemap-0.6-py3-none-any.whl
Size 32.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9824d7406ba6158ee9877bf8d7651504565beff5a9ccca1a77d9eed41874faba
BLAKE2b-256 checksum
How to use checksums
fee57b129586595894a6118dd0014d674561fc932394dd532881ad0ab19a15b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.1

Security for pytreemap 0.6

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