core-data-structures 1.1.0__tar.gz → 1.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 (25) hide show
  1. core_data_structures-1.2.0/PKG-INFO +173 -0
  2. core_data_structures-1.2.0/README.rst +140 -0
  3. core_data_structures-1.2.0/core_data_structures.egg-info/PKG-INFO +173 -0
  4. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/core_data_structures.egg-info/SOURCES.txt +2 -1
  5. core_data_structures-1.2.0/core_data_structures.egg-info/requires.txt +5 -0
  6. core_data_structures-1.2.0/data_structures/__init__.py +18 -0
  7. core_data_structures-1.2.0/data_structures/graphs/__init__.py +12 -0
  8. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/data_structures/graphs/graphs.py +29 -17
  9. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/data_structures/graphs/vertex.py +10 -4
  10. core_data_structures-1.2.0/data_structures/trees/__init__.py +12 -0
  11. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/data_structures/trees/binary_tree.py +12 -7
  12. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/data_structures/trees/simple_tree.py +2 -0
  13. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/pyproject.toml +17 -13
  14. core_data_structures-1.1.0/PKG-INFO +0 -64
  15. core_data_structures-1.1.0/README.md +0 -33
  16. core_data_structures-1.1.0/core_data_structures.egg-info/PKG-INFO +0 -64
  17. core_data_structures-1.1.0/core_data_structures.egg-info/requires.txt +0 -7
  18. core_data_structures-1.1.0/data_structures/__init__.py +0 -4
  19. core_data_structures-1.1.0/data_structures/graphs/__init__.py +0 -4
  20. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/LICENSE +0 -0
  21. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/core_data_structures.egg-info/dependency_links.txt +0 -0
  22. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/core_data_structures.egg-info/top_level.txt +0 -0
  23. /core_data_structures-1.1.0/data_structures/trees/__init__.py → /core_data_structures-1.2.0/data_structures/py.typed +0 -0
  24. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/setup.cfg +0 -0
  25. {core_data_structures-1.1.0 → core_data_structures-1.2.0}/setup.py +0 -0
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.4
2
+ Name: core-data-structures
3
+ Version: 1.2.0
4
+ Summary: This project/library contains commons data structures...
5
+ Author-email: Alejandro Cora González <alek.cora.glez@gmail.com>
6
+ Maintainer: Alejandro Cora González
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://gitlab.com/bytecode-solutions/core/core-data-structures
9
+ Project-URL: Repository, https://gitlab.com/bytecode-solutions/core/core-data-structures
10
+ Project-URL: Documentation, https://core-data-structures.readthedocs.io/en/latest/
11
+ Project-URL: Issues, https://gitlab.com/bytecode-solutions/core/core-data-structures/-/issues
12
+ Project-URL: Changelog, https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/master/CHANGELOG.md
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Classifier: Topic :: Utilities
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/x-rst
27
+ License-File: LICENSE
28
+ Requires-Dist: typing-extensions>=4.8.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: core-dev-tools>=2.0.0; extra == "dev"
31
+ Requires-Dist: core-tests>=2.1.0; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ core-data-structures
35
+ ===============================================================================
36
+
37
+ A Python library providing common data structures including graphs and trees,
38
+ with built-in traversal and path-finding algorithms.
39
+
40
+ ===============================================================================
41
+
42
+ .. image:: https://img.shields.io/pypi/pyversions/core-data-structures.svg
43
+ :target: https://pypi.org/project/core-data-structures/
44
+ :alt: Python Versions
45
+
46
+ .. image:: https://img.shields.io/badge/license-MIT-blue.svg
47
+ :target: https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/main/LICENSE
48
+ :alt: License
49
+
50
+ .. image:: https://gitlab.com/bytecode-solutions/core/core-data-structures/badges/release/pipeline.svg
51
+ :target: https://gitlab.com/bytecode-solutions/core/core-data-structures/-/pipelines
52
+ :alt: Pipeline Status
53
+
54
+ .. image:: https://readthedocs.org/projects/core-data-structures/badge/?version=latest
55
+ :target: https://readthedocs.org/projects/core-data-structures/
56
+ :alt: Docs Status
57
+
58
+ .. image:: https://img.shields.io/badge/security-bandit-yellow.svg
59
+ :target: https://github.com/PyCQA/bandit
60
+ :alt: Security
61
+
62
+ |
63
+
64
+
65
+ Features
66
+ ===============================================================================
67
+
68
+ - **Graphs** — undirected weighted graph with adjacency dictionary representation.
69
+
70
+ - Breadth-first search (BFS)
71
+ - Depth-first search (DFS)
72
+ - Path finding (single path, all paths, shortest path)
73
+
74
+ - **Trees** — binary tree and simple nested-dictionary tree.
75
+
76
+ - Pre-order, in-order, post-order, and level-order traversal
77
+ - Recursive and iterative variants
78
+ - Tree depth calculation
79
+
80
+
81
+ Quick Start
82
+ ===============================================================================
83
+
84
+ Installation
85
+ -------------------------------------------------------------------------------
86
+
87
+ Install from PyPI using pip:
88
+
89
+ .. code-block:: bash
90
+
91
+ pip install core-data-structures
92
+ uv pip install core-data-structures # Or using UV...
93
+ pip install -e ".[dev]" # For development...
94
+
95
+
96
+ Setting Up Environment
97
+ -------------------------------------------------------------------------------
98
+
99
+ 1. Install required libraries:
100
+
101
+ .. code-block:: bash
102
+
103
+ pip install --upgrade pip
104
+ pip install virtualenv
105
+
106
+ 2. Create Python virtual environment:
107
+
108
+ .. code-block:: bash
109
+
110
+ virtualenv --python=python3.12 .venv
111
+
112
+ 3. Activate the virtual environment:
113
+
114
+ .. code-block:: bash
115
+
116
+ source .venv/bin/activate
117
+
118
+ 4. Install packages:
119
+
120
+ .. code-block:: bash
121
+
122
+ pip install .
123
+ pip install -e ".[dev]"
124
+
125
+ Check tests and coverage
126
+ -------------------------------------------------------------------------------
127
+
128
+ .. code-block:: bash
129
+
130
+ python manager.py run-tests
131
+ python manager.py run-coverage
132
+
133
+
134
+ Contributing
135
+ ===============================================================================
136
+
137
+ Contributions are welcome! Please:
138
+
139
+ 1. Fork the repository
140
+ 2. Create a feature branch
141
+ 3. Write tests for new functionality
142
+ 4. Ensure all tests pass: ``python manager.py run-tests``
143
+ 5. Run linting: ``pylint data_structures``
144
+ 6. Run security checks: ``bandit -r data_structures``
145
+ 7. Submit a pull request
146
+
147
+
148
+ License
149
+ ===============================================================================
150
+
151
+ This project is licensed under the MIT License. See the LICENSE file for details.
152
+
153
+
154
+ Links
155
+ ===============================================================================
156
+
157
+ * **Documentation:** https://core-data-structures.readthedocs.io/en/latest/
158
+ * **Repository:** https://gitlab.com/bytecode-solutions/core/core-data-structures
159
+ * **Issues:** https://gitlab.com/bytecode-solutions/core/core-data-structures/-/issues
160
+ * **Changelog:** https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/master/CHANGELOG.md
161
+ * **PyPI:** https://pypi.org/project/core-data-structures/
162
+
163
+
164
+ Support
165
+ ===============================================================================
166
+
167
+ For questions or support, please open an issue on GitLab or contact the maintainers.
168
+
169
+
170
+ Authors
171
+ ===============================================================================
172
+
173
+ * **Alejandro Cora González** - *Initial work* - alek.cora.glez@gmail.com
@@ -0,0 +1,140 @@
1
+ core-data-structures
2
+ ===============================================================================
3
+
4
+ A Python library providing common data structures including graphs and trees,
5
+ with built-in traversal and path-finding algorithms.
6
+
7
+ ===============================================================================
8
+
9
+ .. image:: https://img.shields.io/pypi/pyversions/core-data-structures.svg
10
+ :target: https://pypi.org/project/core-data-structures/
11
+ :alt: Python Versions
12
+
13
+ .. image:: https://img.shields.io/badge/license-MIT-blue.svg
14
+ :target: https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/main/LICENSE
15
+ :alt: License
16
+
17
+ .. image:: https://gitlab.com/bytecode-solutions/core/core-data-structures/badges/release/pipeline.svg
18
+ :target: https://gitlab.com/bytecode-solutions/core/core-data-structures/-/pipelines
19
+ :alt: Pipeline Status
20
+
21
+ .. image:: https://readthedocs.org/projects/core-data-structures/badge/?version=latest
22
+ :target: https://readthedocs.org/projects/core-data-structures/
23
+ :alt: Docs Status
24
+
25
+ .. image:: https://img.shields.io/badge/security-bandit-yellow.svg
26
+ :target: https://github.com/PyCQA/bandit
27
+ :alt: Security
28
+
29
+ |
30
+
31
+
32
+ Features
33
+ ===============================================================================
34
+
35
+ - **Graphs** — undirected weighted graph with adjacency dictionary representation.
36
+
37
+ - Breadth-first search (BFS)
38
+ - Depth-first search (DFS)
39
+ - Path finding (single path, all paths, shortest path)
40
+
41
+ - **Trees** — binary tree and simple nested-dictionary tree.
42
+
43
+ - Pre-order, in-order, post-order, and level-order traversal
44
+ - Recursive and iterative variants
45
+ - Tree depth calculation
46
+
47
+
48
+ Quick Start
49
+ ===============================================================================
50
+
51
+ Installation
52
+ -------------------------------------------------------------------------------
53
+
54
+ Install from PyPI using pip:
55
+
56
+ .. code-block:: bash
57
+
58
+ pip install core-data-structures
59
+ uv pip install core-data-structures # Or using UV...
60
+ pip install -e ".[dev]" # For development...
61
+
62
+
63
+ Setting Up Environment
64
+ -------------------------------------------------------------------------------
65
+
66
+ 1. Install required libraries:
67
+
68
+ .. code-block:: bash
69
+
70
+ pip install --upgrade pip
71
+ pip install virtualenv
72
+
73
+ 2. Create Python virtual environment:
74
+
75
+ .. code-block:: bash
76
+
77
+ virtualenv --python=python3.12 .venv
78
+
79
+ 3. Activate the virtual environment:
80
+
81
+ .. code-block:: bash
82
+
83
+ source .venv/bin/activate
84
+
85
+ 4. Install packages:
86
+
87
+ .. code-block:: bash
88
+
89
+ pip install .
90
+ pip install -e ".[dev]"
91
+
92
+ Check tests and coverage
93
+ -------------------------------------------------------------------------------
94
+
95
+ .. code-block:: bash
96
+
97
+ python manager.py run-tests
98
+ python manager.py run-coverage
99
+
100
+
101
+ Contributing
102
+ ===============================================================================
103
+
104
+ Contributions are welcome! Please:
105
+
106
+ 1. Fork the repository
107
+ 2. Create a feature branch
108
+ 3. Write tests for new functionality
109
+ 4. Ensure all tests pass: ``python manager.py run-tests``
110
+ 5. Run linting: ``pylint data_structures``
111
+ 6. Run security checks: ``bandit -r data_structures``
112
+ 7. Submit a pull request
113
+
114
+
115
+ License
116
+ ===============================================================================
117
+
118
+ This project is licensed under the MIT License. See the LICENSE file for details.
119
+
120
+
121
+ Links
122
+ ===============================================================================
123
+
124
+ * **Documentation:** https://core-data-structures.readthedocs.io/en/latest/
125
+ * **Repository:** https://gitlab.com/bytecode-solutions/core/core-data-structures
126
+ * **Issues:** https://gitlab.com/bytecode-solutions/core/core-data-structures/-/issues
127
+ * **Changelog:** https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/master/CHANGELOG.md
128
+ * **PyPI:** https://pypi.org/project/core-data-structures/
129
+
130
+
131
+ Support
132
+ ===============================================================================
133
+
134
+ For questions or support, please open an issue on GitLab or contact the maintainers.
135
+
136
+
137
+ Authors
138
+ ===============================================================================
139
+
140
+ * **Alejandro Cora González** - *Initial work* - alek.cora.glez@gmail.com
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.4
2
+ Name: core-data-structures
3
+ Version: 1.2.0
4
+ Summary: This project/library contains commons data structures...
5
+ Author-email: Alejandro Cora González <alek.cora.glez@gmail.com>
6
+ Maintainer: Alejandro Cora González
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://gitlab.com/bytecode-solutions/core/core-data-structures
9
+ Project-URL: Repository, https://gitlab.com/bytecode-solutions/core/core-data-structures
10
+ Project-URL: Documentation, https://core-data-structures.readthedocs.io/en/latest/
11
+ Project-URL: Issues, https://gitlab.com/bytecode-solutions/core/core-data-structures/-/issues
12
+ Project-URL: Changelog, https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/master/CHANGELOG.md
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Classifier: Topic :: Utilities
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/x-rst
27
+ License-File: LICENSE
28
+ Requires-Dist: typing-extensions>=4.8.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: core-dev-tools>=2.0.0; extra == "dev"
31
+ Requires-Dist: core-tests>=2.1.0; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ core-data-structures
35
+ ===============================================================================
36
+
37
+ A Python library providing common data structures including graphs and trees,
38
+ with built-in traversal and path-finding algorithms.
39
+
40
+ ===============================================================================
41
+
42
+ .. image:: https://img.shields.io/pypi/pyversions/core-data-structures.svg
43
+ :target: https://pypi.org/project/core-data-structures/
44
+ :alt: Python Versions
45
+
46
+ .. image:: https://img.shields.io/badge/license-MIT-blue.svg
47
+ :target: https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/main/LICENSE
48
+ :alt: License
49
+
50
+ .. image:: https://gitlab.com/bytecode-solutions/core/core-data-structures/badges/release/pipeline.svg
51
+ :target: https://gitlab.com/bytecode-solutions/core/core-data-structures/-/pipelines
52
+ :alt: Pipeline Status
53
+
54
+ .. image:: https://readthedocs.org/projects/core-data-structures/badge/?version=latest
55
+ :target: https://readthedocs.org/projects/core-data-structures/
56
+ :alt: Docs Status
57
+
58
+ .. image:: https://img.shields.io/badge/security-bandit-yellow.svg
59
+ :target: https://github.com/PyCQA/bandit
60
+ :alt: Security
61
+
62
+ |
63
+
64
+
65
+ Features
66
+ ===============================================================================
67
+
68
+ - **Graphs** — undirected weighted graph with adjacency dictionary representation.
69
+
70
+ - Breadth-first search (BFS)
71
+ - Depth-first search (DFS)
72
+ - Path finding (single path, all paths, shortest path)
73
+
74
+ - **Trees** — binary tree and simple nested-dictionary tree.
75
+
76
+ - Pre-order, in-order, post-order, and level-order traversal
77
+ - Recursive and iterative variants
78
+ - Tree depth calculation
79
+
80
+
81
+ Quick Start
82
+ ===============================================================================
83
+
84
+ Installation
85
+ -------------------------------------------------------------------------------
86
+
87
+ Install from PyPI using pip:
88
+
89
+ .. code-block:: bash
90
+
91
+ pip install core-data-structures
92
+ uv pip install core-data-structures # Or using UV...
93
+ pip install -e ".[dev]" # For development...
94
+
95
+
96
+ Setting Up Environment
97
+ -------------------------------------------------------------------------------
98
+
99
+ 1. Install required libraries:
100
+
101
+ .. code-block:: bash
102
+
103
+ pip install --upgrade pip
104
+ pip install virtualenv
105
+
106
+ 2. Create Python virtual environment:
107
+
108
+ .. code-block:: bash
109
+
110
+ virtualenv --python=python3.12 .venv
111
+
112
+ 3. Activate the virtual environment:
113
+
114
+ .. code-block:: bash
115
+
116
+ source .venv/bin/activate
117
+
118
+ 4. Install packages:
119
+
120
+ .. code-block:: bash
121
+
122
+ pip install .
123
+ pip install -e ".[dev]"
124
+
125
+ Check tests and coverage
126
+ -------------------------------------------------------------------------------
127
+
128
+ .. code-block:: bash
129
+
130
+ python manager.py run-tests
131
+ python manager.py run-coverage
132
+
133
+
134
+ Contributing
135
+ ===============================================================================
136
+
137
+ Contributions are welcome! Please:
138
+
139
+ 1. Fork the repository
140
+ 2. Create a feature branch
141
+ 3. Write tests for new functionality
142
+ 4. Ensure all tests pass: ``python manager.py run-tests``
143
+ 5. Run linting: ``pylint data_structures``
144
+ 6. Run security checks: ``bandit -r data_structures``
145
+ 7. Submit a pull request
146
+
147
+
148
+ License
149
+ ===============================================================================
150
+
151
+ This project is licensed under the MIT License. See the LICENSE file for details.
152
+
153
+
154
+ Links
155
+ ===============================================================================
156
+
157
+ * **Documentation:** https://core-data-structures.readthedocs.io/en/latest/
158
+ * **Repository:** https://gitlab.com/bytecode-solutions/core/core-data-structures
159
+ * **Issues:** https://gitlab.com/bytecode-solutions/core/core-data-structures/-/issues
160
+ * **Changelog:** https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/master/CHANGELOG.md
161
+ * **PyPI:** https://pypi.org/project/core-data-structures/
162
+
163
+
164
+ Support
165
+ ===============================================================================
166
+
167
+ For questions or support, please open an issue on GitLab or contact the maintainers.
168
+
169
+
170
+ Authors
171
+ ===============================================================================
172
+
173
+ * **Alejandro Cora González** - *Initial work* - alek.cora.glez@gmail.com
@@ -1,5 +1,5 @@
1
1
  LICENSE
