stepps 0.0.0.dev0__tar.gz → 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.
Files changed (54) hide show
  1. {stepps-0.0.0.dev0 → stepps-0.1.0}/LICENSE +1 -1
  2. stepps-0.1.0/PKG-INFO +483 -0
  3. stepps-0.1.0/README.md +453 -0
  4. {stepps-0.0.0.dev0 → stepps-0.1.0}/pyproject.toml +1 -1
  5. stepps-0.1.0/src/stepps/TreeBuilder/__init__.py +13 -0
  6. stepps-0.1.0/src/stepps/TreeBuilder/inorder_tree_builder.py +8 -0
  7. stepps-0.1.0/src/stepps/TreeBuilder/inorder_tree_builder_impl.py +52 -0
  8. stepps-0.1.0/src/stepps/TreeBuilder/level_order_tree_builder.py +8 -0
  9. stepps-0.1.0/src/stepps/TreeBuilder/level_order_tree_builder_impl.py +46 -0
  10. stepps-0.1.0/src/stepps/TreeBuilder/postorder_tree_builder.py +8 -0
  11. stepps-0.1.0/src/stepps/TreeBuilder/postorder_tree_builder_impl.py +64 -0
  12. stepps-0.1.0/src/stepps/TreeBuilder/preorder_tree_builder.py +8 -0
  13. stepps-0.1.0/src/stepps/TreeBuilder/preorder_tree_builder_impl.py +61 -0
  14. stepps-0.1.0/src/stepps/TreeBuilder/tree_builder.py +21 -0
  15. stepps-0.1.0/src/stepps/iterators/__init__.py +13 -0
  16. stepps-0.1.0/src/stepps/iterators/base_iterator.py +30 -0
  17. stepps-0.1.0/src/stepps/iterators/inorder.py +39 -0
  18. stepps-0.1.0/src/stepps/iterators/levelorder.py +40 -0
  19. stepps-0.1.0/src/stepps/iterators/postorder.py +56 -0
  20. stepps-0.1.0/src/stepps/iterators/preorder.py +47 -0
  21. stepps-0.1.0/src/stepps/nodes/__init__.py +3 -0
  22. stepps-0.1.0/src/stepps/nodes/binary_node.py +61 -0
  23. stepps-0.1.0/src/stepps/py.typed +0 -0
  24. stepps-0.1.0/src/stepps/trees/__init__.py +68 -0
  25. stepps-0.1.0/src/stepps/trees/binary_tree.py +98 -0
  26. stepps-0.1.0/src/stepps/trees/binary_tree_impl.py +228 -0
  27. stepps-0.1.0/src/stepps/trees/bst.py +63 -0
  28. stepps-0.1.0/src/stepps/trees/bst_impl.py +187 -0
  29. stepps-0.1.0/src/stepps/trees/tree.py +48 -0
  30. stepps-0.1.0/src/stepps/visualizer/__init__.py +7 -0
  31. stepps-0.1.0/src/stepps/visualizer/cli_visualizer.py +19 -0
  32. stepps-0.1.0/src/stepps/visualizer/cli_visualizer_impl.py +53 -0
  33. stepps-0.1.0/src/stepps/visualizer/tree_visualizer.py +16 -0
  34. stepps-0.1.0/src/stepps.egg-info/PKG-INFO +483 -0
  35. stepps-0.1.0/src/stepps.egg-info/SOURCES.txt +44 -0
  36. stepps-0.1.0/src/stepps.egg-info/top_level.txt +1 -0
  37. stepps-0.1.0/tests/test_binary_tree.py +177 -0
  38. stepps-0.1.0/tests/test_bst.py +161 -0
  39. stepps-0.1.0/tests/test_inorder_tree_builder.py +93 -0
  40. stepps-0.1.0/tests/test_level_order_tree_builder.py +76 -0
  41. stepps-0.1.0/tests/test_postorder_tree_builder.py +93 -0
  42. stepps-0.1.0/tests/test_preorder_tree_builder.py +93 -0
  43. stepps-0.1.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.1.0}/setup.cfg +0 -0
  53. /stepps-0.0.0.dev0/src/algor/py.typed → /stepps-0.1.0/src/stepps/__init__.py +0 -0
  54. {stepps-0.0.0.dev0 → stepps-0.1.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.1.0/PKG-INFO ADDED
@@ -0,0 +1,483 @@
1
+ Metadata-Version: 2.4
2
+ Name: stepps
3
+ Version: 0.1.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
+ ## Project Structure
283
+
284
+ ```text
285
+ src/
286
+ └── stepps/
287
+ ├── iterators/
288
+ │ ├── base_iterator.py
289
+ │ ├── inorder.py
290
+ │ ├── levelorder.py
291
+ │ ├── postorder.py
292
+ │ └── preorder.py
293
+ │
294
+ ├── nodes/
295
+ │ └── binary_node.py
296
+ │
297
+ ├── TreeBuilder/
298
+ │ ├── tree_builder.py
299
+ │ ├── level_order_tree_builder.py
300
+ │ ├── level_order_tree_builder_impl.py
301
+ │ ├── inorder_tree_builder.py
302
+ │ ├── inorder_tree_builder_impl.py
303
+ │ ├── preorder_tree_builder.py
304
+ │ ├── preorder_tree_builder_impl.py
305
+ │ ├── postorder_tree_builder.py
306
+ │ └── postorder_tree_builder_impl.py
307
+ │
308
+ ├── trees/
309
+ │ ├── tree.py
310
+ │ ├── binary_tree.py
311
+ │ ├── binary_tree_impl.py
312
+ │ ├── bst.py
313
+ │ └── bst_impl.py
314
+ │
315
+ └── visualizer/
316
+ ├── tree_visualizer.py
317
+ ├── cli_visualizer.py
318
+ └── cli_visualizer_impl.py
319
+
320
+ tests/
321
+ ├── test_binary_tree.py
322
+ ├── test_bst.py
323
+ ├── test_inorder_tree_builder.py
324
+ ├── test_level_order_tree_builder.py
325
+ ├── test_postorder_tree_builder.py
326
+ ├── test_preorder_tree_builder.py
327
+ └── test_visualizer.py
328
+ ```
329
+
330
+ ---
331
+
332
+ ## Architecture
333
+
334
+ The project separates interfaces from their default implementations.
335
+
336
+ ### Tree Builders
337
+
338
+ ```text
339
+ TreeBuilder
340
+ ├── LevelOrderTreeBuilder
341
+ │ └── LevelOrderTreeBuilderImpl
342
+ ├── InOrderTreeBuilder
343
+ │ └── InOrderTreeBuilderImpl
344
+ ├── PreOrderTreeBuilder
345
+ │ └── PreOrderTreeBuilderImpl
346
+ └── PostOrderTreeBuilder
347
+ └── PostOrderTreeBuilderImpl
348
+ ```
349
+
350
+ ### Trees
351
+
352
+ ```text
353
+ Tree
354
+ │
355
+ └── BinaryTree
356
+ │
357
+ └── BinaryTreeImpl
358
+ │
359
+ └── BSTImpl
360
+ ```
361
+
362
+ This architecture keeps public interfaces separate from their concrete
363
+ implementations and allows additional implementations to be introduced.
364
+
365
+ ---
366
+
367
+ ## Testing
368
+
369
+ The project uses `pytest` for testing.
370
+
371
+ Run the complete test suite:
372
+
373
+ ```bash
374
+ python -m pytest -v
375
+ ```
376
+
377
+ Run tests with output enabled:
378
+
379
+ ```bash
380
+ python -m pytest -v -s
381
+ ```
382
+
383
+ Generate a coverage report:
384
+
385
+ ```bash
386
+ python -m pytest --cov=stepps --cov-report=term-missing
387
+ ```
388
+
389
+ The test suite covers:
390
+
391
+ - Binary tree operations.
392
+ - Binary search tree operations.
393
+ - Tree traversal iterators.
394
+ - Tree builders.
395
+ - Tree visualization.
396
+ - Empty and single-node trees.
397
+ - Different tree sizes and structures.
398
+ - Traversal sequence reconstruction.
399
+
400
+ ---
401
+
402
+ ## Type Checking
403
+
404
+ The project uses MyPy for static type checking.
405
+
406
+ ```bash
407
+ python -m mypy .
408
+ ```
409
+
410
+ The public APIs use Python generic type parameters to provide type-safe
411
+ operations across nodes, trees, iterators, and tree builders.
412
+
413
+ ---
414
+
415
+ ## Linting and Formatting
416
+
417
+ The project uses Ruff for linting and formatting.
418
+
419
+ Check for linting issues:
420
+
421
+ ```bash
422
+ ruff check .
423
+ ```
424
+
425
+ Automatically fix supported linting issues:
426
+
427
+ ```bash
428
+ ruff check --fix .
429
+ ```
430
+
431
+ Format the project:
432
+
433
+ ```bash
434
+ ruff format .
435
+ ```
436
+
437
+ Check formatting without modifying files:
438
+
439
+ ```bash
440
+ ruff format --check .
441
+ ```
442
+
443
+ ---
444
+
445
+ ## Contributing
446
+
447
+ Clone the repository:
448
+
449
+ ```bash
450
+ git clone https://github.com/Vaastav-Technologies/py-stepps.git
451
+ cd py-stepps
452
+ ```
453
+
454
+ Install the project in editable mode:
455
+
456
+ ```bash
457
+ pip install -e .
458
+ ```
459
+
460
+ Before submitting changes, run:
461
+
462
+ ```bash
463
+ python -m pytest
464
+ python -m mypy .
465
+ ruff check .
466
+ ruff format --check .
467
+ ```
468
+
469
+ Please add or update tests when modifying existing functionality or adding
470
+ new functionality.
471
+
472
+ ---
473
+
474
+ ## License
475
+
476
+ See [LICENSE](./LICENSE) for the license under which this project is
477
+ distributed.
478
+
479
+ ---
480
+
481
+ ## Links
482
+
483
+ - GitHub: https://github.com/Vaastav-Technologies/py-stepps