pythonstl 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 (38) hide show
  1. pythonstl-0.1.0/LICENSE +21 -0
  2. pythonstl-0.1.0/PKG-INFO +437 -0
  3. pythonstl-0.1.0/README.md +405 -0
  4. pythonstl-0.1.0/pyproject.toml +76 -0
  5. pythonstl-0.1.0/pythonstl/__init__.py +45 -0
  6. pythonstl-0.1.0/pythonstl/core/__init__.py +32 -0
  7. pythonstl-0.1.0/pythonstl/core/base.py +51 -0
  8. pythonstl-0.1.0/pythonstl/core/exceptions.py +57 -0
  9. pythonstl-0.1.0/pythonstl/core/iterator.py +187 -0
  10. pythonstl-0.1.0/pythonstl/facade/__init__.py +10 -0
  11. pythonstl-0.1.0/pythonstl/facade/map.py +270 -0
  12. pythonstl-0.1.0/pythonstl/facade/priority_queue.py +200 -0
  13. pythonstl-0.1.0/pythonstl/facade/queue.py +203 -0
  14. pythonstl-0.1.0/pythonstl/facade/set.py +247 -0
  15. pythonstl-0.1.0/pythonstl/facade/stack.py +188 -0
  16. pythonstl-0.1.0/pythonstl/facade/vector.py +369 -0
  17. pythonstl-0.1.0/pythonstl/implementations/__init__.py +3 -0
  18. pythonstl-0.1.0/pythonstl/implementations/associative/__init__.py +6 -0
  19. pythonstl-0.1.0/pythonstl/implementations/associative/_map_impl.py +164 -0
  20. pythonstl-0.1.0/pythonstl/implementations/associative/_set_impl.py +139 -0
  21. pythonstl-0.1.0/pythonstl/implementations/heaps/__init__.py +5 -0
  22. pythonstl-0.1.0/pythonstl/implementations/heaps/_priority_queue_impl.py +118 -0
  23. pythonstl-0.1.0/pythonstl/implementations/linear/__init__.py +7 -0
  24. pythonstl-0.1.0/pythonstl/implementations/linear/_queue_impl.py +117 -0
  25. pythonstl-0.1.0/pythonstl/implementations/linear/_stack_impl.py +99 -0
  26. pythonstl-0.1.0/pythonstl/implementations/linear/_vector_impl.py +251 -0
  27. pythonstl-0.1.0/pythonstl.egg-info/PKG-INFO +437 -0
  28. pythonstl-0.1.0/pythonstl.egg-info/SOURCES.txt +36 -0
  29. pythonstl-0.1.0/pythonstl.egg-info/dependency_links.txt +1 -0
  30. pythonstl-0.1.0/pythonstl.egg-info/top_level.txt +1 -0
  31. pythonstl-0.1.0/setup.cfg +4 -0
  32. pythonstl-0.1.0/setup.py +39 -0
  33. pythonstl-0.1.0/tests/test_map.py +111 -0
  34. pythonstl-0.1.0/tests/test_priority_queue.py +101 -0
  35. pythonstl-0.1.0/tests/test_queue.py +95 -0
  36. pythonstl-0.1.0/tests/test_set.py +97 -0
  37. pythonstl-0.1.0/tests/test_stack.py +88 -0
  38. pythonstl-0.1.0/tests/test_vector.py +153 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PySTL Contributors
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.
@@ -0,0 +1,437 @@
1
+ Metadata-Version: 2.4
2
+ Name: pythonstl
3
+ Version: 0.1.0
4
+ Summary: C++ STL-style containers implemented in Python using the Facade Design Pattern
5
+ Home-page: https://github.com/yourusername/pystl
6
+ Author: PySTL Contributors
7
+ Author-email: PySTL Contributors <pythonstl@example.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/AnshMNSoni/STL
10
+ Project-URL: Repository, https://github.com/AnshMNSoni/STL
11
+ Project-URL: Issues, https://github.com/AnshMNSoni/STL/issues
12
+ Project-URL: Documentation, https://github.com/AnshMNSoni/STL#readme
13
+ Keywords: stl,data-structures,containers,facade-pattern,cpp-stl,standard-template-library
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Software Development :: Libraries
23
+ Classifier: Typing :: Typed
24
+ Classifier: Operating System :: OS Independent
25
+ Requires-Python: >=3.10
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Dynamic: author
29
+ Dynamic: home-page
30
+ Dynamic: license-file
31
+ Dynamic: requires-python
32
+
33
+ # PythonSTL - Python Standard Template Library
34
+
35
+ [![Python Version](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
36
+ [![PyPI version](https://img.shields.io/pypi/v/pythonstl.svg)](https://pypi.org/project/pythonstl/)
37
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
38
+ [![Version](https://img.shields.io/badge/version-0.1.0-brightgreen.svg)](https://github.com/AnshMNSoni/STL)
39
+
40
+ A production-ready Python package that replicates C++ STL-style data structures using the **Facade Design Pattern**. PythonSTL provides clean, familiar interfaces for developers coming from C++ while maintaining Pythonic best practices.
41
+
42
+ ## ๐ŸŽฏ Features
43
+
44
+ - **C++ STL Compliance**: Exact method names and semantics matching C++ STL
45
+ - **Facade Design Pattern**: Clean separation between interface and implementation
46
+ - **Iterator Support**: STL-style iterators (begin, end, rbegin, rend) and Python iteration
47
+ - **Python Integration**: Magic methods (__len__, __bool__, __contains__, __repr__, __eq__)
48
+ - **Type Safety**: Full type hints throughout the codebase
49
+ - **Copy Operations**: Deep copy support with copy(), __copy__(), and __deepcopy__()
50
+ - **Comprehensive Documentation**: Detailed docstrings with time complexity annotations
51
+ - **Production Quality**: Proper error handling, PEP8 compliance, and extensive testing
52
+ - **Zero Dependencies**: Core package has no external dependencies
53
+
54
+ ## ๐Ÿ“ฆ Installation
55
+
56
+ ```bash
57
+ pip install pythonstl
58
+ ```
59
+
60
+ Or install from source:
61
+
62
+ ```bash
63
+ git clone https://github.com/AnshMNSoni/STL.git
64
+ cd STL
65
+ pip install -e .
66
+ ```
67
+
68
+ ## ๐Ÿš€ Quick Start
69
+
70
+ ```python
71
+ from pythonstl import stack, queue, vector, stl_set, stl_map, priority_queue
72
+
73
+ # Stack (LIFO) - Now with Python magic methods!
74
+ s = stack()
75
+ s.push(10)
76
+ s.push(20)
77
+ print(s.top()) # 20
78
+ print(len(s)) # 2 - Python len() support
79
+ print(bool(s)) # True - Python bool() support
80
+
81
+ # Vector (Dynamic Array) - With iterators!
82
+ v = vector()
83
+ v.push_back(100)
84
+ v.push_back(200)
85
+ v.push_back(300)
86
+ v.reserve(1000) # Pre-allocate capacity
87
+ print(len(v)) # 3
88
+ print(200 in v) # True - Python 'in' operator
89
+
90
+ # Iterate using STL-style iterators
91
+ for elem in v.begin():
92
+ print(elem)
93
+
94
+ # Or use Python iteration
95
+ for elem in v:
96
+ print(elem)
97
+
98
+ # Set (Unique Elements) - With magic methods
99
+ s = stl_set()
100
+ s.insert(5)
101
+ s.insert(10)
102
+ print(5 in s) # True
103
+ print(len(s)) # 2
104
+
105
+ # Map (Key-Value Pairs) - With iteration
106
+ m = stl_map()
107
+ m.insert("key1", 100)
108
+ m.insert("key2", 200)
109
+ print("key1" in m) # True
110
+ for key, value in m:
111
+ print(f"{key}: {value}")
112
+
113
+ # Priority Queue - With comparator support
114
+ pq_max = priority_queue(comparator="max") # Max-heap (default)
115
+ pq_min = priority_queue(comparator="min") # Min-heap
116
+ pq_max.push(30)
117
+ pq_max.push(10)
118
+ pq_max.push(20)
119
+ print(pq_max.top()) # 30
120
+ ```
121
+
122
+ ## ๐Ÿ“š Data Structures
123
+
124
+ ### Stack
125
+
126
+ LIFO (Last-In-First-Out) container adapter.
127
+
128
+ **Methods:**
129
+ - `push(value)` - Add element to top
130
+ - `pop()` - Remove top element
131
+ - `top()` - Access top element
132
+ - `empty()` - Check if empty
133
+ - `size()` - Get number of elements
134
+ - `copy()` - Create deep copy
135
+
136
+ **Python Integration:**
137
+ - `len(s)` - Get size
138
+ - `bool(s)` - Check if non-empty
139
+ - `repr(s)` - String representation
140
+ - `s1 == s2` - Equality comparison
141
+
142
+ ### Queue
143
+
144
+ FIFO (First-In-First-Out) container adapter.
145
+
146
+ **Methods:**
147
+ - `push(value)` - Add element to back
148
+ - `pop()` - Remove front element
149
+ - `front()` - Access front element
150
+ - `back()` - Access back element
151
+ - `empty()` - Check if empty
152
+ - `size()` - Get number of elements
153
+ - `copy()` - Create deep copy
154
+
155
+ **Python Integration:**
156
+ - `len(q)` - Get size
157
+ - `bool(q)` - Check if non-empty
158
+ - `repr(q)` - String representation
159
+ - `q1 == q2` - Equality comparison
160
+
161
+ ### Vector
162
+
163
+ Dynamic array with capacity management.
164
+
165
+ **Methods:**
166
+ - `push_back(value)` - Add element to end
167
+ - `pop_back()` - Remove last element
168
+ - `at(index)` - Access element with bounds checking
169
+ - `insert(position, value)` - Insert element at position
170
+ - `erase(position)` - Remove element at position
171
+ - `clear()` - Remove all elements
172
+ - `reserve(capacity)` - Pre-allocate capacity
173
+ - `shrink_to_fit()` - Reduce capacity to size
174
+ - `size()` - Get number of elements
175
+ - `capacity()` - Get current capacity
176
+ - `empty()` - Check if empty
177
+ - `begin()` - Get forward iterator
178
+ - `end()` - Get end iterator
179
+ - `rbegin()` - Get reverse iterator
180
+ - `rend()` - Get reverse end iterator
181
+ - `copy()` - Create deep copy
182
+
183
+ **Python Integration:**
184
+ - `len(v)` - Get size
185
+ - `bool(v)` - Check if non-empty
186
+ - `value in v` - Check if value exists
187
+ - `repr(v)` - String representation
188
+ - `v1 == v2` - Equality comparison
189
+ - `v1 < v2` - Lexicographic comparison
190
+ - `for elem in v` - Python iteration
191
+
192
+ ### Set
193
+
194
+ Associative container storing unique elements.
195
+
196
+ **Methods:**
197
+ - `insert(value)` - Add element
198
+ - `erase(value)` - Remove element
199
+ - `find(value)` - Check if element exists
200
+ - `empty()` - Check if empty
201
+ - `size()` - Get number of elements
202
+ - `begin()` - Get iterator
203
+ - `end()` - Get end iterator
204
+ - `copy()` - Create deep copy
205
+
206
+ **Python Integration:**
207
+ - `len(s)` - Get size
208
+ - `bool(s)` - Check if non-empty
209
+ - `value in s` - Check if value exists
210
+ - `repr(s)` - String representation
211
+ - `s1 == s2` - Equality comparison
212
+ - `for elem in s` - Python iteration
213
+
214
+ ### Map
215
+
216
+ Associative container storing key-value pairs.
217
+
218
+ **Methods:**
219
+ - `insert(key, value)` - Add or update key-value pair
220
+ - `erase(key)` - Remove key-value pair
221
+ - `find(key)` - Check if key exists
222
+ - `at(key)` - Access value by key
223
+ - `empty()` - Check if empty
224
+ - `size()` - Get number of pairs
225
+ - `begin()` - Get iterator
226
+ - `end()` - Get end iterator
227
+ - `copy()` - Create deep copy
228
+
229
+ **Python Integration:**
230
+ - `len(m)` - Get size
231
+ - `bool(m)` - Check if non-empty
232
+ - `key in m` - Check if key exists
233
+ - `repr(m)` - String representation
234
+ - `m1 == m2` - Equality comparison
235
+ - `for key, value in m` - Python iteration
236
+
237
+ ### Priority Queue
238
+
239
+ Container adapter providing priority-based access.
240
+
241
+ **Methods:**
242
+ - `push(value)` - Insert element
243
+ - `pop()` - Remove top element
244
+ - `top()` - Access top element
245
+ - `empty()` - Check if empty
246
+ - `size()` - Get number of elements
247
+ - `copy()` - Create deep copy
248
+
249
+ **Comparator Support:**
250
+ - `priority_queue(comparator="max")` - Max-heap (default)
251
+ - `priority_queue(comparator="min")` - Min-heap
252
+
253
+ **Python Integration:**
254
+ - `len(pq)` - Get size
255
+ - `bool(pq)` - Check if non-empty
256
+ - `repr(pq)` - String representation
257
+ - `pq1 == pq2` - Equality comparison
258
+
259
+ ## โšก Time Complexity Reference
260
+
261
+ | Container | Operation | Complexity |
262
+ |-----------|-----------|------------|
263
+ | **Stack** | push() | O(1) amortized |
264
+ | | pop() | O(1) |
265
+ | | top() | O(1) |
266
+ | **Queue** | push() | O(1) |
267
+ | | pop() | O(1) |
268
+ | | front() / back() | O(1) |
269
+ | **Vector** | push_back() | O(1) amortized |
270
+ | | pop_back() | O(1) |
271
+ | | at() | O(1) |
272
+ | | insert() | O(n) |
273
+ | | erase() | O(n) |
274
+ | | reserve() | O(1) |
275
+ | | shrink_to_fit() | O(1) |
276
+ | **Set** | insert() | O(1) average |
277
+ | | erase() | O(1) average |
278
+ | | find() | O(1) average |
279
+ | **Map** | insert() | O(1) average |
280
+ | | erase() | O(1) average |
281
+ | | find() | O(1) average |
282
+ | | at() | O(1) average |
283
+ | **Priority Queue** | push() | O(log n) |
284
+ | | pop() | O(log n) |
285
+ | | top() | O(1) |
286
+
287
+ ## ๐Ÿ—๏ธ Architecture
288
+
289
+ PythonSTL follows the **Facade Design Pattern** with three layers:
290
+
291
+ 1. **Core Layer** (`pythonstl/core/`)
292
+ - Base classes and type definitions
293
+ - Custom exceptions
294
+ - Iterator classes
295
+
296
+ 2. **Implementation Layer** (`pythonstl/implementations/`)
297
+ - Private implementation classes (prefixed with `_`)
298
+ - Efficient use of Python built-ins
299
+ - Not intended for direct user access
300
+
301
+ 3. **Facade Layer** (`pythonstl/facade/`)
302
+ - Public-facing classes
303
+ - Clean, STL-compliant API
304
+ - Delegates to implementation layer
305
+
306
+ This architecture ensures:
307
+ - **Encapsulation**: Internal implementation is hidden
308
+ - **Maintainability**: Easy to modify internals without breaking API
309
+ - **Testability**: Each layer can be tested independently
310
+
311
+ ## ๐Ÿ”’ Thread Safety
312
+
313
+ **Important:** PythonSTL containers are **NOT thread-safe** by default. If you need to use them in a multi-threaded environment, you must provide your own synchronization (e.g., using `threading.Lock`).
314
+
315
+ ```python
316
+ import threading
317
+ from pythonstl import stack
318
+
319
+ s = stack()
320
+ lock = threading.Lock()
321
+
322
+ def thread_safe_push(value):
323
+ with lock:
324
+ s.push(value)
325
+ ```
326
+
327
+ ## ๐ŸŽจ Design Decisions
328
+
329
+ ### Why Facade Pattern?
330
+
331
+ - **Clean API**: Users interact with simple, well-defined interfaces
332
+ - **Flexibility**: Internal implementation can change without affecting users
333
+ - **Type Safety**: Facade layer enforces type contracts
334
+ - **Error Handling**: Consistent error messages across all containers
335
+
336
+ ### Why STL Naming?
337
+
338
+ - **Familiarity**: C++ developers can use PythonSTL immediately
339
+ - **Consistency**: Predictable method names across containers
340
+ - **Documentation**: Extensive C++ STL documentation applies
341
+
342
+ ### Python Integration
343
+
344
+ Full Python integration while maintaining STL compatibility:
345
+ - Magic methods for natural Python usage
346
+ - Iterator protocol support
347
+ - Copy protocol support
348
+ - Maintains backward compatibility
349
+
350
+ ## ๐Ÿ“Š Benchmarks
351
+
352
+ PythonSTL provides benchmarks comparing performance against Python built-ins:
353
+
354
+ ```bash
355
+ python benchmarks/benchmark_stack.py
356
+ python benchmarks/benchmark_vector.py
357
+ python benchmarks/benchmark_map.py
358
+ ```
359
+
360
+ **Expected Overhead:** 1.1x - 1.5x compared to native Python structures
361
+
362
+ The facade pattern adds minimal overhead while providing:
363
+ - STL-style API
364
+ - Better error messages
365
+ - Bounds checking
366
+ - Type safety
367
+
368
+ See `benchmarks/README.md` for detailed analysis.
369
+
370
+ ## ๐Ÿงช Testing
371
+
372
+ Run the test suite:
373
+
374
+ ```bash
375
+ # Install test dependencies
376
+ pip install pytest pytest-cov
377
+
378
+ # Run tests
379
+ pytest tests/
380
+
381
+ # Run with coverage
382
+ pytest tests/ --cov=pythonstl --cov-report=html
383
+ ```
384
+
385
+ ## ๐Ÿ› ๏ธ Development
386
+
387
+ ### Setup
388
+
389
+ ```bash
390
+ git clone https://github.com/AnshMNSoni/STL.git
391
+ cd STL
392
+ pip install -e ".[dev]"
393
+ ```
394
+
395
+ ### Code Quality
396
+
397
+ ```bash
398
+ # Type checking
399
+ mypy pythonstl/
400
+
401
+ # Linting
402
+ flake8 pythonstl/
403
+
404
+ # Run all checks
405
+ pytest && mypy pythonstl/ && flake8 pythonstl/
406
+ ```
407
+
408
+ ## ๐Ÿ“ License
409
+
410
+ MIT License - see LICENSE file for details.
411
+
412
+ ## ๐Ÿค Contributing
413
+
414
+ Contributions are welcome! Please:
415
+ 1. Fork the repository
416
+ 2. Create a feature branch
417
+ 3. Add tests for new features
418
+ 4. Ensure all tests pass
419
+ 5. Submit a pull request
420
+
421
+ ## ๐Ÿ“ฎ Contact
422
+
423
+ - GitHub: [@AnshMNSoni](https://github.com/AnshMNSoni)
424
+ - Issues: [GitHub Issues](https://github.com/AnshMNSoni/STL/issues)
425
+
426
+ ## ๐Ÿ—บ๏ธ Roadmap
427
+
428
+ Future enhancements:
429
+ - Additional STL containers (deque, list, multiset, multimap)
430
+ - Algorithm library (sort, search, transform)
431
+ - Custom allocators
432
+ - Thread-safe variants
433
+ - Performance optimizations
434
+
435
+ ---
436
+
437
+ **PythonSTL v0.1.0** - Bringing C++ STL elegance to Python ๐Ÿ