stepps 0.0.0.dev0__tar.gz → 0.2.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.
Files changed (54) hide show
  1. {stepps-0.0.0.dev0 → stepps-0.2.0}/LICENSE +1 -1
  2. stepps-0.2.0/PKG-INFO +404 -0
  3. stepps-0.2.0/README.md +374 -0
  4. {stepps-0.0.0.dev0 → stepps-0.2.0}/pyproject.toml +1 -1
  5. stepps-0.2.0/src/stepps/TreeBuilder/__init__.py +13 -0
  6. stepps-0.2.0/src/stepps/TreeBuilder/inorder_tree_builder.py +8 -0
  7. stepps-0.2.0/src/stepps/TreeBuilder/inorder_tree_builder_impl.py +52 -0
  8. stepps-0.2.0/src/stepps/TreeBuilder/level_order_tree_builder.py +8 -0
  9. stepps-0.2.0/src/stepps/TreeBuilder/level_order_tree_builder_impl.py +46 -0
  10. stepps-0.2.0/src/stepps/TreeBuilder/postorder_tree_builder.py +8 -0
  11. stepps-0.2.0/src/stepps/TreeBuilder/postorder_tree_builder_impl.py +64 -0
  12. stepps-0.2.0/src/stepps/TreeBuilder/preorder_tree_builder.py +8 -0
  13. stepps-0.2.0/src/stepps/TreeBuilder/preorder_tree_builder_impl.py +61 -0
  14. stepps-0.2.0/src/stepps/TreeBuilder/tree_builder.py +21 -0
  15. stepps-0.2.0/src/stepps/iterators/__init__.py +13 -0
  16. stepps-0.2.0/src/stepps/iterators/base_iterator.py +30 -0
  17. stepps-0.2.0/src/stepps/iterators/inorder.py +39 -0
  18. stepps-0.2.0/src/stepps/iterators/levelorder.py +40 -0
  19. stepps-0.2.0/src/stepps/iterators/postorder.py +56 -0
  20. stepps-0.2.0/src/stepps/iterators/preorder.py +47 -0
  21. stepps-0.2.0/src/stepps/nodes/__init__.py +3 -0
  22. stepps-0.2.0/src/stepps/nodes/binary_node.py +61 -0
  23. stepps-0.2.0/src/stepps/py.typed +0 -0
  24. stepps-0.2.0/src/stepps/trees/__init__.py +68 -0
  25. stepps-0.2.0/src/stepps/trees/binary_tree.py +134 -0
  26. stepps-0.2.0/src/stepps/trees/binary_tree_impl.py +307 -0
  27. stepps-0.2.0/src/stepps/trees/bst.py +63 -0
  28. stepps-0.2.0/src/stepps/trees/bst_impl.py +187 -0
  29. stepps-0.2.0/src/stepps/trees/tree.py +59 -0
  30. stepps-0.2.0/src/stepps/visualizer/__init__.py +7 -0
  31. stepps-0.2.0/src/stepps/visualizer/cli_visualizer.py +19 -0
  32. stepps-0.2.0/src/stepps/visualizer/cli_visualizer_impl.py +53 -0
  33. stepps-0.2.0/src/stepps/visualizer/tree_visualizer.py +16 -0
  34. stepps-0.2.0/src/stepps.egg-info/PKG-INFO +404 -0
  35. stepps-0.2.0/src/stepps.egg-info/SOURCES.txt +44 -0
  36. stepps-0.2.0/src/stepps.egg-info/top_level.txt +1 -0
  37. stepps-0.2.0/tests/test_binary_tree.py +392 -0
  38. stepps-0.2.0/tests/test_bst.py +161 -0
  39. stepps-0.2.0/tests/test_inorder_tree_builder.py +93 -0
  40. stepps-0.2.0/tests/test_level_order_tree_builder.py +76 -0
  41. stepps-0.2.0/tests/test_postorder_tree_builder.py +93 -0
  42. stepps-0.2.0/tests/test_preorder_tree_builder.py +93 -0
  43. stepps-0.2.0/tests/test_visualizer.py +119 -0
  44. stepps-0.0.0.dev0/PKG-INFO +0 -37
  45. stepps-0.0.0.dev0/README.md +0 -7
  46. stepps-0.0.0.dev0/src/algor/__init__.py +0 -5
  47. stepps-0.0.0.dev0/src/algor/algor.py +0 -8
  48. stepps-0.0.0.dev0/src/stepps.egg-info/PKG-INFO +0 -37
  49. stepps-0.0.0.dev0/src/stepps.egg-info/SOURCES.txt +0 -11
  50. stepps-0.0.0.dev0/src/stepps.egg-info/top_level.txt +0 -1
  51. stepps-0.0.0.dev0/test/test_algor.py +0 -8
  52. {stepps-0.0.0.dev0 → stepps-0.2.0}/setup.cfg +0 -0
  53. /stepps-0.0.0.dev0/src/algor/py.typed → /stepps-0.2.0/src/stepps/__init__.py +0 -0
  54. {stepps-0.0.0.dev0 → stepps-0.2.0}/src/stepps.egg-info/dependency_links.txt +0 -0