2
- README.md
2
+ README.rst
3
3
  pyproject.toml
4
4
  setup.py
5
5
  core_data_structures.egg-info/PKG-INFO
@@ -8,6 +8,7 @@ core_data_structures.egg-info/dependency_links.txt
8
8
  core_data_structures.egg-info/requires.txt
9
9
  core_data_structures.egg-info/top_level.txt
10
10
  data_structures/__init__.py
11
+ data_structures/py.typed
11
12
  data_structures/graphs/__init__.py
12
13
  data_structures/graphs/graphs.py
13
14
  data_structures/graphs/vertex.py
@@ -0,0 +1,5 @@
1
+ typing-extensions>=4.8.0
2
+
3
+ [dev]
4
+ core-dev-tools>=2.0.0
5
+ core-tests>=2.1.0
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """Core data structures package."""
4
+
5
+ from importlib.metadata import PackageNotFoundError
6
+ from importlib.metadata import version
7
+
8
+
9
+ try:
10
+ __version__ = version("core-data-structures")
11
+
12
+ except PackageNotFoundError:
13
+ __version__ = "unknown"
14
+
15
+
16
+ __all__ = [
17
+ "__version__",
18
+ ]
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """Graph data structures package."""
4
+
5
+ from .graphs import Graph
6
+ from . vertex import Vertex
7
+
8
+
9
+ __all__ = [
10
+ "Graph",
11
+ "Vertex",
12
+ ]
@@ -1,19 +1,25 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ """Graph data structure with common traversal and path-finding algorithms."""
4
+
3
5
  import json
