pythonic-fp-circulararray 6.1.0__py3-none-any.whl → 6.2.0__py3-none-any.whl
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.
- pythonic_fp/circulararray/.mypy_cache/.gitignore +2 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/@plugins_snapshot.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/__future__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/__future__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_ast.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_ast.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_codecs.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_codecs.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_collections_abc.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_collections_abc.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_frozen_importlib.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_frozen_importlib.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_frozen_importlib_external.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_frozen_importlib_external.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_io.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_io.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_sitebuiltins.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_sitebuiltins.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_typeshed/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_typeshed/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_typeshed/importlib.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_typeshed/importlib.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_warnings.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/_warnings.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/abc.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/abc.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/ast.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/ast.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/builtins.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/builtins.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/circulararray/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/circulararray/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/circulararray/auto.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/circulararray/auto.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/circulararray/fixed.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/circulararray/fixed.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/codecs.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/codecs.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/collections/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/collections/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/collections/abc.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/collections/abc.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/contextlib.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/contextlib.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/dataclasses.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/dataclasses.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/_policybase.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/_policybase.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/charset.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/charset.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/contentmanager.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/contentmanager.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/errors.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/errors.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/header.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/header.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/message.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/message.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/policy.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/email/policy.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/enum.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/enum.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/genericpath.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/genericpath.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/_abc.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/_abc.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/_bootstrap.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/_bootstrap.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/_bootstrap_external.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/_bootstrap_external.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/abc.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/abc.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/machinery.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/machinery.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/metadata/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/metadata/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/metadata/_meta.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/metadata/_meta.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/readers.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/readers.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/resources/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/resources/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/resources/_common.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/resources/_common.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/resources/_functional.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/resources/_functional.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/resources/abc.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/importlib/resources/abc.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/io.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/io.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/os/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/os/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/os/path.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/os/path.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/pathlib/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/pathlib/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/posixpath.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/posixpath.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/re.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/re.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/resource.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/resource.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/sre_compile.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/sre_compile.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/sre_constants.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/sre_constants.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/sre_parse.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/sre_parse.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/subprocess.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/subprocess.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/sys/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/sys/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/sys/_monitoring.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/sys/_monitoring.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/types.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/types.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/typing.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/typing.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/typing_extensions.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/typing_extensions.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/warnings.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/warnings.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/zipfile/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/zipfile/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/zipfile/_path/__init__.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/zipfile/_path/__init__.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/zipimport.data.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.13/zipimport.meta.json +1 -0
- pythonic_fp/circulararray/.mypy_cache/3.14/cache.db +0 -0
- pythonic_fp/circulararray/.mypy_cache/CACHEDIR.TAG +3 -0
- pythonic_fp/circulararray/auto.py +197 -106
- pythonic_fp/circulararray/auto.pyi +3 -3
- pythonic_fp/circulararray/fixed.py +194 -110
- pythonic_fp/circulararray/fixed.pyi +5 -5
- {pythonic_fp_circulararray-6.1.0.dist-info → pythonic_fp_circulararray-6.2.0.dist-info}/METADATA +16 -30
- pythonic_fp_circulararray-6.2.0.dist-info/RECORD +145 -0
- pythonic_fp_circulararray-6.1.0.dist-info/RECORD +0 -11
- {pythonic_fp_circulararray-6.1.0.dist-info → pythonic_fp_circulararray-6.2.0.dist-info}/WHEEL +0 -0
- {pythonic_fp_circulararray-6.1.0.dist-info → pythonic_fp_circulararray-6.2.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
from collections.abc import Callable, Iterable, Iterator
|
|
16
|
-
from typing import
|
|
16
|
+
from typing import Final, cast, overload
|
|
17
|
+
|
|
17
18
|
from pythonic_fp.gadgets.sentinels.novalue import NoValue
|
|
18
19
|
|
|
19
20
|
__all__ = ['CA', 'ca']
|
|
@@ -23,26 +24,33 @@ nada: Final[NoValue] = NoValue()
|
|
|
23
24
|
|
|
24
25
|
class CA[X]:
|
|
25
26
|
"""
|
|
26
|
-
.. admonition::
|
|
27
|
+
.. admonition:: Auto resizing circular array CA
|
|
27
28
|
|
|
28
29
|
- O(1) pops either end
|
|
29
30
|
- O(1) amortized pushes either end
|
|
30
31
|
- O(1) indexing, fully supports slicing
|
|
31
|
-
- auto-resizing more storage capacity when necessary,
|
|
32
|
-
|
|
32
|
+
- auto-resizing more storage capacity when necessary,
|
|
33
|
+
manually compatible
|
|
34
|
+
- iterable (see __iter__ method below)
|
|
33
35
|
- comparisons compare identity before equality, like builtins
|
|
34
36
|
- in boolean context, falsy when empty, otherwise truthy
|
|
35
|
-
- function ``ca`` produces auto-resizing circular array
|
|
37
|
+
- function ``ca`` produces auto-resizing circular array
|
|
38
|
+
from arguments
|
|
36
39
|
|
|
37
40
|
"""
|
|
41
|
+
|
|
38
42
|
__slots__ = '_xs', '_cnt', '_cap', '_front', '_rear'
|
|
39
43
|
|
|
40
44
|
def __init__(self, *xs: Iterable[X]) -> None:
|
|
41
45
|
"""
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
.. admonition:: initializer
|
|
47
|
+
|
|
48
|
+
Populate ``CA`` with an optional iterable
|
|
49
|
+
from front (left) to rear (right).
|
|
50
|
+
|
|
51
|
+
:param xs: Takes an optional iterable parameter.
|
|
52
|
+
:raises ValueError: When more than one parameter is provided.
|
|
53
|
+
:raises TypeError: When passed a non-iterable parameter.
|
|
46
54
|
|
|
47
55
|
"""
|
|
48
56
|
if (size := len(xs)) > 1:
|
|
@@ -77,9 +85,7 @@ class CA[X]:
|
|
|
77
85
|
self._front,
|
|
78
86
|
self._cap,
|
|
79
87
|
) = (
|
|
80
|
-
self._xs[: self._front]
|
|
81
|
-
+ [nada] * self._cap
|
|
82
|
-
+ self._xs[self._front :],
|
|
88
|
+
self._xs[: self._front] + [nada] * self._cap + self._xs[self._front :],
|
|
83
89
|
self._front + self._cap,
|
|
84
90
|
2 * self._cap,
|
|
85
91
|
)
|
|
@@ -140,61 +146,48 @@ class CA[X]:
|
|
|
140
146
|
)
|
|
141
147
|
|
|
142
148
|
def __bool__(self) -> bool:
|
|
149
|
+
"""
|
|
150
|
+
.. admonition:: bool
|
|
151
|
+
|
|
152
|
+
- falsy when empty
|
|
153
|
+
- truthy when not empty
|
|
154
|
+
|
|
155
|
+
:returns: ``True`` when not empty,
|
|
156
|
+
``False`` otherwise.
|
|
157
|
+
|
|
158
|
+
"""
|
|
143
159
|
return self._cnt > 0
|
|
144
160
|
|
|
145
161
|
def __len__(self) -> int:
|
|
162
|
+
"""
|
|
163
|
+
.. admonition:: length
|
|
164
|
+
|
|
165
|
+
Number of items in the ``CA``.
|
|
166
|
+
|
|
167
|
+
:returns: The number of items in the ``CA``.
|
|
168
|
+
|
|
169
|
+
"""
|
|
146
170
|
return self._cnt
|
|
147
171
|
|
|
148
|
-
def
|
|
172
|
+
def __iter__(self) -> Iterator[X]:
|
|
149
173
|
"""
|
|
150
|
-
.. admonition::
|
|
174
|
+
.. admonition:: iterate
|
|
151
175
|
|
|
152
|
-
|
|
176
|
+
Iterates circular array, left (front) to right (rear).
|
|
153
177
|
|
|
154
|
-
|
|
155
|
-
:returns: ``True`` if ``other`` is another ``CA`` whose
|
|
156
|
-
contents compare as equal to the corresponding
|
|
157
|
-
contents of the ``CA``, otherwise ``False``.
|
|
178
|
+
:yields: The ``CA`` contents front to rear.
|
|
158
179
|
|
|
159
|
-
|
|
160
|
-
if self is other:
|
|
161
|
-
return True
|
|
162
|
-
if not isinstance(other, type(self)):
|
|
163
|
-
return False
|
|
180
|
+
.. warning::
|
|
164
181
|
|
|
165
|
-
|
|
166
|
-
front1,
|
|
167
|
-
cnt1,
|
|
168
|
-
capacity1,
|
|
169
|
-
front2,
|
|
170
|
-
cnt2,
|
|
171
|
-
capacity2,
|
|
172
|
-
) = (
|
|
173
|
-
self._front,
|
|
174
|
-
self._cnt,
|
|
175
|
-
self._cap,
|
|
176
|
-
other._front,
|
|
177
|
-
other._cnt,
|
|
178
|
-
other._cap,
|
|
179
|
-
)
|
|
182
|
+
Not threadsafe, especially for long living iterators.
|
|
180
183
|
|
|
181
|
-
|
|
182
|
-
return False
|
|
184
|
+
.. tip::
|
|
183
185
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
is other._xs[(front2 + nn) % capacity2]
|
|
188
|
-
):
|
|
189
|
-
continue
|
|
190
|
-
if (
|
|
191
|
-
self._xs[(front1 + nn) % capacity1]
|
|
192
|
-
!= other._xs[(front2 + nn) % capacity2]
|
|
193
|
-
):
|
|
194
|
-
return False
|
|
195
|
-
return True
|
|
186
|
+
Cache contents to make more thread tolerant. Put
|
|
187
|
+
a lock around circular array during caching process
|
|
188
|
+
to make threadsafe.
|
|
196
189
|
|
|
197
|
-
|
|
190
|
+
"""
|
|
198
191
|
if self._cnt > 0:
|
|
199
192
|
(
|
|
200
193
|
capacity,
|
|
@@ -214,6 +207,24 @@ class CA[X]:
|
|
|
214
207
|
yield cast(X, current_state[position])
|
|
215
208
|
|
|
216
209
|
def __reversed__(self) -> Iterator[X]:
|
|
210
|
+
"""
|
|
211
|
+
.. admonition:: reverse iterate
|
|
212
|
+
|
|
213
|
+
Iterates circular array, right (rear) to left (front).
|
|
214
|
+
|
|
215
|
+
:yields: The ``CA`` contents right to left.
|
|
216
|
+
|
|
217
|
+
.. warning
|
|
218
|
+
|
|
219
|
+
Not thread safe, especially for long living iterators.
|
|
220
|
+
|
|
221
|
+
.. tip::
|
|
222
|
+
|
|
223
|
+
Cache contents to make more thread tolerant. Put
|
|
224
|
+
a lock around circular array during caching process
|
|
225
|
+
to make threadsafe.
|
|
226
|
+
|
|
227
|
+
"""
|
|
217
228
|
if self._cnt > 0:
|
|
218
229
|
(
|
|
219
230
|
capacity,
|
|
@@ -232,12 +243,68 @@ class CA[X]:
|
|
|
232
243
|
position = (position - 1) % capacity
|
|
233
244
|
yield cast(X, current_state[position])
|
|
234
245
|
|
|
246
|
+
def __eq__(self, other: object) -> bool:
|
|
247
|
+
"""
|
|
248
|
+
.. admonition:: equality comparison
|
|
249
|
+
|
|
250
|
+
Efficiently compare ``CA`` to another object.
|
|
251
|
+
|
|
252
|
+
:param other: The object to be compared.
|
|
253
|
+
:returns: ``True`` if ``other`` is another ``CA`` whose
|
|
254
|
+
contents compare as equal to the corresponding
|
|
255
|
+
contents of the ``CA``, otherwise ``False``.
|
|
256
|
+
|
|
257
|
+
"""
|
|
258
|
+
if self is other:
|
|
259
|
+
return True
|
|
260
|
+
if not isinstance(other, type(self)):
|
|
261
|
+
return False
|
|
262
|
+
|
|
263
|
+
(
|
|
264
|
+
front1,
|
|
265
|
+
cnt1,
|
|
266
|
+
capacity1,
|
|
267
|
+
front2,
|
|
268
|
+
cnt2,
|
|
269
|
+
capacity2,
|
|
270
|
+
) = (
|
|
271
|
+
self._front,
|
|
272
|
+
self._cnt,
|
|
273
|
+
self._cap,
|
|
274
|
+
other._front,
|
|
275
|
+
other._cnt,
|
|
276
|
+
other._cap,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
if cnt1 != cnt2:
|
|
280
|
+
return False
|
|
281
|
+
|
|
282
|
+
for nn in range(cnt1):
|
|
283
|
+
if (
|
|
284
|
+
self._xs[(front1 + nn) % capacity1]
|
|
285
|
+
is other._xs[(front2 + nn) % capacity2]
|
|
286
|
+
):
|
|
287
|
+
continue
|
|
288
|
+
if (
|
|
289
|
+
self._xs[(front1 + nn) % capacity1]
|
|
290
|
+
!= other._xs[(front2 + nn) % capacity2]
|
|
291
|
+
):
|
|
292
|
+
return False
|
|
293
|
+
return True
|
|
294
|
+
|
|
235
295
|
@overload
|
|
236
296
|
def __getitem__(self, idx: int) -> X: ...
|
|
237
297
|
@overload
|
|
238
298
|
def __getitem__(self, idx: slice) -> 'CA[X]': ...
|
|
239
299
|
|
|
240
300
|
def __getitem__(self, idx: int | slice) -> X | 'CA[X]':
|
|
301
|
+
"""
|
|
302
|
+
.. admonition:: getitem
|
|
303
|
+
|
|
304
|
+
Auto resizing circular arrays are fully indexable
|
|
305
|
+
and sliceable.
|
|
306
|
+
|
|
307
|
+
"""
|
|
241
308
|
if isinstance(idx, slice):
|
|
242
309
|
return CA(list(self)[idx])
|
|
243
310
|
|
|
@@ -263,6 +330,13 @@ class CA[X]:
|
|
|
263
330
|
def __setitem__(self, idx: slice, vals: Iterable[X]) -> None: ...
|
|
264
331
|
|
|
265
332
|
def __setitem__(self, idx: int | slice, vals: X | Iterable[X]) -> None:
|
|
333
|
+
"""
|
|
334
|
+
.. admonition:: setitem
|
|
335
|
+
|
|
336
|
+
Auto resizing circular arrays are fully indexable
|
|
337
|
+
and sliceable.
|
|
338
|
+
|
|
339
|
+
"""
|
|
266
340
|
if isinstance(idx, slice):
|
|
267
341
|
if isinstance(vals, Iterable):
|
|
268
342
|
item_list = list(self)
|
|
@@ -306,6 +380,13 @@ class CA[X]:
|
|
|
306
380
|
def __delitem__(self, idx: slice) -> None: ...
|
|
307
381
|
|
|
308
382
|
def __delitem__(self, idx: int | slice) -> None:
|
|
383
|
+
"""
|
|
384
|
+
.. admonition:: delitem
|
|
385
|
+
|
|
386
|
+
Auto resizing circular arrays are fully indexable
|
|
387
|
+
and sliceable.
|
|
388
|
+
|
|
389
|
+
"""
|
|
309
390
|
item_list = list(self)
|
|
310
391
|
del item_list[idx]
|
|
311
392
|
_ca = CA(item_list)
|
|
@@ -326,38 +407,37 @@ class CA[X]:
|
|
|
326
407
|
|
|
327
408
|
def __repr__(self) -> str:
|
|
328
409
|
"""
|
|
329
|
-
.. admonition::
|
|
410
|
+
.. admonition:: repr string
|
|
330
411
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
contents and "repr(xi)" is the repr-string for xi.
|
|
412
|
+
Construct string 'CA(x₁, x₂, … xₙ)' where
|
|
413
|
+
x₁, x₂, … xₙ are the contents displayed with ``repr()``.
|
|
334
414
|
|
|
335
|
-
|
|
415
|
+
:returns: A string to reproduce the ``CA``.
|
|
336
416
|
|
|
337
417
|
"""
|
|
338
418
|
return 'ca(' + ', '.join(map(repr, self)) + ')'
|
|
339
419
|
|
|
340
420
|
def __str__(self) -> str:
|
|
341
421
|
r"""
|
|
342
|
-
.. admonition::
|
|
422
|
+
.. admonition:: user string
|
|
343
423
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
contents displayed as strings.
|
|
424
|
+
Construct string '(\| x₁, x₂, … xₙ \|)' where
|
|
425
|
+
x₁, x₂, ..., xₙ are the contents displayed with ``str()``.
|
|
347
426
|
|
|
348
|
-
|
|
427
|
+
:returns: A string meaningful to an end user.
|
|
349
428
|
|
|
350
429
|
"""
|
|
351
430
|
return '(| ' + ', '.join(map(str, self)) + ' |)'
|
|
352
431
|
|
|
353
432
|
def pushl(self, *xs: X) -> None:
|
|
354
433
|
"""
|
|
355
|
-
.. admonition::
|
|
434
|
+
.. admonition:: push left
|
|
356
435
|
|
|
357
436
|
Push items from the left onto the ``CA`` in the
|
|
358
437
|
order they were iterated.
|
|
359
438
|
|
|
360
|
-
|
|
439
|
+
:param xs: Items to be pushed onto the front of the ``CA``
|
|
440
|
+
from the left.
|
|
361
441
|
|
|
362
442
|
"""
|
|
363
443
|
for x in xs:
|
|
@@ -375,12 +455,13 @@ class CA[X]:
|
|
|
375
455
|
|
|
376
456
|
def pushr(self, *xs: X) -> None:
|
|
377
457
|
"""
|
|
378
|
-
.. admonition::
|
|
458
|
+
.. admonition:: push right
|
|
379
459
|
|
|
380
460
|
Push items from the right onto the ``CA`` in the
|
|
381
461
|
order they were iterated.
|
|
382
462
|
|
|
383
|
-
|
|
463
|
+
:param xs: Items to be pushed onto the rear of
|
|
464
|
+
the ``CA`` from the right.
|
|
384
465
|
|
|
385
466
|
"""
|
|
386
467
|
for item in xs:
|
|
@@ -398,12 +479,12 @@ class CA[X]:
|
|
|
398
479
|
|
|
399
480
|
def popl(self) -> X:
|
|
400
481
|
"""
|
|
401
|
-
.. admonition::
|
|
482
|
+
.. admonition:: pop left
|
|
402
483
|
|
|
403
484
|
Pop a single items off the left side of the ``CA``.
|
|
404
485
|
|
|
405
|
-
|
|
406
|
-
|
|
486
|
+
:returns: Item popped from left side (front) of the ``CA``.
|
|
487
|
+
:raises ValueError: When called on an empty ``CA``.
|
|
407
488
|
|
|
408
489
|
"""
|
|
409
490
|
if self._cnt > 1:
|
|
@@ -439,12 +520,12 @@ class CA[X]:
|
|
|
439
520
|
|
|
440
521
|
def popr(self) -> X:
|
|
441
522
|
"""
|
|
442
|
-
.. admonition::
|
|
523
|
+
.. admonition:: pop right
|
|
443
524
|
|
|
444
525
|
Pop a single items off the right side of the ``CA``.
|
|
445
526
|
|
|
446
|
-
|
|
447
|
-
|
|
527
|
+
:returns: Item popped from right side (rear) of the ``CA``.
|
|
528
|
+
:raises ValueError: When called on an empty ``CA``.
|
|
448
529
|
|
|
449
530
|
"""
|
|
450
531
|
if self._cnt > 1:
|
|
@@ -480,14 +561,14 @@ class CA[X]:
|
|
|
480
561
|
|
|
481
562
|
def popld(self, default: X) -> X:
|
|
482
563
|
"""
|
|
483
|
-
.. admonition::
|
|
564
|
+
.. admonition:: pop Left with default
|
|
484
565
|
|
|
485
566
|
Pop a single items off the left side of the ``CA``.
|
|
486
567
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
568
|
+
:param default: Default value to return if ``CA`` is empty.
|
|
569
|
+
:returns: Item popped from left side (front) of the ``CA``
|
|
570
|
+
if not empty, otherwise return the provided
|
|
571
|
+
default value.
|
|
491
572
|
|
|
492
573
|
"""
|
|
493
574
|
try:
|
|
@@ -497,14 +578,14 @@ class CA[X]:
|
|
|
497
578
|
|
|
498
579
|
def poprd(self, default: X) -> X:
|
|
499
580
|
"""
|
|
500
|
-
.. admonition::
|
|
581
|
+
.. admonition:: pop Right with default
|
|
501
582
|
|
|
502
583
|
Pop a single items off the right side of the ``CA``.
|
|
503
584
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
585
|
+
:param default: Default value to return if ``CA`` is empty.
|
|
586
|
+
:returns: Item popped from right side (rear) of the ``CA``
|
|
587
|
+
if not empty, otherwise return the provided
|
|
588
|
+
default value.
|
|
508
589
|
|
|
509
590
|
"""
|
|
510
591
|
try:
|
|
@@ -518,8 +599,9 @@ class CA[X]:
|
|
|
518
599
|
|
|
519
600
|
Pop items off the left side of the ``CA``.
|
|
520
601
|
|
|
521
|
-
|
|
522
|
-
|
|
602
|
+
:param maximum: Maximum number of items to pop,
|
|
603
|
+
may pop less if not enough items in ``CA``.
|
|
604
|
+
:returns: A ``tuple`` of the items popped, left to right.
|
|
523
605
|
|
|
524
606
|
"""
|
|
525
607
|
xs: list[X] = []
|
|
@@ -540,8 +622,9 @@ class CA[X]:
|
|
|
540
622
|
|
|
541
623
|
Pop items off the right side of the ``CA``.
|
|
542
624
|
|
|
543
|
-
|
|
544
|
-
|
|
625
|
+
:param maximum: Maximum number of items to pop,
|
|
626
|
+
may pop less if not enough items in ``CA``.
|
|
627
|
+
:returns: A ``tuple`` of the items popped, right to left.
|
|
545
628
|
|
|
546
629
|
"""
|
|
547
630
|
item_list: list[X] = []
|
|
@@ -561,7 +644,8 @@ class CA[X]:
|
|
|
561
644
|
Rotate contents of ``CA`` to the left putting first
|
|
562
645
|
item onto rear.
|
|
563
646
|
|
|
564
|
-
|
|
647
|
+
:param n: Number of times to shift items left.
|
|
648
|
+
Default 1 time.
|
|
565
649
|
|
|
566
650
|
"""
|
|
567
651
|
if self._cnt < 2:
|
|
@@ -576,7 +660,8 @@ class CA[X]:
|
|
|
576
660
|
Rotate contents of ``CA`` to the right putting last
|
|
577
661
|
item onto front.
|
|
578
662
|
|
|
579
|
-
|
|
663
|
+
:param n: Number of times to shift items right.
|
|
664
|
+
Default 1 time.
|
|
580
665
|
|
|
581
666
|
"""
|
|
582
667
|
if self._cnt < 2:
|
|
@@ -590,8 +675,8 @@ class CA[X]:
|
|
|
590
675
|
|
|
591
676
|
Apply function ``f`` over the circular array's contents.
|
|
592
677
|
|
|
593
|
-
|
|
594
|
-
|
|
678
|
+
:param f: Callable from type ``X`` to type ``Y``.
|
|
679
|
+
:returns: New auto-resizing circular array instance.
|
|
595
680
|
|
|
596
681
|
"""
|
|
597
682
|
return CA(map(f, self))
|
|
@@ -607,10 +692,12 @@ class CA[X]:
|
|
|
607
692
|
|
|
608
693
|
Fold ``CA`` left with a function and optional starting item.
|
|
609
694
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
695
|
+
:param f: Folding function, first argument to ``f`` is for
|
|
696
|
+
the accumulator.
|
|
697
|
+
:param start: Optional starting item.
|
|
698
|
+
:returns: Reduced value produced by the left fold.
|
|
699
|
+
:raises ValueError: When circular array empty and ``start``
|
|
700
|
+
not given.
|
|
614
701
|
|
|
615
702
|
"""
|
|
616
703
|
if self._cnt == 0:
|
|
@@ -641,10 +728,12 @@ class CA[X]:
|
|
|
641
728
|
|
|
642
729
|
Fold ``CA`` right with a function and optional starting item.
|
|
643
730
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
731
|
+
:param f: Folding function, second argument to ``f`` is for
|
|
732
|
+
the accumulator.
|
|
733
|
+
:param start: Optional starting item.
|
|
734
|
+
:returns: Reduced value produced by the right fold.
|
|
735
|
+
:raises ValueError: When circular array empty and ``start``
|
|
736
|
+
not given.
|
|
648
737
|
|
|
649
738
|
"""
|
|
650
739
|
if self._cnt == 0:
|
|
@@ -670,7 +759,7 @@ class CA[X]:
|
|
|
670
759
|
|
|
671
760
|
Get the current storage capacity of the circular array.
|
|
672
761
|
|
|
673
|
-
|
|
762
|
+
:returns: Current storage capacity.
|
|
674
763
|
|
|
675
764
|
"""
|
|
676
765
|
return self._cap
|
|
@@ -700,7 +789,7 @@ class CA[X]:
|
|
|
700
789
|
|
|
701
790
|
Find fraction of the storage capacity which is filled.
|
|
702
791
|
|
|
703
|
-
|
|
792
|
+
:returns: The ratio count/capacity.
|
|
704
793
|
|
|
705
794
|
"""
|
|
706
795
|
return self._cnt / self._cap
|
|
@@ -713,7 +802,8 @@ class CA[X]:
|
|
|
713
802
|
minimum storage capacity. To just compact the circular
|
|
714
803
|
array, do not provide ``minimum_capacity``.
|
|
715
804
|
|
|
716
|
-
:param minimum_capacity: Minimum storage capacity to compact
|
|
805
|
+
:param minimum_capacity: Minimum storage capacity to compact
|
|
806
|
+
the circular array.
|
|
717
807
|
|
|
718
808
|
"""
|
|
719
809
|
self._compact_storage_capacity()
|
|
@@ -733,10 +823,11 @@ def ca[T](*ts: T) -> CA[T]:
|
|
|
733
823
|
"""
|
|
734
824
|
.. admonition:: Circular array factory function
|
|
735
825
|
|
|
736
|
-
Produce a circular array from
|
|
826
|
+
Produce a auto resizing circular array from
|
|
827
|
+
a variable number of arguments.
|
|
737
828
|
|
|
738
|
-
|
|
739
|
-
|
|
829
|
+
:param ts: Initial items for a new auto-resizing circular array.
|
|
830
|
+
:returns: New variable storage capacity circular array.
|
|
740
831
|
|
|
741
832
|
"""
|
|
742
833
|
return CA(ts)
|
|
@@ -5,10 +5,11 @@ __all__ = ['CA', 'ca']
|
|
|
5
5
|
|
|
6
6
|
class CA[X]:
|
|
7
7
|
def __init__(self, *xs: Iterable[X]) -> None: ...
|
|
8
|
-
def __iter__(self) -> Iterator[X]: ...
|
|
9
|
-
def __reversed__(self) -> Iterator[X]: ...
|
|
10
8
|
def __bool__(self) -> bool: ...
|
|
11
9
|
def __len__(self) -> int: ...
|
|
10
|
+
def __iter__(self) -> Iterator[X]: ...
|
|
11
|
+
def __reversed__(self) -> Iterator[X]: ...
|
|
12
|
+
def __eq__(self, other: object) -> bool: ...
|
|
12
13
|
@overload
|
|
13
14
|
def __getitem__(self, idx: int) -> X: ...
|
|
14
15
|
@overload
|
|
@@ -21,7 +22,6 @@ class CA[X]:
|
|
|
21
22
|
def __delitem__(self, idx: int) -> None: ...
|
|
22
23
|
@overload
|
|
23
24
|
def __delitem__(self, idx: slice) -> None: ...
|
|
24
|
-
def __eq__(self, other: object) -> bool: ...
|
|
25
25
|
def pushl(self, *xs: X) -> None: ...
|
|
26
26
|
def pushr(self, *xs: X) -> None: ...
|
|
27
27
|
def popl(self) -> X: ...
|