Skip to main content

Tree protocols and generic algorithms for the vcti ecosystem. Zero-dependency abstractions; pluggable backings.

Project description

vcti-tree

Tree protocols and generic algorithms for the vcti ecosystem. Zero-dependency abstractions; pluggable backings.

Overview

vcti-tree defines what a tree is in the vcti ecosystem: three Protocols (ReadOnlyTree, MutableTree, LockableTree) parameterised in payload type T and handle type H, plus generic algorithms — DFS and BFS walks, ancestor/depth/path queries, locking guards — written against those Protocols. The Protocols specify semantics (what a tree must support); they do not prescribe storage. Any backing — numpy-array, pointer-based, dict-based — that satisfies the Protocols gets the algorithms for free. The package has no numpy or other heavy dependency; it is a pure-Python abstraction layer that downstream tree packages depend on.

Why this exists

Tree code in the Python ecosystem typically bundles storage, mutation, and traversal into a single class — every new tree implementation re-implements its own walker, its own navigation helpers, its own delete semantics. This package brings across a pattern that's well-established in C++: a small abstract interface defining what a tree is, multiple concrete implementations choosing their own storage, and generic algorithms written once against the interface and reused across every backing. The result is that adding a new tree implementation (numpy-backed, pointer-backed, persistent, …) doesn't mean rewriting walkers and guards — it means satisfying three small Protocols and inheriting the entire algorithm library. See docs/design.md for the full background and the design decisions.

Installation

pip install vcti-tree

In requirements.txt

vcti-tree>=2.0.0

In pyproject.toml dependencies

dependencies = [
    "vcti-tree>=2.0.0",
]

Quick Start

The protocols and algorithms are the API; you bring (or import) a backing. DictTree is the bundled dict-backed reference implementation — enough to build a tree and run the generic algorithms against it:

from vcti.tree.core import DictTree, dfs_preorder, ancestors, depth

tree = DictTree[str]("root")            # every tree has a root from the start
a = tree.create_child(tree.root_handle, "a")
b = tree.create_child(tree.root_handle, "b")
tree.create_child(a, "a1")

# Generic walks/queries work against any tree that satisfies the protocols.
print([tree.payload(h) for h in dfs_preorder(tree)])   # ['root', 'a', 'a1', 'b']
print([tree.payload(h) for h in ancestors(tree, a)])   # ['root']
print(depth(tree, a))                                  # 1

The protocols (ReadOnlyTree, MutableTree, LockableTree) and the rest of the algorithm set are importable from the same package root:

from vcti.tree.core import ReadOnlyTree, MutableTree, LockableTree
from vcti.tree.core import dfs_preorder, dfs_postorder, bfs
from vcti.tree.core import ancestors, depth, path, descendants

Dependencies

None. Standard library only.

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

vcti_tree-2.0.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

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

vcti_tree-2.0.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file vcti_tree-2.0.0.tar.gz.

File metadata

  • Download URL: vcti_tree-2.0.0.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vcti_tree-2.0.0.tar.gz
Algorithm Hash digest
SHA256 7772c6932d3010a5f8336ba0aaa5d12e6cb3a0a71d1e6911a47956b555c37b2a
MD5 ecc39c27864f4895774a726cfc8bb583
BLAKE2b-256 0897af8a3c1dbe6289af0e50a1e617d24da0cfb9d1fdf8d4f4fb5f77ba68eda2

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_tree-2.0.0.tar.gz:

Publisher: release.yml on vcollab/vcti-python-tree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vcti_tree-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: vcti_tree-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vcti_tree-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44305b02fa857d115b03a728142b291aa157ddf5238eaa61d4628906117686b0
MD5 66ed3cf9a75dfb91165be4ee9f0ffdc3
BLAKE2b-256 7b398f12fcacae021a71c2385c2317815b509659e5a9d15986dde1bce65902f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_tree-2.0.0-py3-none-any.whl:

Publisher: release.yml on vcollab/vcti-python-tree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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