4
6
  from queue import Queue
5
- from typing import Any, Dict, List
7
+ from typing import Any, Dict, List, Optional
6
8
 
7
9
  from .vertex import Vertex
8
10
 
9
11
 
10
12
  class Graph:
13
+ """Undirected weighted graph backed by an adjacency dictionary of Vertex objects."""
14
+
11
15
  def __init__(self):
12
16
  self.vertices = {}
13
17
 
14
18
  @classmethod
15
19
  def create_example_graph(cls):
16
- """
20
+ r"""
21
+ Example graph structure::
22
+
17
23
  A
18
24
  / \
19
25
  B --- C
@@ -39,12 +45,14 @@ class Graph:
39
45
 
40
46
  def __str__(self):
41
47
  return json.dumps({
42
- key: [x for x in vertex.get_connections_ids()] for key, vertex in self.vertices.items()
48
+ key: list(vertex.get_connections_ids())
49
+ for key, vertex in self.vertices.items()
43
50
  })
44
51
 
45
52
  def __repr__(self):
46
53
  return json.dumps({
47
- key: [x for x in vertex.get_connections_ids()] for key, vertex in self.vertices.items()
54
+ key: list(vertex.get_connections_ids())
55
+ for key, vertex in self.vertices.items()
48
56
  })
49
57
 
