pythonic-fp-circulararray 5.4.0__py3-none-any.whl → 6.0.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.
@@ -41,22 +41,21 @@ nada: Final[NoValue] = NoValue()
41
41
  class CA[I]:
42
42
  __slots__ = '_items', '_cnt', '_cap', '_front', '_rear'
43
43
 
44
- @overload
45
- def __init__(self) -> None: ...
46
- @overload
47
- def __init__(self, items: Iterable[I]) -> None: ...
48
-
49
- def __init__(self, items: Iterable[I | NoValue] | NoValue = nada) -> None:
44
+ def __init__(self, *items: Iterable[I]) -> None:
50
45
  """
51
- :param items: "Optional" iterable to initial populate circular array.
52
- :raises TypeError: When ``items`` not Iterable.
46
+ :param items: "Optionally" takes a single iterable to populate circular array.
47
+ :raises TypeError: When ``items[0]`` not iterable.
48
+ :raises ValueError: If more than 1 iterable is given.
53
49
  """
54
- if items is nada:
55
- self._items: list[I | NoValue] = [nada, nada]
56
- else:
57
- values: list[I | NoValue] = list(cast(Iterable[I | NoValue], items))
50
+ if (size := len(items)) > 1:
51
+ msg = f'CA expects at most 1 argument, got {size}'
52
+ raise ValueError(msg)
53
+ if size:
54
+ values: list[I | NoValue] = list(cast(Iterable[I | NoValue], items[0]))
58
55
  self._items = [nada] + values + [nada]
59
- self._cap = cap = len(self._items)
56
+ else:
57
+ self._items = [nada, nada]
58
+ self._cap = (cap := len(self._items))
60
59
  self._cnt = cap - 2
61
60
  if cap == 2:
62
61
  self._front = 0
@@ -292,10 +291,10 @@ class CA[I]:
292
291
 
293
292
  (
294
293
  front1,
295
- count1,
294
+ cnt1,
296
295
  capacity1,
297
296
  front2,
298
- count2,
297
+ cnt2,
299
298
  capacity2,
300
299
  ) = (
301
300
  self._front,
@@ -306,10 +305,10 @@ class CA[I]:
306
305
  other._cap,
307
306
  )
308
307
 
309
- if count1 != count2:
308
+ if cnt1 != cnt2:
310
309
  return False
311
310
 
