dtree-encoding 1.5.0__tar.gz → 1.7.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.
- {dtree_encoding-1.5.0 → dtree_encoding-1.7.0}/PKG-INFO +24 -10
- {dtree_encoding-1.5.0 → dtree_encoding-1.7.0}/README.md +21 -7
- dtree_encoding-1.7.0/dtree/__init__.py +6 -0
- dtree_encoding-1.7.0/dtree/bench.py +580 -0
- {dtree_encoding-1.5.0 → dtree_encoding-1.7.0}/dtree/dtree.py +387 -147
- {dtree_encoding-1.5.0 → dtree_encoding-1.7.0}/dtree_encoding.egg-info/PKG-INFO +24 -10
- {dtree_encoding-1.5.0 → dtree_encoding-1.7.0}/dtree_encoding.egg-info/SOURCES.txt +1 -0
- {dtree_encoding-1.5.0 → dtree_encoding-1.7.0}/pyproject.toml +3 -3
- {dtree_encoding-1.5.0 → dtree_encoding-1.7.0}/tests/test_dtree.py +183 -2
- dtree_encoding-1.5.0/dtree/__init__.py +0 -6
- {dtree_encoding-1.5.0 → dtree_encoding-1.7.0}/dtree_encoding.egg-info/dependency_links.txt +0 -0
- {dtree_encoding-1.5.0 → dtree_encoding-1.7.0}/dtree_encoding.egg-info/top_level.txt +0 -0
- {dtree_encoding-1.5.0 → dtree_encoding-1.7.0}/setup.cfg +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dtree-encoding
|
|
3
|
-
Version: 1.
|
|
4
|
-
Summary: DTree: incremental encoding of directed trees by two projections (Q1, Q2)
|
|
3
|
+
Version: 1.7.0
|
|
4
|
+
Summary: DTree: incremental encoding of the topology of directed trees by two projections (Q1, Q2): O(1) reachability, and/or queries on the topology of the tree, dynamic (incremental) updates
|
|
5
5
|
Author-email: Enis Olgac <enis@digraphs.info>
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/EnisOlgac/DTree
|
|
@@ -9,7 +9,7 @@ Project-URL: Documentation, https://github.com/EnisOlgac/DTree/blob/main/docs/AP
|
|
|
9
9
|
Project-URL: Changelog, https://github.com/EnisOlgac/DTree/blob/main/CHANGELOG.md
|
|
10
10
|
Project-URL: Paper, https://doi.org/10.5772/intechopen.1013408
|
|
11
11
|
Project-URL: Archive, https://doi.org/10.5281/zenodo.23395710
|
|
12
|
-
Keywords: directed tree,reachability,incremental encoding,dynamic tree,graph theory,data structure
|
|
12
|
+
Keywords: directed tree,tree topology,reachability,and/or queries,incremental encoding,dynamic tree,graph theory,data structure
|
|
13
13
|
Classifier: Development Status :: 5 - Production/Stable
|
|
14
14
|
Classifier: Intended Audience :: Science/Research
|
|
15
15
|
Classifier: Intended Audience :: Developers
|
|
@@ -23,7 +23,7 @@ Description-Content-Type: text/markdown
|
|
|
23
23
|
|
|
24
24
|
# DTree for Python
|
|
25
25
|
|
|
26
|
-
Python implementation of `DTree`, the incremental encoding of directed trees by two projections Q1 and Q2 (see the [API reference](https://github.com/EnisOlgac/DTree/blob/main/docs/API.md) and the [paper](https://doi.org/10.5772/intechopen.1013408)). No dependencies; Python 3.8+.
|
|
26
|
+
Python implementation of `DTree`, the incremental encoding of the topology of directed trees by two projections Q1 and Q2 (see the [API reference](https://github.com/EnisOlgac/DTree/blob/main/docs/API.md) and the [paper](https://doi.org/10.5772/intechopen.1013408)). No dependencies; Python 3.8+.
|
|
27
27
|
|
|
28
28
|
```
|
|
29
29
|
pip install dtree-encoding
|
|
@@ -73,18 +73,25 @@ t = DTree.from_file("Test.csx") # e.g. examples/Test.csx from the repository
|
|
|
73
73
|
| `SameSubtree`, `SubtreeSize` | `same_subtree`, `subtree_size` (plus `subtree`) |
|
|
74
74
|
| `Depth` | `depth` (root = 0) |
|
|
75
75
|
| `PathToRoot`, `RootToPath` | `path_to_root`, `root_to_path` (plus `path(u, v)`) |
|
|
76
|
+
| `GetNode`, `TryGetNode`, `DNode` | `get_node`, `try_get_node`, `DNode` (node handles; `insert` returns one) |
|
|
77
|
+
| `SubtreeLast` | `subtree_last` (last node of a subtree in Q1) |
|
|
78
|
+
| `NextInQ1` | `next_in_q1` (next node in Q1, the display order; `None` at the end) |
|
|
76
79
|
| `VMin`, `VMax`, `UMin`, `UMax` (of nodes) | `vmin`, `vmax`, `umin`, `umax` |
|
|
77
80
|
| `ReachesAll`, `MayReachSome`, `ReachesSome` | `reaches_all`, `may_reach_some`, `reaches_some` |
|
|
78
81
|
| `ReachedByAll`, `MayBeReachedBySome`, `ReachedBySome` | `reached_by_all`, `may_be_reached_by_some`, `reached_by_some` |
|
|
82
|
+
| `Add`, `Discard`, `Contains` (of a constructed node) | `add`, `discard`, `node in s` |
|
|
83
|
+
| `UMin.Covering` | `covering` (topmost member that reaches a node; `None` if none) |
|
|
79
84
|
|
|
80
85
|
## Semantics
|
|
81
86
|
|
|
87
|
+
- Every method accepts a node name or a node handle (`DNode`). `insert` returns the handle of the new node, `get_node(name)` gives the handle of an existing one. A handle refers directly to the node's positions in Q1 and Q2, so `can_reach` on handles is two position comparisons without any lookup by name. Handles of deleted nodes, or of another tree, are rejected (KeyError) or reported as unreachable.
|
|
88
|
+
|
|
82
89
|
- `can_reach(u, v)` is irreflexive: no node reaches itself, so `can_reach(u, u)` is `False`. (The C# prototype is reflexive.)
|
|
83
90
|
- `is_ancestor(u, v)` equals `can_reach(u, v)` and is likewise proper.
|
|
84
91
|
- `delete(v)` re-attaches v's children to v's parent, in v's place among its siblings.
|
|
85
92
|
- `delete_subtree(v)` removes v with all its descendants and returns them in Q1 order.
|
|
86
93
|
- `cut_n_paste(u, p)` moves the subtree rooted at u under p as p's last child; p must not lie inside u's subtree.
|
|
87
|
-
-
|
|
94
|
+
- And/or queries on the topology: the constructed nodes `vmin(S)`, `vmax(S)` (S as target) and `umin(S)`, `umax(S)` (S as source) take the minimum or maximum of each index over S, separately in Q1 and Q2. `reaches_all` and `reached_by_all` are exact O(1) tests; `may_reach_some` and `may_be_reached_by_some` are only filters, and `reaches_some` and `reached_by_some` are exact in O(log k). Members are added with `add` and removed with `discard`. A constructed node stays valid under insertions and is recomputed automatically after `delete`, `delete_subtree` or `cut_n_paste`. See [and/or queries on the topology](https://github.com/EnisOlgac/DTree/blob/main/docs/and-or-queries.md).
|
|
88
95
|
- Projection positions are fractions: a new node gets the mediant (a+c)/(b+d) of its neighbors, so normally no other node moves. Only rare alternating insertion patterns trigger a local renumbering. Tree depth and width are unbounded. `t.Q1.index(v)` returns a position as a `Fraction`.
|
|
89
96
|
|
|
90
97
|
## Tests
|
|
@@ -97,14 +104,21 @@ Every operation is checked against a brute-force parent/children model on random
|
|
|
97
104
|
|
|
98
105
|
## Benchmarks
|
|
99
106
|
|
|
107
|
+
The benchmarks come with the package, so you can measure on your own machine:
|
|
108
|
+
|
|
100
109
|
```
|
|
101
|
-
python
|
|
102
|
-
python
|
|
103
|
-
python
|
|
104
|
-
python
|
|
110
|
+
python -m dtree.bench # trees of 10,000 and 100,000 nodes
|
|
111
|
+
python -m dtree.bench --quick # a few seconds
|
|
112
|
+
python -m dtree.bench --dynamic # only the dynamic updates and the tree view
|
|
113
|
+
python -m dtree.bench --note "idle machine" # remark for the report
|
|
114
|
+
python -m dtree.bench 1000000 # custom sizes
|
|
105
115
|
```
|
|
106
116
|
|
|
107
|
-
|
|
117
|
+
In a clone of the repository, `python python/benchmarks/bench.py` runs the same code from the sources.
|
|
118
|
+
|
|
119
|
+
The script prints Markdown tables: build time and renumbering counts per tree shape (random, chain, star at the root, star at an inner node, alternating worst case), list growth at either end, and timings for `can_reach`, `depth`, `delete`, `cut_n_paste` and `delete_subtree`, and comparisons with a classical parent walk: reachability by tree depth, and/or queries with constructed nodes, dynamic updates (insertions with 1 or 10 queries each, and static pre/post numbers at depths 100 and 1,000), and a tree view with expand/collapse. Each dynamic measurement is the best of three runs. Each `DList` keeps the counters `renumber_count` and `renumber_moved`, so the same figures are available in your own code via `t.Q1` and `t.Q2`.
|
|
120
|
+
|
|
121
|
+
Every run also writes its tables as a Markdown report to `benchmarks/python/`—in the current directory, or at the repository root when run inside a clone— named after date and time (for example `2026-10-17_14-18.md`), with a header giving the DTree and Python versions, the operating system and the processor; `--no-save` skips it. The C# benchmarks (`dotnet run --project csharp/DTree.Tests -c Release -- bench`) write theirs to `benchmarks/csharp/`.
|
|
108
122
|
|
|
109
123
|
## Provenance
|
|
110
124
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# DTree for Python
|
|
2
2
|
|
|
3
|
-
Python implementation of `DTree`, the incremental encoding of directed trees by two projections Q1 and Q2 (see the [API reference](https://github.com/EnisOlgac/DTree/blob/main/docs/API.md) and the [paper](https://doi.org/10.5772/intechopen.1013408)). No dependencies; Python 3.8+.
|
|
3
|
+
Python implementation of `DTree`, the incremental encoding of the topology of directed trees by two projections Q1 and Q2 (see the [API reference](https://github.com/EnisOlgac/DTree/blob/main/docs/API.md) and the [paper](https://doi.org/10.5772/intechopen.1013408)). No dependencies; Python 3.8+.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
pip install dtree-encoding
|
|
@@ -50,18 +50,25 @@ t = DTree.from_file("Test.csx") # e.g. examples/Test.csx from the repository
|
|
|
50
50
|
| `SameSubtree`, `SubtreeSize` | `same_subtree`, `subtree_size` (plus `subtree`) |
|
|
51
51
|
| `Depth` | `depth` (root = 0) |
|
|
52
52
|
| `PathToRoot`, `RootToPath` | `path_to_root`, `root_to_path` (plus `path(u, v)`) |
|
|
53
|
+
| `GetNode`, `TryGetNode`, `DNode` | `get_node`, `try_get_node`, `DNode` (node handles; `insert` returns one) |
|
|
54
|
+
| `SubtreeLast` | `subtree_last` (last node of a subtree in Q1) |
|
|
55
|
+
| `NextInQ1` | `next_in_q1` (next node in Q1, the display order; `None` at the end) |
|
|
53
56
|
| `VMin`, `VMax`, `UMin`, `UMax` (of nodes) | `vmin`, `vmax`, `umin`, `umax` |
|
|
54
57
|
| `ReachesAll`, `MayReachSome`, `ReachesSome` | `reaches_all`, `may_reach_some`, `reaches_some` |
|
|
55
58
|
| `ReachedByAll`, `MayBeReachedBySome`, `ReachedBySome` | `reached_by_all`, `may_be_reached_by_some`, `reached_by_some` |
|
|
59
|
+
| `Add`, `Discard`, `Contains` (of a constructed node) | `add`, `discard`, `node in s` |
|
|
60
|
+
| `UMin.Covering` | `covering` (topmost member that reaches a node; `None` if none) |
|
|
56
61
|
|
|
57
62
|
## Semantics
|
|
58
63
|
|
|
64
|
+
- Every method accepts a node name or a node handle (`DNode`). `insert` returns the handle of the new node, `get_node(name)` gives the handle of an existing one. A handle refers directly to the node's positions in Q1 and Q2, so `can_reach` on handles is two position comparisons without any lookup by name. Handles of deleted nodes, or of another tree, are rejected (KeyError) or reported as unreachable.
|
|
65
|
+
|
|
59
66
|
- `can_reach(u, v)` is irreflexive: no node reaches itself, so `can_reach(u, u)` is `False`. (The C# prototype is reflexive.)
|
|
60
67
|
- `is_ancestor(u, v)` equals `can_reach(u, v)` and is likewise proper.
|
|
61
68
|
- `delete(v)` re-attaches v's children to v's parent, in v's place among its siblings.
|
|
62
69
|
- `delete_subtree(v)` removes v with all its descendants and returns them in Q1 order.
|
|
63
70
|
- `cut_n_paste(u, p)` moves the subtree rooted at u under p as p's last child; p must not lie inside u's subtree.
|
|
64
|
-
-
|
|
71
|
+
- And/or queries on the topology: the constructed nodes `vmin(S)`, `vmax(S)` (S as target) and `umin(S)`, `umax(S)` (S as source) take the minimum or maximum of each index over S, separately in Q1 and Q2. `reaches_all` and `reached_by_all` are exact O(1) tests; `may_reach_some` and `may_be_reached_by_some` are only filters, and `reaches_some` and `reached_by_some` are exact in O(log k). Members are added with `add` and removed with `discard`. A constructed node stays valid under insertions and is recomputed automatically after `delete`, `delete_subtree` or `cut_n_paste`. See [and/or queries on the topology](https://github.com/EnisOlgac/DTree/blob/main/docs/and-or-queries.md).
|
|
65
72
|
- Projection positions are fractions: a new node gets the mediant (a+c)/(b+d) of its neighbors, so normally no other node moves. Only rare alternating insertion patterns trigger a local renumbering. Tree depth and width are unbounded. `t.Q1.index(v)` returns a position as a `Fraction`.
|
|
66
73
|
|
|
67
74
|
## Tests
|
|
@@ -74,14 +81,21 @@ Every operation is checked against a brute-force parent/children model on random
|
|
|
74
81
|
|
|
75
82
|
## Benchmarks
|
|
76
83
|
|
|
84
|
+
The benchmarks come with the package, so you can measure on your own machine:
|
|
85
|
+
|
|
77
86
|
```
|
|
78
|
-
python
|
|
79
|
-
python
|
|
80
|
-
python
|
|
81
|
-
python
|
|
87
|
+
python -m dtree.bench # trees of 10,000 and 100,000 nodes
|
|
88
|
+
python -m dtree.bench --quick # a few seconds
|
|
89
|
+
python -m dtree.bench --dynamic # only the dynamic updates and the tree view
|
|
90
|
+
python -m dtree.bench --note "idle machine" # remark for the report
|
|
91
|
+
python -m dtree.bench 1000000 # custom sizes
|
|
82
92
|
```
|
|
83
93
|
|
|
84
|
-
|
|
94
|
+
In a clone of the repository, `python python/benchmarks/bench.py` runs the same code from the sources.
|
|
95
|
+
|
|
96
|
+
The script prints Markdown tables: build time and renumbering counts per tree shape (random, chain, star at the root, star at an inner node, alternating worst case), list growth at either end, and timings for `can_reach`, `depth`, `delete`, `cut_n_paste` and `delete_subtree`, and comparisons with a classical parent walk: reachability by tree depth, and/or queries with constructed nodes, dynamic updates (insertions with 1 or 10 queries each, and static pre/post numbers at depths 100 and 1,000), and a tree view with expand/collapse. Each dynamic measurement is the best of three runs. Each `DList` keeps the counters `renumber_count` and `renumber_moved`, so the same figures are available in your own code via `t.Q1` and `t.Q2`.
|
|
97
|
+
|
|
98
|
+
Every run also writes its tables as a Markdown report to `benchmarks/python/`—in the current directory, or at the repository root when run inside a clone— named after date and time (for example `2026-10-17_14-18.md`), with a header giving the DTree and Python versions, the operating system and the processor; `--no-save` skips it. The C# benchmarks (`dotnet run --project csharp/DTree.Tests -c Release -- bench`) write theirs to `benchmarks/csharp/`.
|
|
85
99
|
|
|
86
100
|
## Provenance
|
|
87
101
|
|