50
58
  @classmethod
@@ -67,12 +75,14 @@ class Graph:
67
75
  return graph
68
76
 
69
77
  def add_vertex(self, key) -> Vertex:
78
+ """ Add a vertex for the given key if it does not already exist and return it. """
79
+
70
80
  if key not in self.vertices:
71
81
  self.vertices[key] = Vertex(key)
72
82
 
73
83
  return self.vertices[key]
74
84
 
75
- def get_vertex(self, key) -> Vertex:
85
+ def get_vertex(self, key) -> Optional[Vertex]:
76
86
  """ Return a vertex by key """
77
87
  return self.vertices.get(key, None)
78
88
 
@@ -81,6 +91,8 @@ class Graph:
81
91
  return self.vertices
82
92
 
83
93
  def add_edge(self, key_vertex1, key_vertex2, weight=0):
94
+ """ Add a directed edge from key_vertex1 to key_vertex2 with an optional weight. """
95
+
84
96
  if key_vertex1 not in self.vertices:
85
97
  self.add_vertex(key_vertex1)
86
98
 
@@ -112,7 +124,7 @@ class Graph:
112
124
 
113
125
  return visited
114
126
 
115
- def depth_first_search(self, node_id, visited: List = None):
127
+ def depth_first_search(self, node_id, visited: Optional[List] = None):
116
128
  """
117
129
  Depth First Traversal Algorithm...
118
130
 
@@ -135,10 +147,7 @@ class Graph:
135
147
 
136
148
  return visited
137
149
 
138
- def find_path(self, start, end, path: List = None):
139
- if not path:
140
- path = []
141
-
150
+ def find_path(self, start, end, path: Optional[List] = None):
142
151
  """
