arborpy 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arborpy-0.1.0/.github/CODEOWNERS +1 -0
- arborpy-0.1.0/.github/ISSUE_TEMPLATE/bug_report.md +21 -0
- arborpy-0.1.0/.github/ISSUE_TEMPLATE/feature_request.md +19 -0
- arborpy-0.1.0/.github/pull_request_template.md +16 -0
- arborpy-0.1.0/.github/workflows/ci.yml +49 -0
- arborpy-0.1.0/.github/workflows/release.yml +54 -0
- arborpy-0.1.0/.gitignore +35 -0
- arborpy-0.1.0/.pre-commit-config.yaml +22 -0
- arborpy-0.1.0/.python-version +1 -0
- arborpy-0.1.0/CHANGELOG.md +22 -0
- arborpy-0.1.0/CONTRIBUTING.md +85 -0
- arborpy-0.1.0/LICENSE +21 -0
- arborpy-0.1.0/Makefile +21 -0
- arborpy-0.1.0/PKG-INFO +153 -0
- arborpy-0.1.0/README.md +128 -0
- arborpy-0.1.0/pyproject.toml +81 -0
- arborpy-0.1.0/src/arborpy/__init__.py +31 -0
- arborpy-0.1.0/src/arborpy/_version.py +3 -0
- arborpy-0.1.0/src/arborpy/binary_tree.py +329 -0
- arborpy-0.1.0/src/arborpy/exceptions.py +43 -0
- arborpy-0.1.0/src/arborpy/node.py +73 -0
- arborpy-0.1.0/src/arborpy/py.typed +0 -0
- arborpy-0.1.0/src/arborpy/serialize.py +100 -0
- arborpy-0.1.0/src/arborpy/traversals.py +111 -0
- arborpy-0.1.0/src/arborpy/visualize.py +99 -0
- arborpy-0.1.0/tests/__init__.py +1 -0
- arborpy-0.1.0/tests/conftest.py +27 -0
- arborpy-0.1.0/tests/test_binary_tree.py +230 -0
- arborpy-0.1.0/tests/test_node.py +75 -0
- arborpy-0.1.0/tests/test_serialize.py +81 -0
- arborpy-0.1.0/tests/test_traversals.py +86 -0
- arborpy-0.1.0/tests/test_visualize.py +34 -0
- arborpy-0.1.0/uv.lock +761 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @prabhav-jalan
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug Report
|
|
3
|
+
about: Report a bug in arborpy
|
|
4
|
+
labels: bug
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
**Describe the bug**
|
|
8
|
+
A clear description of what the bug is.
|
|
9
|
+
|
|
10
|
+
**To reproduce**
|
|
11
|
+
```python
|
|
12
|
+
# Minimal code to reproduce
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Expected behavior**
|
|
16
|
+
What should have happened.
|
|
17
|
+
|
|
18
|
+
**Environment**
|
|
19
|
+
- Python version:
|
|
20
|
+
- arborpy version:
|
|
21
|
+
- OS:
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature Request
|
|
3
|
+
about: Suggest a new feature for arborpy
|
|
4
|
+
labels: enhancement
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
**Describe the feature**
|
|
8
|
+
A clear description of what you'd like added.
|
|
9
|
+
|
|
10
|
+
**Use case**
|
|
11
|
+
Why is this feature useful? What problem does it solve?
|
|
12
|
+
|
|
13
|
+
**Proposed API**
|
|
14
|
+
```python
|
|
15
|
+
# How you'd like to use the feature
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Alternatives considered**
|
|
19
|
+
Any alternative solutions you've thought about.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
## Summary
|
|
2
|
+
Brief description of what this PR does.
|
|
3
|
+
|
|
4
|
+
## Type of change
|
|
5
|
+
- [ ] New feature
|
|
6
|
+
- [ ] Bug fix
|
|
7
|
+
- [ ] Documentation
|
|
8
|
+
- [ ] Refactoring
|
|
9
|
+
- [ ] CI/CD
|
|
10
|
+
|
|
11
|
+
## Checklist
|
|
12
|
+
- [ ] Tests pass locally (`uv run pytest`)
|
|
13
|
+
- [ ] Linting passes (`uv run ruff check src/ tests/`)
|
|
14
|
+
- [ ] Type checking passes (`uv run mypy src/`)
|
|
15
|
+
- [ ] Docstrings added for public API
|
|
16
|
+
- [ ] CHANGELOG.md updated (if user-facing change)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, develop]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ${{ matrix.os }}
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: false
|
|
17
|
+
matrix:
|
|
18
|
+
os: [ubuntu-latest, macos-latest]
|
|
19
|
+
python-version: ["3.13", "3.14"]
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Install uv
|
|
25
|
+
uses: astral-sh/setup-uv@v3
|
|
26
|
+
|
|
27
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
28
|
+
run: uv python install ${{ matrix.python-version }}
|
|
29
|
+
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: uv sync
|
|
32
|
+
|
|
33
|
+
- name: Lint with Ruff
|
|
34
|
+
run: uv run ruff check src/ tests/
|
|
35
|
+
|
|
36
|
+
- name: Format check
|
|
37
|
+
run: uv run ruff format --check src/ tests/
|
|
38
|
+
|
|
39
|
+
- name: Type check with mypy
|
|
40
|
+
run: uv run mypy src/
|
|
41
|
+
|
|
42
|
+
- name: Run tests
|
|
43
|
+
run: uv run pytest --cov-report=xml
|
|
44
|
+
|
|
45
|
+
- name: Upload coverage
|
|
46
|
+
if: matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest'
|
|
47
|
+
uses: codecov/codecov-action@v4
|
|
48
|
+
with:
|
|
49
|
+
file: ./coverage.xml
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: Release to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v3
|
|
20
|
+
|
|
21
|
+
- name: Build package
|
|
22
|
+
run: uv build
|
|
23
|
+
|
|
24
|
+
- name: Upload artifacts
|
|
25
|
+
uses: actions/upload-artifact@v4
|
|
26
|
+
with:
|
|
27
|
+
name: dist
|
|
28
|
+
path: dist/
|
|
29
|
+
|
|
30
|
+
publish:
|
|
31
|
+
needs: build
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
environment: pypi
|
|
34
|
+
steps:
|
|
35
|
+
- name: Download artifacts
|
|
36
|
+
uses: actions/download-artifact@v4
|
|
37
|
+
with:
|
|
38
|
+
name: dist
|
|
39
|
+
path: dist/
|
|
40
|
+
|
|
41
|
+
- name: Publish to PyPI
|
|
42
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
43
|
+
|
|
44
|
+
github-release:
|
|
45
|
+
needs: publish
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
permissions:
|
|
48
|
+
contents: write
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@v4
|
|
51
|
+
- name: Create GitHub Release
|
|
52
|
+
env:
|
|
53
|
+
GH_TOKEN: ${{ github.token }}
|
|
54
|
+
run: gh release create ${{ github.ref_name }} --generate-notes
|
arborpy-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.egg-info/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
.eggs/
|
|
9
|
+
|
|
10
|
+
# Virtual environments
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
|
|
14
|
+
# IDE
|
|
15
|
+
.vscode/
|
|
16
|
+
.idea/
|
|
17
|
+
*.swp
|
|
18
|
+
*.swo
|
|
19
|
+
|
|
20
|
+
# Testing
|
|
21
|
+
.pytest_cache/
|
|
22
|
+
.coverage
|
|
23
|
+
htmlcov/
|
|
24
|
+
.mypy_cache/
|
|
25
|
+
|
|
26
|
+
# Docs
|
|
27
|
+
docs/_build/
|
|
28
|
+
|
|
29
|
+
# OS
|
|
30
|
+
.DS_Store
|
|
31
|
+
Thumbs.db
|
|
32
|
+
|
|
33
|
+
# Distribution
|
|
34
|
+
*.tar.gz
|
|
35
|
+
*.whl
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.4.8
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff
|
|
6
|
+
args: [--fix]
|
|
7
|
+
- id: ruff-format
|
|
8
|
+
|
|
9
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
10
|
+
rev: v4.6.0
|
|
11
|
+
hooks:
|
|
12
|
+
- id: trailing-whitespace
|
|
13
|
+
- id: end-of-file-fixer
|
|
14
|
+
- id: check-yaml
|
|
15
|
+
- id: check-added-large-files
|
|
16
|
+
|
|
17
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
18
|
+
rev: v1.10.0
|
|
19
|
+
hooks:
|
|
20
|
+
- id: mypy
|
|
21
|
+
additional_dependencies: [pytest]
|
|
22
|
+
args: [--strict]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-03-27
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `Node` class with value, left/right children, and `is_leaf()` method
|
|
14
|
+
- `BinarySearchTree` with insert, delete, search, find_min, find_max, height
|
|
15
|
+
- Traversal functions: inorder, preorder, postorder, level_order
|
|
16
|
+
- Serialization: to_dict, from_dict, to_json, from_json
|
|
17
|
+
- ASCII pretty-print visualization via `print(bst)`
|
|
18
|
+
- Custom exceptions: EmptyTreeError, NodeNotFoundError, DuplicateKeyError
|
|
19
|
+
- Support for `len(bst)`, `in` operator, and `bool(bst)`
|
|
20
|
+
- Full test suite with 77 tests
|
|
21
|
+
- CI pipeline with GitHub Actions (Python 3.13, 3.14 on Ubuntu and macOS)
|
|
22
|
+
- Type hints throughout (PEP 561 compatible with py.typed marker)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Contributing to ArborPy
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing! Here's how to get started.
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
1. Fork and clone the repo:
|
|
8
|
+
```bash
|
|
9
|
+
git clone git@github.com:your-username/arborpy.git
|
|
10
|
+
cd arborpy
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
2. Install [uv](https://docs.astral.sh/uv/):
|
|
14
|
+
```bash
|
|
15
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
3. Install dependencies:
|
|
19
|
+
```bash
|
|
20
|
+
uv sync
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
4. Install pre-commit hooks:
|
|
24
|
+
```bash
|
|
25
|
+
pre-commit install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Running Tests
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
uv run pytest # all tests
|
|
32
|
+
uv run pytest tests/test_node.py # single file
|
|
33
|
+
uv run pytest -x # stop on first failure
|
|
34
|
+
uv run pytest -v # verbose output
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Code Quality
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
uv run ruff check src/ tests/ # lint
|
|
41
|
+
uv run ruff format src/ tests/ # format
|
|
42
|
+
uv run mypy src/ # type check
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Or run everything at once:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
make check
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Branch Naming
|
|
52
|
+
|
|
53
|
+
| Prefix | Use for |
|
|
54
|
+
|--------|---------|
|
|
55
|
+
| `feat/` | New features |
|
|
56
|
+
| `fix/` | Bug fixes |
|
|
57
|
+
| `docs/` | Documentation |
|
|
58
|
+
| `refactor/` | Code refactoring |
|
|
59
|
+
| `test/` | Adding or fixing tests |
|
|
60
|
+
|
|
61
|
+
## Commit Messages
|
|
62
|
+
|
|
63
|
+
Use [Conventional Commits](https://www.conventionalcommits.org/):
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
feat: add AVL tree with self-balancing insert
|
|
67
|
+
fix: correct BST delete when node has two children
|
|
68
|
+
docs: update README with AVL usage examples
|
|
69
|
+
test: add edge case tests for empty tree operations
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Pull Request Process
|
|
73
|
+
|
|
74
|
+
1. Create a feature branch from `develop`
|
|
75
|
+
2. Write tests for your changes
|
|
76
|
+
3. Ensure all checks pass (`make check`)
|
|
77
|
+
4. Submit PR against `develop`
|
|
78
|
+
5. Fill in the PR template
|
|
79
|
+
|
|
80
|
+
## Code Style
|
|
81
|
+
|
|
82
|
+
- Type hints on all public functions and methods
|
|
83
|
+
- Google-style docstrings on all public classes and methods
|
|
84
|
+
- Line length limit: 88 characters
|
|
85
|
+
- Ruff handles formatting and linting automatically
|
arborpy-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Prabhav Jalan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
arborpy-0.1.0/Makefile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
.PHONY: test lint format typecheck clean build check
|
|
2
|
+
|
|
3
|
+
test:
|
|
4
|
+
uv run pytest
|
|
5
|
+
|
|
6
|
+
lint:
|
|
7
|
+
uv run ruff check src/ tests/
|
|
8
|
+
|
|
9
|
+
format:
|
|
10
|
+
uv run ruff format src/ tests/
|
|
11
|
+
|
|
12
|
+
typecheck:
|
|
13
|
+
uv run mypy src/
|
|
14
|
+
|
|
15
|
+
check: lint typecheck test
|
|
16
|
+
|
|
17
|
+
clean:
|
|
18
|
+
rm -rf dist/ build/ *.egg-info .pytest_cache .mypy_cache htmlcov/
|
|
19
|
+
|
|
20
|
+
build: clean
|
|
21
|
+
uv build
|
arborpy-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arborpy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A comprehensive Python library for tree data structures
|
|
5
|
+
Project-URL: Homepage, https://github.com/prabhav-jalan/arborpy
|
|
6
|
+
Project-URL: Documentation, https://arborpy.readthedocs.io
|
|
7
|
+
Project-URL: Repository, https://github.com/prabhav-jalan/arborpy
|
|
8
|
+
Project-URL: Issues, https://github.com/prabhav-jalan/arborpy/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/prabhav-jalan/arborpy/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Prabhav Jalan <prabhavjalan12@gmail.com>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: avl,binary-tree,bst,data-structures,heap,tree,trie
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Education
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.13
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# ArborPy 🌳
|
|
27
|
+
|
|
28
|
+
[](https://github.com/prabhav-jalan/arborpy/actions/workflows/ci.yml)
|
|
29
|
+
[](https://pypi.org/project/arborpy/)
|
|
30
|
+
[](https://pypi.org/project/arborpy/)
|
|
31
|
+
[](https://opensource.org/licenses/MIT)
|
|
32
|
+
|
|
33
|
+
A comprehensive, typed, and well-tested Python library for tree data structures.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install arborpy
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from arborpy import BinarySearchTree
|
|
45
|
+
|
|
46
|
+
bst = BinarySearchTree()
|
|
47
|
+
for val in [5, 3, 7, 1, 4]:
|
|
48
|
+
bst.insert(val)
|
|
49
|
+
|
|
50
|
+
print(bst.inorder()) # [1, 3, 4, 5, 7]
|
|
51
|
+
print(bst.search(4)) # True
|
|
52
|
+
print(5 in bst) # True
|
|
53
|
+
print(len(bst)) # 5
|
|
54
|
+
print(bst) # Pretty-printed tree
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Features
|
|
58
|
+
|
|
59
|
+
### Binary Search Tree
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from arborpy import BinarySearchTree
|
|
63
|
+
|
|
64
|
+
bst = BinarySearchTree()
|
|
65
|
+
|
|
66
|
+
# Insert values
|
|
67
|
+
for val in [5, 3, 7, 1, 4, 6, 8]:
|
|
68
|
+
bst.insert(val)
|
|
69
|
+
|
|
70
|
+
# Search
|
|
71
|
+
bst.search(4) # True
|
|
72
|
+
bst.search(99) # False
|
|
73
|
+
|
|
74
|
+
# Delete
|
|
75
|
+
bst.delete(3)
|
|
76
|
+
|
|
77
|
+
# Min and max
|
|
78
|
+
bst.find_min() # 1
|
|
79
|
+
bst.find_max() # 8
|
|
80
|
+
|
|
81
|
+
# Tree properties
|
|
82
|
+
bst.height() # 2
|
|
83
|
+
len(bst) # 7
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Traversals
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from arborpy import BinarySearchTree
|
|
90
|
+
|
|
91
|
+
bst = BinarySearchTree()
|
|
92
|
+
for val in [5, 3, 7, 1, 4, 6, 8]:
|
|
93
|
+
bst.insert(val)
|
|
94
|
+
|
|
95
|
+
bst.inorder() # [1, 3, 4, 5, 6, 7, 8]
|
|
96
|
+
bst.preorder() # [5, 3, 1, 4, 7, 6, 8]
|
|
97
|
+
bst.postorder() # [1, 4, 3, 6, 8, 7, 5]
|
|
98
|
+
bst.level_order() # [[5], [3, 7], [1, 4, 6, 8]]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Serialization
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from arborpy import BinarySearchTree, to_json, from_json, to_dict, from_dict
|
|
105
|
+
|
|
106
|
+
bst = BinarySearchTree()
|
|
107
|
+
for val in [5, 3, 7]:
|
|
108
|
+
bst.insert(val)
|
|
109
|
+
|
|
110
|
+
# To/from dictionary
|
|
111
|
+
d = to_dict(bst.root)
|
|
112
|
+
node = from_dict(d)
|
|
113
|
+
|
|
114
|
+
# To/from JSON
|
|
115
|
+
json_str = to_json(bst.root)
|
|
116
|
+
node = from_json(json_str)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Standalone Traversal Functions
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from arborpy import Node, inorder, preorder, postorder, level_order
|
|
123
|
+
|
|
124
|
+
# Build a tree manually
|
|
125
|
+
root = Node(1, Node(2, Node(4), Node(5)), Node(3))
|
|
126
|
+
|
|
127
|
+
inorder(root) # [4, 2, 5, 1, 3]
|
|
128
|
+
preorder(root) # [1, 2, 4, 5, 3]
|
|
129
|
+
postorder(root) # [4, 5, 2, 3, 1]
|
|
130
|
+
level_order(root) # [[1], [2, 3], [4, 5]]
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Roadmap
|
|
134
|
+
|
|
135
|
+
- [x] Binary Search Tree
|
|
136
|
+
- [x] Traversals (inorder, preorder, postorder, level-order)
|
|
137
|
+
- [x] Serialization (dict, JSON)
|
|
138
|
+
- [x] ASCII visualization
|
|
139
|
+
- [ ] AVL Tree (self-balancing)
|
|
140
|
+
- [ ] Min/Max Heap
|
|
141
|
+
- [ ] Red-Black Tree
|
|
142
|
+
- [ ] Trie (prefix tree)
|
|
143
|
+
- [ ] Segment Tree
|
|
144
|
+
- [ ] Fenwick Tree (Binary Indexed Tree)
|
|
145
|
+
- [ ] N-ary Tree
|
|
146
|
+
|
|
147
|
+
## Contributing
|
|
148
|
+
|
|
149
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT — see [LICENSE](LICENSE) for details.
|
arborpy-0.1.0/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# ArborPy 🌳
|
|
2
|
+
|
|
3
|
+
[](https://github.com/prabhav-jalan/arborpy/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/arborpy/)
|
|
5
|
+
[](https://pypi.org/project/arborpy/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
A comprehensive, typed, and well-tested Python library for tree data structures.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install arborpy
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from arborpy import BinarySearchTree
|
|
20
|
+
|
|
21
|
+
bst = BinarySearchTree()
|
|
22
|
+
for val in [5, 3, 7, 1, 4]:
|
|
23
|
+
bst.insert(val)
|
|
24
|
+
|
|
25
|
+
print(bst.inorder()) # [1, 3, 4, 5, 7]
|
|
26
|
+
print(bst.search(4)) # True
|
|
27
|
+
print(5 in bst) # True
|
|
28
|
+
print(len(bst)) # 5
|
|
29
|
+
print(bst) # Pretty-printed tree
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
### Binary Search Tree
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from arborpy import BinarySearchTree
|
|
38
|
+
|
|
39
|
+
bst = BinarySearchTree()
|
|
40
|
+
|
|
41
|
+
# Insert values
|
|
42
|
+
for val in [5, 3, 7, 1, 4, 6, 8]:
|
|
43
|
+
bst.insert(val)
|
|
44
|
+
|
|
45
|
+
# Search
|
|
46
|
+
bst.search(4) # True
|
|
47
|
+
bst.search(99) # False
|
|
48
|
+
|
|
49
|
+
# Delete
|
|
50
|
+
bst.delete(3)
|
|
51
|
+
|
|
52
|
+
# Min and max
|
|
53
|
+
bst.find_min() # 1
|
|
54
|
+
bst.find_max() # 8
|
|
55
|
+
|
|
56
|
+
# Tree properties
|
|
57
|
+
bst.height() # 2
|
|
58
|
+
len(bst) # 7
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Traversals
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from arborpy import BinarySearchTree
|
|
65
|
+
|
|
66
|
+
bst = BinarySearchTree()
|
|
67
|
+
for val in [5, 3, 7, 1, 4, 6, 8]:
|
|
68
|
+
bst.insert(val)
|
|
69
|
+
|
|
70
|
+
bst.inorder() # [1, 3, 4, 5, 6, 7, 8]
|
|
71
|
+
bst.preorder() # [5, 3, 1, 4, 7, 6, 8]
|
|
72
|
+
bst.postorder() # [1, 4, 3, 6, 8, 7, 5]
|
|
73
|
+
bst.level_order() # [[5], [3, 7], [1, 4, 6, 8]]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Serialization
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from arborpy import BinarySearchTree, to_json, from_json, to_dict, from_dict
|
|
80
|
+
|
|
81
|
+
bst = BinarySearchTree()
|
|
82
|
+
for val in [5, 3, 7]:
|
|
83
|
+
bst.insert(val)
|
|
84
|
+
|
|
85
|
+
# To/from dictionary
|
|
86
|
+
d = to_dict(bst.root)
|
|
87
|
+
node = from_dict(d)
|
|
88
|
+
|
|
89
|
+
# To/from JSON
|
|
90
|
+
json_str = to_json(bst.root)
|
|
91
|
+
node = from_json(json_str)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Standalone Traversal Functions
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from arborpy import Node, inorder, preorder, postorder, level_order
|
|
98
|
+
|
|
99
|
+
# Build a tree manually
|
|
100
|
+
root = Node(1, Node(2, Node(4), Node(5)), Node(3))
|
|
101
|
+
|
|
102
|
+
inorder(root) # [4, 2, 5, 1, 3]
|
|
103
|
+
preorder(root) # [1, 2, 4, 5, 3]
|
|
104
|
+
postorder(root) # [4, 5, 2, 3, 1]
|
|
105
|
+
level_order(root) # [[1], [2, 3], [4, 5]]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Roadmap
|
|
109
|
+
|
|
110
|
+
- [x] Binary Search Tree
|
|
111
|
+
- [x] Traversals (inorder, preorder, postorder, level-order)
|
|
112
|
+
- [x] Serialization (dict, JSON)
|
|
113
|
+
- [x] ASCII visualization
|
|
114
|
+
- [ ] AVL Tree (self-balancing)
|
|
115
|
+
- [ ] Min/Max Heap
|
|
116
|
+
- [ ] Red-Black Tree
|
|
117
|
+
- [ ] Trie (prefix tree)
|
|
118
|
+
- [ ] Segment Tree
|
|
119
|
+
- [ ] Fenwick Tree (Binary Indexed Tree)
|
|
120
|
+
- [ ] N-ary Tree
|
|
121
|
+
|
|
122
|
+
## Contributing
|
|
123
|
+
|
|
124
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
MIT — see [LICENSE](LICENSE) for details.
|