{"id":20545969,"url":"https://github.com/rtjoa/python-treecontainers","last_synced_at":"2025-08-12T02:33:25.496Z","repository":{"id":112360222,"uuid":"394893535","full_name":"rtjoa/python-treecontainers","owner":"rtjoa","description":"Asymptotically efficient heap x map in pure Python","archived":false,"fork":false,"pushed_at":"2021-08-11T12:16:50.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T05:15:46.727Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/treecontainers/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rtjoa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-11T06:59:36.000Z","updated_at":"2021-08-11T12:16:53.000Z","dependencies_parsed_at":"2023-05-13T15:15:07.687Z","dependency_job_id":null,"html_url":"https://github.com/rtjoa/python-treecontainers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rtjoa/python-treecontainers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtjoa%2Fpython-treecontainers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtjoa%2Fpython-treecontainers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtjoa%2Fpython-treecontainers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtjoa%2Fpython-treecontainers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rtjoa","download_url":"https://codeload.github.com/rtjoa/python-treecontainers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtjoa%2Fpython-treecontainers/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269988879,"owners_count":24508546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T01:55:00.729Z","updated_at":"2025-08-12T02:33:25.441Z","avatar_url":"https://github.com/rtjoa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tree Containers\n\nAsymptotically-efficient tree-based containers in pure Python. Licensed under the [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n\n## PriorityMap\n\nA combination between a heap and a map that stores key:priority mappings.\n\n### Operations\n| Operation | Description | Runtime Complexity |\n|---|---|---|\n| `__getitem__(key)` | Get priority of key | O(1) |\n| `__setitem__(key, priority)` | Set priority of key | O(log n) |\n| `__delitem__(key)` | Remove a key | O(log n) |\n| `__contains__(key)` | Check whether a key is contained | O(1) |\n| `__len__()` | Return the number of keys contained | O(1) |\n| `peek()` | Get lowest-priority key and its priority | O(1) |\n| `pop()` | Get and remove lowest-priority key and its priority | O(log n) |\n\n### Example Console Output\n```py\n\u003e\u003e\u003e from prioritymap import PriorityMap\n\u003e\u003e\u003e pm = PriorityMap()\n\u003e\u003e\u003e pm[\"first\"] = 1\n\u003e\u003e\u003e pm[\"second\"] = 2\n\u003e\u003e\u003e pm[\"underdog\"] = 5\n\u003e\u003e\u003e pm.peek()\n('first', 1)\n\u003e\u003e\u003e pm[\"underdog\"] = 0\n\u003e\u003e\u003e len(pm)\n3\n\u003e\u003e\u003e pm.pop()\n('underdog', 0)\n\u003e\u003e\u003e pm.pop()\n('first', 1)\n\u003e\u003e\u003e pm.pop()\n('second', 2)\n\u003e\u003e\u003e len(pm)\n0\n```\n## PriorityQueue\n\nLike Java's PriorityQueue, but with O(log(n)) arbitrary removal and O(1) containment check (versus linear for both in Java).\n\n### Operations\n| Operation | Description | Runtime Complexity |\n|---|---|---|\n| `__init__(key=None)` | Key is a function determining priority of an item, identity function by default. | O(1) |\n| `add(item)` | Add an item | O(log n) |\n| `remove(item)` | Remove an item, erroring if it doesn't exist | O(log n) |\n| `discard(item)` | Remove an item if it exists | O(log n) |\n| `peek()` | Get the lowest-priority item | O(1) |\n| `pop()` | Get and remove the lowest-priority item | O(log n) |\n| `__contains__(item)` | Check whether an item is contained | O(1) |\n| `__len__()` | Return the number of items contained | O(1) |\n\n## PrioritySet\n\nExactly like the PriorityQueue above, but slightly optimized and not tracking multiples of items. (Adding an existing item does nothing).\n\nRoughly, PrioritySet is to PriorityMap as set is to dict.\n\n## TreeMap\n\nTo be implemented.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtjoa%2Fpython-treecontainers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtjoa%2Fpython-treecontainers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtjoa%2Fpython-treecontainers/lists"}