143
152
  Determine a path between two nodes...
144
153
 
@@ -151,6 +160,9 @@ class Graph:
151
160
  ["A", "B", "C", "D"]
152
161
  """
153
162
 
163
+ if not path:
164
+ path = []
165
+
154
166
  path = path + [start]
155
167
  if start == end:
156
168
  return path
@@ -158,7 +170,7 @@ class Graph:
158
170
  if start not in self:
159
171
  return None
160
172
 
161
- for node in self.get_vertex(start).get_connections():
173
+ for node in self.vertices[start].get_connections():
162
174
  if node.id not in path:
163
175
  new_path = self.find_path(node.id, end, path)
164
176
  if new_path:
@@ -166,10 +178,7 @@ class Graph:
166
178
 
167
179
  return None
168
180
 
169
- def find_all_paths(self, start, end, path: List = None):
170
- if not path:
171
- path = []
172
-
181
+ def find_all_paths(self, start, end, path: Optional[List] = None):
173
182
  """
174
183
  Determine all paths between two nodes...
175
184
 
@@ -182,6 +191,9 @@ class Graph:
182
191
  [["A", "B", "C", "D"], ["A", "B", "D"], ["A", "C", "D"]]
183
192
  """
184
193
 
194
+ if not path:
195
+ path = []
196
+
185
197
  path = path + [start]
186
198
  if start == end:
187
199
  return [path]
@@ -190,7 +202,7 @@ class Graph:
190
202
  return []
191
203
 
192
204
  paths = []
193
- for node in self.get_vertex(start).get_connections():
205
+ for node in self.vertices[start].get_connections():
194
206
  if node.id not in path:
195
207
  new_paths = self.find_all_paths(node.id, end, path)
196
208
  paths.extend(new_paths)
@@ -217,7 +229,7 @@ class Graph:
217
229
 
218
230
  while not q.empty():
219
231
  key = q.get()
220
- for next_ in self.get_vertex(key).get_connections():
232
+ for next_ in self.vertices[key].get_connections():
221
233
  next_ = next_.id
222
234
  if next_ not in dist:
223
235
  dist[next_] = dist[key] + [next_]
@@ -1,17 +1,22 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ """Vertex node used within graph data structures."""
4
+
5
+ import sys
3
6
  from typing import Dict, List
4
7
 
5
- try:
8
+ if sys.version_info >= (3, 11):
6
9
  from typing import Self
7
-
8
- except ImportError:
9
- # For earlier versions...
10
+ else:
10
11
  from typing_extensions import Self
11
12
 
12
13
 
13
14
  class Vertex:
15
+ """Represents a node in a graph with weighted connections to neighbors."""
16
+
14
17
  def __init__(self, key):
18
+ """ Initialize the vertex with a key and no connections. """
19
+
15
20
  self._id = key
16
21
  self._connections = {}
17
22
 
@@ -20,6 +25,7 @@ class Vertex:
20
25
 
21
26
  @property
22
27
  def id(self):
28
+ """ The vertex identifier. """
23
29
  return self._id
24
30
 
25
31
  @id.setter
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """Tree data structures package."""
4
+
5
+ from .binary_tree import BinaryTree
6
+ from .simple_tree import Tree
7
+
8
+
9
+ __all__ = [
10
+ "BinaryTree",
11
+ "Tree",
12
+ ]
@@ -1,7 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ """Binary tree data structure with recursive and iterative traversal algorithms."""
4
+
3
5
  from queue import Queue
4
- from typing import List
6
+ from typing import List, Optional
5
7
 
6
8
 
7
9
  class BinaryTree:
@@ -11,13 +13,15 @@ class BinaryTree:
11
13
  left child and the right child...
12
14
  """
