# pytreemap [![Build Status](https://travis-ci.com/GavinPHR/pytreemap.svg?branch=master)](https://travis-ci.com/GavinPHR/pytreemap) [![codecov](https://codecov.io/gh/GavinPHR/pytreemap/branch/master/graph/badge.svg)](https://codecov.io/gh/GavinPHR/pytreemap) ![](https://img.shields.io/pypi/v/pytreemap) ![](https://img.shields.io/badge/python-%3E%3D3.5-blue) ![](https://img.shields.io/github/license/GavinPHR/pytreemap)
Python implementation of the Java TreeMap/Tree.
- [Installation](#installation)
- [Documentation](#documentation)
- [Basic Usage](#basic-usage)
- [Testings](#testing)
- [Benchmarks](#benchmarks)
## Installation
Install with pip:
```bash
pip install pytreemap
```
## Documentation
[Click here to access the documentation](https://gavinphr.github.io/pytreemap/)
## Basic Usage
This demo aims to show you the basic operations available in this package.
Consult the [documentation]((https://gavinphr.github.io/pytreemap/)) for more details.
### Import and instantiate
```python
>>> from pytreemap import TreeMap
>>> tm = TreeMap()
```
### Insert key-value mappings
```python
>>> 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
```python
>>> tm[5]
'Python is great!'
>>> tm[2]
KeyError: 'key not found'
>>> tm.get(2) # No error is raised
```
### Delete key-value mappings
```python
>>> 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
```python
>>> 2 in tm
False
>>> -1 in tm
True
>>> tm.contains_key(-1)
True
```
### Iterate over keys/values/entries
```python
>>> [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:
<p align="center">
<img src="https://raw.githubusercontent.com/GavinPHR/pytreemap/master/benchmarks/java.png" width="450"/>
</p>
And here is the result using pytreemap:
<p align="center">
<img src="https://raw.githubusercontent.com/GavinPHR/pytreemap/master/benchmarks/pytreemap.png" width="450"/>
</p>
Overlay the plots together, we can see that pytreemap is ~30x slower:
<p align="center">
<img src="https://raw.githubusercontent.com/GavinPHR/pytreemap/master/benchmarks/java_vs_pytreemap.png" width="450"/>
</p>
Raw data
{
"_id": null,
"home_page": "https://github.com/GavinPHR/pytreemap",
"name": "pytreemap",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": null,
"keywords": "python3, self-balancing, binary-search-tree, red-black-tree, java, treemap, treeset",
"author": null,
"author_email": "gavinsweden@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/aa/e9/3721fab3eac7641fa204e68ba2f43aa70e5c915042713421b142c1bd8e49/pytreemap-0.6.tar.gz",
"platform": null,
"description": "# pytreemap [![Build Status](https://travis-ci.com/GavinPHR/pytreemap.svg?branch=master)](https://travis-ci.com/GavinPHR/pytreemap) [![codecov](https://codecov.io/gh/GavinPHR/pytreemap/branch/master/graph/badge.svg)](https://codecov.io/gh/GavinPHR/pytreemap) ![](https://img.shields.io/pypi/v/pytreemap) ![](https://img.shields.io/badge/python-%3E%3D3.5-blue) ![](https://img.shields.io/github/license/GavinPHR/pytreemap)\nPython implementation of the Java TreeMap/Tree.\n\n - [Installation](#installation)\n - [Documentation](#documentation)\n - [Basic Usage](#basic-usage)\n - [Testings](#testing)\n - [Benchmarks](#benchmarks)\n\n## Installation\n\nInstall with pip:\n\n```bash\npip install pytreemap\n```\n\n## Documentation\n[Click here to access the documentation](https://gavinphr.github.io/pytreemap/)\n\n## Basic Usage\n\nThis demo aims to show you the basic operations available in this package.\nConsult the [documentation]((https://gavinphr.github.io/pytreemap/)) for more details.\n\n### Import and instantiate\n\n```python\n>>> from pytreemap import TreeMap\n>>> tm = TreeMap()\n```\n \n### Insert key-value mappings\n\n```python\n>>> tm[5] = 'Python is great!'\n>>> print(tm)\n{5=Python is great!}\n>>> tm[10] = 'Java is also nice!'\n>>> print(tm)\n{5=Python is great!, 10=Java is also nice!}\n>>> tm.put(-1, 'We love them both!')\n>>> print(tm)\n{-1=We love them both!, 5=Python is great!, 10=Java is also nice!}\n```\n\n### Search for keys\n\n```python\n>>> tm[5]\n'Python is great!'\n>>> tm[2]\nKeyError: 'key not found'\n>>> tm.get(2) # No error is raised\n```\n\n### Delete key-value mappings\n\n```python\n>>> del tm[10]\n>>> print(tm)\n{-1=We love them both!, 5=Python is great!}\n>>> del tm[2]\nKeyError: 'key not found'\n>>> tm.remove(2) # No error is raised\n```\n\n### Check whether some keys exist\n\n```python\n>>> 2 in tm\nFalse\n>>> -1 in tm\nTrue\n>>> tm.contains_key(-1)\nTrue\n```\n\n### Iterate over keys/values/entries\n\n```python\n>>> [key for key in tm]\n[-1, 5]\n>>> [key for key in tm.key_set()]\n[-1, 5]\n>>> [value for value in tm.values()]\n['We love them both!', 'Python is great!']\n>>> [entry for entry in tm.entry_set()]\n[-1=We love them both!, 5=Python is great!]\n```\n\n## Testing \nMost of the tests from Java that concerned TreeMap are passed. Check out the tests/ directory for more details.\n\n## Benchmarks\nAll benchmarks are done on a laptop with Intel Core i7-7700HQ CPU and 16GB of RAM.\n\nSince this package is an implementation of the Java TreeMap, the benchmarks are focused on comparing the performance between this package and Java\u2019s TreeMap.\n\nThis 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.\n\nA Cython version is in the works.\n\nBenchmark procedure:\n\n1. Prepare n entries with distinct keys. (n ranges from 1000 to 60000 with 1000 interval.)\n\n2. Insert/Remove/Search them into the map in random order and record the completion time.\n\n3. Repeat step 1-2 two more times and average the result.\n\nHere is result using Java TreeMap:\n\n<p align=\"center\">\n<img src=\"https://raw.githubusercontent.com/GavinPHR/pytreemap/master/benchmarks/java.png\" width=\"450\"/>\n</p>\n\nAnd here is the result using pytreemap:\n\n<p align=\"center\">\n<img src=\"https://raw.githubusercontent.com/GavinPHR/pytreemap/master/benchmarks/pytreemap.png\" width=\"450\"/>\n</p>\n\nOverlay the plots together, we can see that pytreemap is ~30x slower:\n\n<p align=\"center\">\n<img src=\"https://raw.githubusercontent.com/GavinPHR/pytreemap/master/benchmarks/java_vs_pytreemap.png\" width=\"450\"/>\n</p>\n\n",
"bugtrack_url": null,
"license": "gpl-2.0",
"summary": "Python Implementation of Java TreeMap/TreeSet",
"version": "0.6",
"project_urls": {
"Homepage": "https://github.com/GavinPHR/pytreemap"
},
"split_keywords": [
"python3",
" self-balancing",
" binary-search-tree",
" red-black-tree",
" java",
" treemap",
" treeset"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fee57b129586595894a6118dd0014d674561fc932394dd532881ad0ab19a15b5",
"md5": "454d7cbe18e4fbe14eb1ddba8b368eaf",
"sha256": "9824d7406ba6158ee9877bf8d7651504565beff5a9ccca1a77d9eed41874faba"
},
"downloads": -1,
"filename": "pytreemap-0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "454d7cbe18e4fbe14eb1ddba8b368eaf",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 32567,
"upload_time": "2024-10-09T16:28:55",
"upload_time_iso_8601": "2024-10-09T16:28:55.860062Z",
"url": "https://files.pythonhosted.org/packages/fe/e5/7b129586595894a6118dd0014d674561fc932394dd532881ad0ab19a15b5/pytreemap-0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "aae93721fab3eac7641fa204e68ba2f43aa70e5c915042713421b142c1bd8e49",
"md5": "0336abfbe1392cfc66488f1c760824f1",
"sha256": "978af6c477a319bace967a4f8f0739ee22da9d8889ba3b8a94923c0aeb5ee900"
},
"downloads": -1,
"filename": "pytreemap-0.6.tar.gz",
"has_sig": false,
"md5_digest": "0336abfbe1392cfc66488f1c760824f1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 22608,
"upload_time": "2024-10-09T16:28:57",
"upload_time_iso_8601": "2024-10-09T16:28:57.023231Z",
"url": "https://files.pythonhosted.org/packages/aa/e9/3721fab3eac7641fa204e68ba2f43aa70e5c915042713421b142c1bd8e49/pytreemap-0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-09 16:28:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "GavinPHR",
"github_project": "pytreemap",
"travis_ci": true,
"coveralls": true,
"github_actions": false,
"lcname": "pytreemap"
}