@@ -198,4 +198,4 @@
198
198
  distributed under the License is distributed on an "AS IS" BASIS,
199
199
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
200
  See the License for the specific language governing permissions and
201
- limitations under the License.
201
+ limitations under the License.
stepps-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,404 @@
1
+ Metadata-Version: 2.4
2
+ Name: stepps
3
+ Version: 0.2.0
4
+ Summary: Useful algorithms in Python
5
+ Author-email: Suhas Krishna Srivastava <suhas.srivastava@vaastav.tech>, Trinay Mitra <trinay.mitra@vaastav.tech>
6
+ Maintainer-email: Suhas Krishna Srivastava <suhas.srivastava@vaastav.tech>
7
+ License-Expression: Apache-2.0
8
+ Project-URL: homepage, https://github.com/Vaastav-Technologies/py-algor
9
+ Project-URL: source, https://github.com/Vaastav-Technologies/py-algor
10
+ Project-URL: issues, https://github.com/Vaastav-Technologies/py-algor/issues
11
+ Keywords: algorithms,data-structures,data-structures-and-algorithms,dsa
12
+ Classifier: Development Status :: 1 - Planning
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: Topic :: Education
16
+ Classifier: Topic :: Software Development
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Programming Language :: Python :: 3.15
24
+ Classifier: Programming Language :: Python :: 3 :: Only
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.12
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Dynamic: license-file
30
+
31
+ # Stepps
32
+
33
+ ![Python Version](https://img.shields.io/badge/python-3.12%2B-blue)
34
+ ![License](https://img.shields.io/github/license/Vaastav-Technologies/py-stepps)
35
+ [![test](https://github.com/Vaastav-Technologies/py-stepps/actions/workflows/test.yml/badge.svg)](https://github.com/Vaastav-Technologies/py-stepps/actions/workflows/test.yml)
36
+ [![typecheck](https://github.com/Vaastav-Technologies/py-stepps/actions/workflows/typecheck.yml/badge.svg)](https://github.com/Vaastav-Technologies/py-stepps/actions/workflows/typecheck.yml)
37
+ [![lint](https://github.com/Vaastav-Technologies/py-stepps/actions/workflows/lint.yml/badge.svg)](https://github.com/Vaastav-Technologies/py-stepps/actions/workflows/lint.yml)
38
+ [![publish](https://github.com/Vaastav-Technologies/py-stepps/actions/workflows/python-publish.yml/badge.svg)](https://github.com/Vaastav-Technologies/py-stepps/actions/workflows/python-publish.yml)
39
+
40
+ ---
41
+
42
+ **Fully typed, modular data structures and algorithms for binary trees in Python.**
43
+
44
+ `stepps` provides generic binary tree and binary search tree implementations,
45
+ tree traversal iterators, traversal-based tree builders, and tree visualization
46
+ utilities.
47
+
48
+ The project follows an interface-and-implementation architecture and uses
49
+ Python generics and static typing throughout its APIs.
50
+
51
+ ---
52
+
53
+ ## Features
54
+
55
+ - Generic binary tree data structures.
56
+ - Binary search tree implementation.
57
+ - Preorder, inorder, postorder, and level-order traversal iterators.
58
+ - Tree builders for preorder, inorder, postorder, and level-order sequences.
59
+ - Binary tree statistics and utility operations.
60
+ - CLI tree visualization.
61
+ - Generic type support.
62
+ - Interface-and-implementation architecture.
63
+ - Pytest-based test suite.
64
+ - MyPy static type checking.
65
+ - Ruff linting and formatting.
66
+
67
+ ---
68
+
69
+ ## Installation
70
+
71
+ ```bash
72
+ pip install stepps
73
+ ```
74
+
75
+ For local development:
76
+
77
+ ```bash
78
+ git clone https://github.com/Vaastav-Technologies/py-stepps.git
79
+ cd py-stepps
80
+ pip install -e .
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Binary Tree
86
+
87
+ `BinaryTree` defines the binary tree interface and `BinaryTreeImpl` provides
88
+ the default implementation.
89
+
90
+ ### Binary Tree Methods
91
+
92
+ | Method | Description |
93
+ |---|---|
94
+ | `insert(value)` | Inserts a value into the tree. |
95
+ | `delete(value)` | Deletes a value from the tree. |
96
+ | `find(value)` | Finds and returns the node containing the value. |
97
+ | `contains(value)` | Checks whether a value exists in the tree. |
98
+ | `__contains__(value)` | Supports the `value in tree` operation. |
99
+ | `clear()` | Removes all nodes from the tree. |
100
+ | `is_empty()` | Checks whether the tree is empty. |
101
+ | `size()` | Returns the number of nodes in the tree. |
102
+ | `height()` | Returns the height of the tree. |
103
+ | `count_leaves()` | Returns the number of leaf nodes. |
104
+ | `count_internal_nodes()` | Returns the number of internal nodes. |
105
+ | `invert_tree()` | Inverts the tree in-place. |
106
+
107
+ ---
108
+
109
+ ## Binary Search Tree
110
+
111
+ `BST` defines the binary search tree interface and `BSTImpl` provides the
112
+ implementation.
113
+
114
+ The binary search tree maintains the ordering property that values in the
115
+ left subtree are smaller than the node value and values in the right subtree
116
+ are greater.
117
+
118
+ ### Binary Search Tree Methods
119
+
120
+ | Method | Description |
121
+ |---|---|
122
+ | `insert(value)` | Inserts a value while maintaining BST ordering. |
123
+ | `delete(value)` | Deletes a value while maintaining BST ordering. |
124
+ | `find(value)` | Searches for and returns the node containing the value. |
125
+ | `contains(value)` | Checks whether a value exists in the BST. |
126
+ | `__contains__(value)` | Supports the `value in tree` operation. |
127
+ | `minimum()` | Returns the node containing the minimum value. |
128
+ | `maximum()` | Returns the node containing the maximum value. |
129
+ | `min()` | Returns the minimum value in the BST. |
130
+ | `max()` | Returns the maximum value in the BST. |
131
+ | `clear()` | Removes all nodes from the tree. |
132
+ | `is_empty()` | Checks whether the tree is empty. |
133
+ | `size()` | Returns the number of nodes in the tree. |
134
+ | `height()` | Returns the height of the tree. |
135
+ | `count_leaves()` | Returns the number of leaf nodes. |
136
+ | `count_internal_nodes()` | Returns the number of internal nodes. |
137
+ | `invert_tree()` | Inverts the tree in-place. |
138
+
139
+ ---
140
+
141
+ ## Tree Traversal Iterators
142
+
143
+ `stepps` provides iterators implementing the standard binary tree traversal
144
+ orders.
145
+
146
+ ### PreOrderIterator
147
+
148
+ Traverses the tree using:
149
+
150
+ `Root → Left → Right`
151
+
152
+ ### InOrderIterator
153
+
154
+ Traverses the tree using:
155
+
156
+ `Left → Root → Right`
157
+
158
+ ### PostOrderIterator
159
+
160
+ Traverses the tree using:
161
+
162
+ `Left → Right → Root`
163
+
164
+ ### LevelOrderIterator
165
+
166
+ Traverses the tree level by level from left to right.
167
+
168
+ ### Iterator API
169
+
170
+ All traversal iterators implement the common `BinaryTreeIterator` interface.
171
+
172
+ | Method | Description |
173
+ |---|---|
174
+ | `__iter__()` | Returns the iterator itself. |
175
+ | `__next__()` | Returns the next node in the traversal and raises `StopIteration` when complete. |
176
+
177
+ ---
178
+
179
+ ## Tree Builders
180
+
181
+ `TreeBuilder` defines the common interface for constructing a binary tree from
182
+ a sequence.
183
+
184
+ ### TreeBuilder Method
185
+
186
+ | Method | Description |
187
+ |---|---|
188
+ | `build(sequence)` | Builds and returns a binary tree from the supplied sequence. Returns `None` for an empty sequence. |
189
+
190
+ The package provides the following builder interfaces and implementations:
191
+
192
+ - `LevelOrderTreeBuilder`
193
+ - `LevelOrderTreeBuilderImpl`
194
+ - `InOrderTreeBuilder`
195
+ - `InOrderTreeBuilderImpl`
196
+ - `PreOrderTreeBuilder`
197
+ - `PreOrderTreeBuilderImpl`
198
+ - `PostOrderTreeBuilder`
199
+ - `PostOrderTreeBuilderImpl`
200
+
201
+ Each builder constructs a tree whose corresponding traversal reproduces the
202
+ input sequence.
203
+
204
+ ---
205
+
206
+ ## Tree Visualization
207
+
208
+ The visualization package provides interfaces and implementations for
209
+ displaying binary trees in the CLI.
210
+
211
+ ### Visualization Components
212
+
213
+ - `TreeVisualizer`
214
+ - `CliTreeVisualizer`
215
+ - `CliTreeVisualizerImpl`
216
+
217
+ ### Visualization Method
218
+
219
+ | Method | Description |
220
+ |---|---|
221
+ | `treevisualizer(root)` | Displays the supplied binary tree in a CLI-friendly tree representation. |
222
+
223
+ ---
224
+
225
+ ## Binary Node
226
+
227
+ `BinaryNode[T]` is the generic node type used by the binary tree structures.
228
+
229
+ Each node provides:
230
+
231
+ | Attribute | Description |
232
+ |---|---|
233
+ | `value` | The value stored in the node. |
234
+ | `left` | Reference to the left child node or `None`. |
235
+ | `right` | Reference to the right child node or `None`. |
236
+
237
+ ---
238
+
239
+ ## Tree Statistics
240
+
241
+ The binary tree implementation provides the following statistics:
242
+
243
+ | Method | Description |
244
+ |---|---|
245
+ | `size()` | Returns the total number of nodes. |
246
+ | `height()` | Returns the height of the tree. |
247
+ | `count_leaves()` | Returns the number of leaf nodes. |
248
+ | `count_internal_nodes()` | Returns the number of internal nodes. |
249
+ | `is_empty()` | Returns whether the tree contains no nodes. |
250
+
251
+ The height convention is:
252
+
253
+ - Empty tree: `-1`
254
+ - Single-node tree: `0`
255
+
256
+ ---
257
+
258
+ ## Complexity
259
+
260
+ ### Binary Search Tree
261
+
262
+ | Operation | Average | Worst Case |
263
+ |---|---:|---:|
264
+ | Search | `O(log n)` | `O(n)` |
265
+ | Insert | `O(log n)` | `O(n)` |
266
+ | Delete | `O(log n)` | `O(n)` |
267
+ | Minimum | `O(log n)` | `O(n)` |
268
+ | Maximum | `O(log n)` | `O(n)` |
269
+
270
+ ### Tree Builders
271
+
272
+ All tree builders construct the tree in:
273
+
274
+ - Time: `O(n)`
275
+ - Total space: `O(n)`
276
+
277
+ The recursive builders use `O(log n)` auxiliary stack space for the balanced
278
+ trees they construct.
279
+
280
+ ---
281
+
282
+
283
+ ## Testing
284
+
285
+ The project uses `pytest` for testing.
286
+
287
+ Run the complete test suite:
288
+
289
+ ```bash
290
+ python -m pytest
291
+ ```
292
+
293
+ Run tests with output enabled:
294
+
295
+ ```bash
296
+ python -m pytest -s
297
+ ```
298
+ Run the test suite along with doctests:
299
+
300
+ ```bash
301
+ pytest --cov --cov-branch --doctest-modules
302
+ ```
303
+
304
+ Generate a coverage report:
305
+
306
+ ```bash
307
+ python -m pytest --cov=stepps --cov-report=term-missing
308
+ ```
309
+
310
+ The test suite covers:
311
+
312
+ - Binary tree operations.
313
+ - Binary search tree operations.
314
+ - Tree traversal iterators.
315
+ - Tree builders.
316
+ - Tree visualization.
317
+ - Empty and single-node trees.
318
+ - Different tree sizes and structures.
319
+ - Traversal sequence reconstruction.
320
+
321
+ ---
322
+
323
+ ## Type Checking
324
+
325
+ The project uses MyPy for static type checking.
326
+
327
+ ```bash
328
+ mypy -p stepps
329
+ ```
330
+
331
+ The public APIs use Python generic type parameters to provide type-safe
332
+ operations across nodes, trees, iterators, and tree builders.
333
+
334
+ ---
335
+
336
+ ## Linting and Formatting
337
+
338
+ The project uses Ruff for linting and formatting.
339
+
340
+ Check for linting issues:
341
+
342
+ ```bash
343
+ ruff check .
344
+ ```
345
+
346
+ Automatically fix supported linting issues:
347
+
348
+ ```bash
349
+ ruff check --fix .
350
+ ```
351
+
352
+ Format the project:
353
+
354
+ ```bash
355
+ ruff format .
356
+ ```
357
+
358
+ Check formatting without modifying files:
359
+
360
+ ```bash
361
+ ruff format --check .
362
+ ```
363
+
364
+ ---
365
+
366
+ ## Contributing
367
+
368
+ Clone the repository:
369
+
370
+ ```bash
371
+ git clone https://github.com/Vaastav-Technologies/py-stepps.git
372
+ cd py-stepps
373
+ ```
374
+
375
+ Install the project in editable mode:
376
+
377
+ ```bash
378
+ pip install -e .
379
+ ```
380
+
381
+ Before submitting changes, run:
382
+
383
+ ```bash
384
+ python -m pytest
385
+ python -m mypy .
386
+ ruff check .
387
+ ruff format --check .
388
+ ```
389
+
390
+ Please add or update tests when modifying existing functionality or adding
391
+ new functionality.
392
+
393
+ ---
394
+
395
+ ## License
396
+
397
+ See [LICENSE](./LICENSE) for the license under which this project is
398
+ distributed.
399
+
400
+ ---
401
+
402
+ ## Links
403
+
404
+ - GitHub: https://github.com/Vaastav-Technologies/py-stepps