13
15
 
14
- def __init__(self, value):
16
+ def __init__(self, value) -> None:
15
17
  self.value = value
16
- self.right = None
17
- self.left = None
18
+ self.right: Optional[BinaryTree] = None
19
+ self.left: Optional[BinaryTree] = None
18
20
 
19
21
  @staticmethod
20
22
  def create_example_tree():
23
+ """ Build and return a complete binary tree with 15 nodes for testing. """
24
+
21
25
  root = BinaryTree(1)
22
26
  tree_node2, tree_node3 = BinaryTree(2), BinaryTree(3)
23
27
  tree_node4, tree_node5 = BinaryTree(4), BinaryTree(5)
@@ -60,7 +64,8 @@ class BinaryTree:
60
64
  """
61
65
 
62
66
  stack: List[BinaryTree] = []
63
- node, res = self, []
67
+ node: Optional[BinaryTree] = self
68
+ res = []
64
69
 
65
70
  while stack or node:
66
71
  while node:
@@ -100,7 +105,7 @@ class BinaryTree:
100
105
 
101
106
  res = []
102
107
  stack: List[BinaryTree] = []
103
- node = self
108
+ node: Optional[BinaryTree] = self
104
109
 
105
110
  while stack or node:
106
111
  while node:
@@ -164,7 +169,7 @@ class BinaryTree:
164
169
  """
165
170
 
166
171
  res = []
167
- q = Queue()
172
+ q: Queue[BinaryTree] = Queue()
168
173
  q.put(self)
169
174
 
170
175
  while not q.empty():
@@ -1,5 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ """Simple tree data structure backed by a nested dictionary."""
4
+
3
5
  from typing import Dict
4
6
 
5
7
 