312
- for nn in range(count1):
311
+ for nn in range(cnt1):
313
312
  if (
314
313
  self._items[(front1 + nn) % capacity1]
315
314
  is other._items[(front2 + nn) % capacity2]
@@ -40,44 +40,38 @@ nada: Final[NoValue] = NoValue()
40
40
  class CAF[I]:
41
41
  __slots__ = '_items', '_cnt', '_cap', '_front', '_rear'
42
42
 
43
- @overload
44
- def __init__(self) -> None: ...
45
- @overload
46
- def __init__(self, items: Iterable[I]) -> None: ...
47
- @overload
48
- def __init__(self, items: Iterable[I], capacity: int) -> None: ...
49
-
50
- def __init__(
51
- self, items: Iterable[I | NoValue] | NoValue = nada, capacity: int = 2
52
- ) -> None:
43
+ def __init__(self, *items: Iterable[I], cap: int = 2) -> None:
53
44
  """
54
- :param items: "Optional" iterable to initial populate circular array.
55
- :param capacity: Minimum fixed storage capacity of circular array.
56
- :raises TypeError: When ``items`` not Iterable,
45
+ :param items: "Optionally" takes a single iterable to populate circular array.
46
+ :param cap: Minimum fixed storage capacity of circular array.
47
+ :raises TypeError: When ``items[0]`` not iterable,
48
+ :raises ValueError: If more than 1 iterable is given.
57
49
  """
58
- capacity = max(2, capacity)
59
- if items is nada:
60
- self._items: list[I | NoValue] = [nada] * capacity
61
- count = 0
50
+ cap = max(2, cap)
51
+ if (size := len(items)) > 1:
52
+ msg = f'CAF expects at most 1 argument, got {size}'
53
+ raise ValueError(msg)
54
+ if size:
55
+ values: list[I | NoValue] = list(cast(Iterable[I | NoValue], items[0]))
56
+ cnt = len(values)
57
+ cap = max(cnt, cap)
58
+ self._items = values + [nada] * (cap - cnt)
62
59
  else:
63
- values: list[I | NoValue] = list(cast(Iterable[I | NoValue], items))
64
- dlist: list[I | NoValue] = list(values)
65
- count = len(dlist)
66
- capacity = max(count, capacity)
67
- self._items = dlist + [nada] * (capacity - count)
68
- self._cap: Final[int] = capacity
69
- self._cnt = count
70
- if count == 0:
60
+ self._items = [nada] * cap
61
+ cnt = 0
62
+ self._cap: Final[int] = cap
63
+ self._cnt = cnt
64
+ if cnt == 0:
71
65
  self._front = 0
72
- self._rear = capacity - 1
66
+ self._rear = cap - 1
73
67
  else:
74
68
  self._front = 0
75
- self._rear = count - 1
69
+ self._rear = cnt - 1
76
70
 
77
71
  def __iter__(self) -> Iterator[I]:
78
72
  if self._cnt > 0:
79
73
  (
80
- capacity,
74
+ cap,
81
75
  rear,
82
76
  position,
83
77
  current_state,
@@ -90,13 +84,13 @@ class CAF[I]:
90
84
 
91
85
  while position != rear:
92
86
  yield cast(I, current_state[position])
93
- position = (position + 1) % capacity
87
+ position = (position + 1) % cap
94
88
  yield cast(I, current_state[position])
95
89
 
96
90
  def __reversed__(self) -> Iterator[I]:
97
91
  if self._cnt > 0:
98
92
  (
99
- capacity,
93
+ cap,
100
94
  front,
101
95
  position,
102
96
  current_state,
@@ -109,7 +103,7 @@ class CAF[I]:
109
103
 
110
104
  while position != front:
111
105
  yield cast(I, current_state[position])
112
- position = (position - 1) % capacity
106
+ position = (position - 1) % cap
113
107
  yield cast(I, current_state[position])
114
108
 
115
109
  def __repr__(self) -> str:
@@ -159,7 +153,7 @@ class CAF[I]:
159
153
  def __delitem__(self, idx: int) -> None:
160
154
  item_list = list(self)
161
155
  del item_list[idx]
162
- _ca = CAF(item_list, self._cap)
156
+ _ca = CAF(item_list, cap = self._cap)
163
157
  (
164
158
  self._items,
165
159
  self._cnt,
@@ -181,11 +175,11 @@ class CAF[I]:
181
175
 
182
176
  (
183
177
  front1,
184
- count1,
185
- capacity1,
178
+ cnt1,
179
+ cap1,
186
180
  front2,
187
- count2,
188
- capacity2,
181
+ cnt2,
182
+ cap2,
189
183
  ) = (
190
184
  self._front,
191
185
  self._cnt,
@@ -195,18 +189,18 @@ class CAF[I]:
195
189
  other._cap,
196
190
  )
197
191
 
198
- if count1 != count2:
192
+ if cnt1 != cnt2:
199
193
  return False
200
194
 
201
- for nn in range(count1):
195
+ for nn in range(cnt1):
202
196
  if (
203
- self._items[(front1 + nn) % capacity1]
204
- is other._items[(front2 + nn) % capacity2]
197
+ self._items[(front1 + nn) % cap1]
198
+ is other._items[(front2 + nn) % cap2]
205
199
  ):
206
200
  continue
207
201
  if (
208
- self._items[(front1 + nn) % capacity1]
209
- != other._items[(front2 + nn) % capacity2]
202
+ self._items[(front1 + nn) % cap1]
203
+ != other._items[(front2 + nn) % cap2]
210
204
  ):
211
205
  return False
212
206
  return True
@@ -409,7 +403,7 @@ class CAF[I]:
409
403
  :param f: Callable from type ``I`` to type ``U``.
410
404
  :returns: New fixed capacity circular array instance.
411
405
  """
412
- return CAF(map(f, self), self._cap)
406
+ return CAF(map(f, self), cap = self._cap)
413
407
 
414
408
  @overload
415
409
  def foldl[L](self, f: Callable[[I, I], I]) -> I: ...
@@ -500,11 +494,11 @@ class CAF[I]:
500
494
  return self._cnt / self._cap
501
495
 
502
496
 
503
- def caf[T](*items: T, capacity: int = 2) -> CAF[T]:
497
+ def caf[T](*items: T, cap: int = 2) -> CAF[T]:
504
498
  """Produce a circular array from a variable number of arguments.
505
499
 
506
500
  :param items: Initial items for a new fixed capacity :circular array.
507
- :param capacity: The minimum storage capacity to set.
501
+ :param cap: The minimum storage capacity to set.
508
502
  :returns: New fixed storage capacity circular array.
509
503
  """
510
- return CAF(items, capacity=capacity)
504
+ return CAF(items, cap=cap)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythonic-fp-circulararray
3
- Version: 5.4.0
3
+ Version: 6.0.0
4
4
  Summary: Circular Array
5
5
  Keywords: auto resizing,circular array,circulararray,dequeue,indexable,pop,push
6
6
  Author-email: "Geoffrey R. Scheller" <geoffrey@scheller.com>
@@ -0,0 +1,8 @@
1
+ pythonic_fp/circulararray/__init__.py,sha256=uR0KASmw1Zraz9l3VPbqPm9WUKzWk-0_tUGT0opabzQ,1515
2
+ pythonic_fp/circulararray/auto.py,sha256=7aT4l93zAPWIuIWjqxnLpXyJJZ349CCPqPGS-yXJxho,19486
3
+ pythonic_fp/circulararray/fixed.py,sha256=usGVbw2wy4idhhMSZq_DFzROTrXUeiCjVpMYfetXiWs,15456
4
+ pythonic_fp/circulararray/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ pythonic_fp_circulararray-6.0.0.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
6
+ pythonic_fp_circulararray-6.0.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
7
+ pythonic_fp_circulararray-6.0.0.dist-info/METADATA,sha256=W9GQEAUwxQi-yzQU2yGqhanDDXYe-piRV5ZxZJYpYpk,2761
8
+ pythonic_fp_circulararray-6.0.0.dist-info/RECORD,,
File without changes
@@ -1,52 +0,0 @@
1
- from collections.abc import Callable, Iterable, Iterator
2
- from typing import overload
3
-
4
- __all__ = ['CA', 'ca']
5
-
6
- class CA[I]:
7
- @overload
8
- def __init__(self) -> None: ...
9
- @overload
10
- def __init__(self, items: Iterable[I]) -> None: ...
11
- def __iter__(self) -> Iterator[I]: ...
12
- def __reversed__(self) -> Iterator[I]: ...
13
- def __bool__(self) -> bool: ...
14
- def __len__(self) -> int: ...
15
- @overload
16
- def __getitem__(self, idx: int) -> I: ...
17
- @overload
18
- def __getitem__(self, idx: slice) -> CA[I]: ...
19
- @overload
20
- def __setitem__(self, idx: int, vals: I) -> None: ...
21
- @overload
22
- def __setitem__(self, idx: slice, vals: Iterable[I]) -> None: ...
23
- @overload
24
- def __delitem__(self, idx: int) -> None: ...
25
- @overload
26
- def __delitem__(self, idx: slice) -> None: ...
27
- def __eq__(self, other: object) -> bool: ...
28
- def pushl(self, *items: I) -> None: ...
29
- def pushr(self, *items: I) -> None: ...
30
- def popl(self) -> I: ...
31
- def popr(self) -> I: ...
32
- def popld(self, default: I) -> I: ...
33
- def poprd(self, default: I) -> I: ...
34
- def poplt(self, maximum: int) -> tuple[I, ...]: ...
35
- def poprt(self, maximum: int) -> tuple[I, ...]: ...
36
- def rotl(self, n: int = 1) -> None: ...
37
- def rotr(self, n: int = 1) -> None: ...
38
- def map[U](self, f: Callable[[I], U]) -> CA[U]: ...
39
- @overload
40
- def foldl[L](self, f: Callable[[I, I], I]) -> I: ...
41
- @overload
42
- def foldl[L](self, f: Callable[[L, I], L], start: L) -> L: ...
43
- @overload
44
- def foldr[R](self, f: Callable[[I, I], I]) -> I: ...
45
- @overload
46
- def foldr[R](self, f: Callable[[I, R], R], start: R) -> R: ...
47
- def capacity(self) -> int: ...
48
- def empty(self) -> None: ...
49
- def fraction_filled(self) -> float: ...
50
- def resize(self, minimum_capacity: int = 2) -> None: ...
51
-
52
- def ca[T](*items: T) -> CA[T]: ...
@@ -1,44 +0,0 @@
1
- from collections.abc import Callable, Iterable, Iterator
2
- from typing import overload
3
-
4
- __all__ = ['CAF', 'caf']
5
-
6
- class CAF[I]:
7
- @overload
8
- def __init__(self) -> None: ...
9
- @overload
10
- def __init__(self, items: Iterable[I]) -> None: ...
11
- @overload
12
- def __init__(self, items: Iterable[I], capacity: int) -> None: ...
13
- def __iter__(self) -> Iterator[I]: ...
14
- def __reversed__(self) -> Iterator[I]: ...
15
- def __bool__(self) -> bool: ...
16
- def __len__(self) -> int: ...
17
- def __getitem__(self, idx: int) -> I: ...
18
- def __setitem__(self, idx: int, val: I) -> None: ...
19
- def __delitem__(self, idx: int) -> None: ...
20
- def __eq__(self, other: object) -> bool: ...
21
- def pushl(self, item: I) -> None: ...
22
- def pushr(self, item: I) -> None: ...
23
- def popl(self) -> I: ...
24
- def popr(self) -> I: ...
25
- def popld(self, default: I) -> I: ...
26
- def poprd(self, default: I) -> I: ...
27
- def poplt(self, maximum: int) -> tuple[I, ...]: ...
28
- def poprt(self, maximum: int) -> tuple[I, ...]: ...
29
- def rotl(self, n: int = 1) -> None: ...
30
- def rotr(self, n: int = 1) -> None: ...
31
- def map[U](self, f: Callable[[I], U]) -> CAF[U]: ...
32
- @overload
33
- def foldl[L](self, f: Callable[[I, I], I]) -> I: ...
34
- @overload
35
- def foldl[L](self, f: Callable[[L, I], L], start: L) -> L: ...
36
- @overload
37
- def foldr[R](self, f: Callable[[I, I], I]) -> I: ...
38
- @overload
39
- def foldr[R](self, f: Callable[[I, R], R], start: R) -> R: ...
40
- def capacity(self) -> int: ...
41
- def empty(self) -> None: ...
42
- def fraction_filled(self) -> float: ...
43
-
44
- def caf[T](*items: T, capacity: int = 2) -> CAF[T]: ...
@@ -1,11 +0,0 @@
1
- pythonic_fp/circulararray/__init__.py,sha256=uR0KASmw1Zraz9l3VPbqPm9WUKzWk-0_tUGT0opabzQ,1515
2
- pythonic_fp/circulararray/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- pythonic_fp/circulararray/auto.py,sha256=mM5kAZnSo4etgA0uSp05VUMGpIOeKXIoCCQ1C3pIETo,19457
4
- pythonic_fp/circulararray/auto.pyi,sha256=DegIbRFv66Ws4N1J1dExQ6cQJOTZw-XXUEJHi1OgIBk,1861
5
- pythonic_fp/circulararray/fixed.py,sha256=VhCWBcE0C8toYqGyd9aKJ1bSJu8sHA46AQGJ7mGxYBE,15700
6
- pythonic_fp/circulararray/fixed.pyi,sha256=Uk0QnXn3_q_6urXeRFEMxsL0gS-3Xa4UsyDRVXk8YoY,1648
7
- pythonic_fp/circulararray/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- pythonic_fp_circulararray-5.4.0.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
9
- pythonic_fp_circulararray-5.4.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
10
- pythonic_fp_circulararray-5.4.0.dist-info/METADATA,sha256=x6ZQX_ItPF3ndJZFS15JOOqKPK01yM6YEf0Y3e9PsK8,2761
11
- pythonic_fp_circulararray-5.4.0.dist-info/RECORD,,