@@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
9
9
  [project]
10
10
  name = "core-data-structures"
11
11
  description = "This project/library contains commons data structures..."
12
- version = "1.1.0"
12
+ version = "1.2.0"
13
13
 
14
14
  authors = [
15
15
  {name = "Alejandro Cora González", email = "alek.cora.glez@gmail.com"}
@@ -19,38 +19,42 @@ maintainers = [
19
19
  {name = "Alejandro Cora González"}
20
20
  ]
21
21
 
22
- requires-python = ">=3.7"
23
- license = {text = "MIT"}
24
- readme = "README.md"
22
+ requires-python = ">=3.9"
23
+ license = "MIT"
24
+ readme = "README.rst"
25
25
 
26
26
  classifiers = [
27
27
  # Classifiers -> https://pypi.org/classifiers/
28
- "License :: OSI Approved :: MIT License",
29
28
  "Intended Audience :: Developers",
30
29
  "Development Status :: 5 - Production/Stable",
31
30
  "Topic :: Software Development :: Libraries :: Python Modules",
32
31
  "Topic :: Utilities",
33
32
  "Programming Language :: Python :: 3",
34
- "Programming Language :: Python :: 3.7",
35
- "Programming Language :: Python :: 3.8",
36
33
  "Programming Language :: Python :: 3.9",
37
34
  "Programming Language :: Python :: 3.10",
38
35
  "Programming Language :: Python :: 3.11",
39
36
  "Programming Language :: Python :: 3.12",
40
- "Programming Language :: Python :: 3.13"
37
+ "Programming Language :: Python :: 3.13",
38
+ "Programming Language :: Python :: 3.14",
39
+ "Programming Language :: Python :: Implementation :: PyPy",
41
40
  ]
42
41
 
43
42
  dependencies = [
44
- "core-tests>=1.1.0",
45
- "typing-extensions>=4.8.0; python_version >= '3.8' and python_version < '3.11'",
46
- "typing-extensions>=4.2.0; python_version >= '3.7' and python_version < '3.8'"
43
+ "typing-extensions>=4.8.0",
47
44
  ]
48
45
 
49
- #[project.optional-dependencies]
50
- #test = []
46
+ [project.optional-dependencies]
47
+ dev = [
48
+ "core-dev-tools>=2.0.0",
49
+ "core-tests>=2.1.0",
50
+ ]
51
51
 
52
52
  [project.urls]
53
53
  Homepage = "https://gitlab.com/bytecode-solutions/core/core-data-structures"
54
54
  Repository = "https://gitlab.com/bytecode-solutions/core/core-data-structures"
55
+ Documentation = "https://core-data-structures.readthedocs.io/en/latest/"
55
56
  Issues = "https://gitlab.com/bytecode-solutions/core/core-data-structures/-/issues"
56
57
  Changelog = "https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/master/CHANGELOG.md"
58
+
59
+ [tool.setuptools.package-data]
60
+ "data_structures" = ["py.typed"]
@@ -1,64 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: core-data-structures
3
- Version: 1.1.0
4
- Summary: This project/library contains commons data structures...
5
- Author-email: Alejandro Cora González <alek.cora.glez@gmail.com>
6
- Maintainer: Alejandro Cora González
7
- License: MIT
8
- Project-URL: Homepage, https://gitlab.com/bytecode-solutions/core/core-data-structures
9
- Project-URL: Repository, https://gitlab.com/bytecode-solutions/core/core-data-structures
10
- Project-URL: Issues, https://gitlab.com/bytecode-solutions/core/core-data-structures/-/issues
11
- Project-URL: Changelog, https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/master/CHANGELOG.md
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Intended Audience :: Developers
14
- Classifier: Development Status :: 5 - Production/Stable
15
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
- Classifier: Topic :: Utilities
17
- Classifier: Programming Language :: Python :: 3
18
- Classifier: Programming Language :: Python :: 3.7
19
- Classifier: Programming Language :: Python :: 3.8
20
- Classifier: Programming Language :: Python :: 3.9
21
- Classifier: Programming Language :: Python :: 3.10
22
- Classifier: Programming Language :: Python :: 3.11
23
- Classifier: Programming Language :: Python :: 3.12
24
- Classifier: Programming Language :: Python :: 3.13
25
- Requires-Python: >=3.7
26
- Description-Content-Type: text/markdown
27
- License-File: LICENSE
28
- Requires-Dist: core-tests>=1.1.0
29
- Requires-Dist: typing-extensions>=4.8.0; python_version >= "3.8" and python_version < "3.11"
30
- Requires-Dist: typing-extensions>=4.2.0; python_version >= "3.7" and python_version < "3.8"
31
-
32
- # core-data-structures
33
- _______________________________________________________________________________
34
-
35
- This project/library contains commons data structures...
36
-
37
- ## Execution Environment
38
-
39
- ### Install libraries
40
- ```commandline
41
- pip install --upgrade pip
42
- pip install virtualenv
43
- ```
44
-
45
- ### Create the Python Virtual Environment.
46
- ```commandline
47
- virtualenv --python=python3.11 .venv
48
- ```
49
-
50
- ### Activate the Virtual Environment.
51
- ```commandline
52
- source .venv/bin/activate
53
- ```
54
-
55
- ### Install required libraries.
56
- ```commandline
57
- pip install .
58
- ```
59
-
60
- ### Check tests and coverage...
61
- ```commandline
62
- python manager.py run-test
63
- python manager.py run-coverage
64
- ```
@@ -1,33 +0,0 @@
1
- # core-data-structures
2
- _______________________________________________________________________________
3
-
4
- This project/library contains commons data structures...
5
-
6
- ## Execution Environment
7
-
8
- ### Install libraries
9
- ```commandline
10
- pip install --upgrade pip
11
- pip install virtualenv
12
- ```
13
-
14
- ### Create the Python Virtual Environment.
15
- ```commandline
16
- virtualenv --python=python3.11 .venv
17
- ```
18
-
19
- ### Activate the Virtual Environment.
20
- ```commandline
21
- source .venv/bin/activate
22
- ```
23
-
24
- ### Install required libraries.
25
- ```commandline
26
- pip install .
27
- ```
28
-
29
- ### Check tests and coverage...
30
- ```commandline
31
- python manager.py run-test
32
- python manager.py run-coverage
33
- ```
@@ -1,64 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: core-data-structures
3
- Version: 1.1.0
4
- Summary: This project/library contains commons data structures...
5
- Author-email: Alejandro Cora González <alek.cora.glez@gmail.com>
6
- Maintainer: Alejandro Cora González
7
- License: MIT
8
- Project-URL: Homepage, https://gitlab.com/bytecode-solutions/core/core-data-structures
9
- Project-URL: Repository, https://gitlab.com/bytecode-solutions/core/core-data-structures
10
- Project-URL: Issues, https://gitlab.com/bytecode-solutions/core/core-data-structures/-/issues
11
- Project-URL: Changelog, https://gitlab.com/bytecode-solutions/core/core-data-structures/-/blob/master/CHANGELOG.md
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Intended Audience :: Developers
14
- Classifier: Development Status :: 5 - Production/Stable
15
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
- Classifier: Topic :: Utilities
17
- Classifier: Programming Language :: Python :: 3
18
- Classifier: Programming Language :: Python :: 3.7
19
- Classifier: Programming Language :: Python :: 3.8
20
- Classifier: Programming Language :: Python :: 3.9
21
- Classifier: Programming Language :: Python :: 3.10
22
- Classifier: Programming Language :: Python :: 3.11
23
- Classifier: Programming Language :: Python :: 3.12
24
- Classifier: Programming Language :: Python :: 3.13
25
- Requires-Python: >=3.7
26
- Description-Content-Type: text/markdown
27
- License-File: LICENSE
28
- Requires-Dist: core-tests>=1.1.0
29
- Requires-Dist: typing-extensions>=4.8.0; python_version >= "3.8" and python_version < "3.11"
30
- Requires-Dist: typing-extensions>=4.2.0; python_version >= "3.7" and python_version < "3.8"
31
-
32
- # core-data-structures
33
- _______________________________________________________________________________
34
-
35
- This project/library contains commons data structures...
36
-
37
- ## Execution Environment
38
-
39
- ### Install libraries
40
- ```commandline
41
- pip install --upgrade pip
42
- pip install virtualenv
43
- ```
44
-
45
- ### Create the Python Virtual Environment.
46
- ```commandline
47
- virtualenv --python=python3.11 .venv
48
- ```
49
-
50
- ### Activate the Virtual Environment.
51
- ```commandline
52
- source .venv/bin/activate
53
- ```
54
-
55
- ### Install required libraries.
56
- ```commandline
57
- pip install .
58
- ```
59
-
60
- ### Check tests and coverage...
61
- ```commandline
62
- python manager.py run-test
63
- python manager.py run-coverage
64
- ```
@@ -1,7 +0,0 @@
1
- core-tests>=1.1.0
2
-
3
- [:python_version >= "3.7" and python_version < "3.8"]
4
- typing-extensions>=4.2.0
5
-
6
- [:python_version >= "3.8" and python_version < "3.11"]
7
- typing-extensions>=4.8.0
@@ -1,4 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- from . import graphs
4
- from . import trees
@@ -1,4 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- from . import graphs
4
- from . import vertex