pythonic-fp-circulararray 5.3.2__py3-none-any.whl → 5.3.3__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/__init__.py +1 -2
- pythonic_fp/circulararray/__init__.pyi +0 -0
- pythonic_fp/circulararray/auto.py +55 -94
- pythonic_fp/circulararray/fixed.py +55 -92
- {pythonic_fp_circulararray-5.3.2.dist-info → pythonic_fp_circulararray-5.3.3.dist-info}/METADATA +2 -2
- pythonic_fp_circulararray-5.3.3.dist-info/RECORD +11 -0
- pythonic_fp_circulararray-5.3.2.dist-info/RECORD +0 -10
- {pythonic_fp_circulararray-5.3.2.dist-info → pythonic_fp_circulararray-5.3.3.dist-info}/WHEEL +0 -0
- {pythonic_fp_circulararray-5.3.2.dist-info → pythonic_fp_circulararray-5.3.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
"""
|
|
16
16
|
Circular Array
|
|
17
|
-
|
|
17
|
+
--------------
|
|
18
18
|
|
|
19
19
|
Package implementing stateful circular array data structures.
|
|
20
20
|
|
|
@@ -29,7 +29,6 @@ Package implementing stateful circular array data structures.
|
|
|
29
29
|
+-------------------------------------+-------------------------------------------+
|
|
30
30
|
| **pythonic_fp.circulararray.fixed** | Fixed storage capacity circular array. |
|
|
31
31
|
+-------------------------------------+-------------------------------------------+
|
|
32
|
-
|
|
33
32
|
"""
|
|
34
33
|
|
|
35
34
|
__author__ = 'Geoffrey R. Scheller'
|
|
File without changes
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
Variable Storage Capacity
|
|
17
17
|
=========================
|
|
18
18
|
|
|
19
|
-
Circular array with variable storage capacity
|
|
19
|
+
**Circular array with variable storage capacity.**
|
|
20
20
|
|
|
21
21
|
- O(1) pops either end
|
|
22
22
|
- O(1) amortized pushes either end
|
|
@@ -25,7 +25,7 @@ Circular array with variable storage capacity.
|
|
|
25
25
|
- iterable, can safely mutate while iterators continue iterating over previous state
|
|
26
26
|
- comparisons compare identity before equality, like builtins
|
|
27
27
|
- in boolean context, falsy when empty, otherwise truthy
|
|
28
|
-
- factory function ca produces a variable storage capacity circular array from its arguments
|
|
28
|
+
- factory function ``ca`` produces a variable storage capacity circular array from its arguments
|
|
29
29
|
|
|
30
30
|
"""
|
|
31
31
|
from collections.abc import Callable, Iterable, Iterator
|
|
@@ -43,12 +43,8 @@ class CA[I]():
|
|
|
43
43
|
items: Iterable[I] | None = None
|
|
44
44
|
) -> None:
|
|
45
45
|
"""
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
:param items: optional iterable to initial populate circular array
|
|
50
|
-
:raises TypeError: if items is not Iterable
|
|
51
|
-
|
|
46
|
+
:param items: Optional iterable to initial populate circular array.
|
|
47
|
+
:raises TypeError: When ``items`` not Iterable.
|
|
52
48
|
"""
|
|
53
49
|
if items is None:
|
|
54
50
|
self._items: list[I | None] = [None, None]
|
|
@@ -310,11 +306,9 @@ class CA[I]():
|
|
|
310
306
|
return True
|
|
311
307
|
|
|
312
308
|
def pushl(self, *items: I) -> None:
|
|
313
|
-
"""
|
|
314
|
-
Push items onto left side (front) of circular array.
|
|
315
|
-
|
|
316
|
-
:param items: items pushed onto circular array from left
|
|
309
|
+
"""Push ``items`` on from left.
|
|
317
310
|
|
|
311
|
+
:param items: Items pushed onto circular array from left (front).
|
|
318
312
|
"""
|
|
319
313
|
for item in items:
|
|
320
314
|
if self._cnt == self._cap:
|
|
@@ -330,11 +324,9 @@ class CA[I]():
|
|
|
330
324
|
)
|
|
331
325
|
|
|
332
326
|
def pushr(self, *items: I) -> None:
|
|
333
|
-
"""
|
|
334
|
-
Push items onto right side (rear) of circular array.
|
|
335
|
-
|
|
336
|
-
:param items: items pushed onto circular array from right
|
|
327
|
+
"""Push ``items`` on from right.
|
|
337
328
|
|
|
329
|
+
:param items: Items pushed onto circular array from right (rear).
|
|
338
330
|
"""
|
|
339
331
|
for item in items:
|
|
340
332
|
if self._cnt == self._cap:
|
|
@@ -350,12 +342,10 @@ class CA[I]():
|
|
|
350
342
|
)
|
|
351
343
|
|
|
352
344
|
def popl(self) -> I:
|
|
353
|
-
"""
|
|
354
|
-
Pop item off left side (front) of circular array.
|
|
355
|
-
|
|
356
|
-
:returns: item popped from left side of circular array
|
|
357
|
-
:raises ValueError: when called on an empty circular array
|
|
345
|
+
"""Pop single item off from left side.
|
|
358
346
|
|
|
347
|
+
:returns: Item popped from left side (front) of circular array.
|
|
348
|
+
:raises ValueError: When called on an empty circular array.
|
|
359
349
|
"""
|
|
360
350
|
if self._cnt > 1:
|
|
361
351
|
(
|
|
@@ -389,12 +379,10 @@ class CA[I]():
|
|
|
389
379
|
return cast(I, d)
|
|
390
380
|
|
|
391
381
|
def popr(self) -> I:
|
|
392
|
-
"""
|
|
393
|
-
Pop item off right side (rear) of circular array.
|
|
394
|
-
|
|
395
|
-
:return: item popped from right side of circular array
|
|
396
|
-
:raises ValueError: when called on an empty circular array
|
|
382
|
+
"""Pop single item off from right.
|
|
397
383
|
|
|
384
|
+
:returns: Item popped from right side (rear) of circular array.
|
|
385
|
+
:raises ValueError: When called on an empty circular array.
|
|
398
386
|
"""
|
|
399
387
|
if self._cnt > 1:
|
|
400
388
|
(
|
|
@@ -428,13 +416,11 @@ class CA[I]():
|
|
|
428
416
|
return cast(I, d)
|
|
429
417
|
|
|
430
418
|
def popld(self, default: I) -> I:
|
|
431
|
-
"""
|
|
432
|
-
|
|
433
|
-
a mandatory default value. "Safe" version of popl.
|
|
434
|
-
|
|
435
|
-
:param default: item returned if circular array is empty
|
|
436
|
-
:return: item popped from left side or default item if empty
|
|
419
|
+
"""Pop one item from left side of the circular array, provide
|
|
420
|
+
a mandatory default value. "Safe" version of ``popl``.
|
|
437
421
|
|
|
422
|
+
:param default: Item returned if circular array is empty.
|
|
423
|
+
:returns: Item popped from left side or default item if empty.
|
|
438
424
|
"""
|
|
439
425
|
try:
|
|
440
426
|
return self.popl()
|
|
@@ -442,13 +428,11 @@ class CA[I]():
|
|
|
442
428
|
return default
|
|
443
429
|
|
|
444
430
|
def poprd(self, default: I) -> I:
|
|
445
|
-
"""
|
|
446
|
-
|
|
447
|
-
a mandatory default value. "Safe" version of popr.
|
|
448
|
-
|
|
449
|
-
:param default: item returned if circular array is empty
|
|
450
|
-
:return: item popped from right side or default item if empty
|
|
431
|
+
"""Pop one item from right side of the circular array, provide
|
|
432
|
+
a mandatory default value. "Safe" version of ``popr``.
|
|
451
433
|
|
|
434
|
+
:param default: Item returned if circular array is empty.
|
|
435
|
+
:returns: Item popped from right side or default item if empty.
|
|
452
436
|
"""
|
|
453
437
|
try:
|
|
454
438
|
return self.popr()
|
|
@@ -456,12 +440,10 @@ class CA[I]():
|
|
|
456
440
|
return default
|
|
457
441
|
|
|
458
442
|
def poplt(self, maximum: int) -> tuple[I, ...]:
|
|
459
|
-
"""
|
|
460
|
-
Pop multiple items from left side of circular array.
|
|
461
|
-
|
|
462
|
-
:param maximum: maximum number of items to pop, may pop less if not enough items
|
|
463
|
-
:return: items in the order popped, left to right
|
|
443
|
+
"""Pop multiple items from left side of circular array.
|
|
464
444
|
|
|
445
|
+
:param maximum: Maximum number of items to pop, may pop less if not enough items.
|
|
446
|
+
:returns: Tuple of items in the order popped, left to right.
|
|
465
447
|
"""
|
|
466
448
|
item_list: list[I] = []
|
|
467
449
|
|
|
@@ -476,12 +458,10 @@ class CA[I]():
|
|
|
476
458
|
return tuple(item_list)
|
|
477
459
|
|
|
478
460
|
def poprt(self, maximum: int) -> tuple[I, ...]:
|
|
479
|
-
"""
|
|
480
|
-
Pop multiple items from right side of circular array.
|
|
481
|
-
|
|
482
|
-
:param maximum: maximum number of items to pop, may pop less if not enough items
|
|
483
|
-
:return: items in the order popped, right to left
|
|
461
|
+
"""Pop multiple items from right side of circular array.
|
|
484
462
|
|
|
463
|
+
:param maximum: Maximum number of items to pop, may pop less if not enough items.
|
|
464
|
+
:returns: Tuple of items in the order popped, right to left.
|
|
485
465
|
"""
|
|
486
466
|
item_list: list[I] = []
|
|
487
467
|
while maximum > 0:
|
|
@@ -494,11 +474,9 @@ class CA[I]():
|
|
|
494
474
|
return tuple(item_list)
|
|
495
475
|
|
|
496
476
|
def rotl(self, n: int = 1) -> None:
|
|
497
|
-
"""
|
|
498
|
-
Rotate items to the left.
|
|
499
|
-
|
|
500
|
-
:param n: number of times to shift elements to the left
|
|
477
|
+
"""Rotate items to the left.
|
|
501
478
|
|
|
479
|
+
:param n: Number of times to shift elements to the left.
|
|
502
480
|
"""
|
|
503
481
|
if self._cnt < 2:
|
|
504
482
|
return
|
|
@@ -506,11 +484,9 @@ class CA[I]():
|
|
|
506
484
|
self.pushr(self.popl())
|
|
507
485
|
|
|
508
486
|
def rotr(self, n: int = 1) -> None:
|
|
509
|
-
"""
|
|
510
|
-
Rotate items to the right.
|
|
511
|
-
|
|
512
|
-
:param n: number of times to shift elements to the right
|
|
487
|
+
"""Rotate items to the right.
|
|
513
488
|
|
|
489
|
+
:param n: Number of times to shift elements to the right.
|
|
514
490
|
"""
|
|
515
491
|
if self._cnt < 2:
|
|
516
492
|
return
|
|
@@ -518,24 +494,20 @@ class CA[I]():
|
|
|
518
494
|
self.pushl(self.popr())
|
|
519
495
|
|
|
520
496
|
def map[U](self, f: Callable[[I], U]) -> "CA[U]":
|
|
521
|
-
"""
|
|
522
|
-
Apply function f over the circular array's contents,
|
|
523
|
-
|
|
524
|
-
:param f: callable from type I to type U
|
|
525
|
-
:returns: new circular array instance
|
|
497
|
+
"""Apply function ``f`` over the circular array's contents.
|
|
526
498
|
|
|
499
|
+
:param f: Callable from type ``I`` to type ``U``.
|
|
500
|
+
:returns: New auto-resizing circular array instance.
|
|
527
501
|
"""
|
|
528
502
|
return CA(map(f, self))
|
|
529
503
|
|
|
530
504
|
def foldl[L](self, f: Callable[[L, I], L], start: L | None = None) -> L:
|
|
531
|
-
"""
|
|
532
|
-
Fold left with a function and optional starting item.
|
|
533
|
-
|
|
534
|
-
:param f: first argument to f is for the accumulator
|
|
535
|
-
:param start: optional starting item
|
|
536
|
-
:returns: reduced value produced by the left fold
|
|
537
|
-
:raises ValueError: when circular array empty and no starting item given
|
|
505
|
+
"""Fold left with a function and optional starting item.
|
|
538
506
|
|
|
507
|
+
:param f: Folding function, first argument to ``f`` is for the accumulator.
|
|
508
|
+
:param start: Optional starting item.
|
|
509
|
+
:returns: Reduced value produced by the left fold.
|
|
510
|
+
:raises ValueError: When circular array empty and no starting item given.
|
|
539
511
|
"""
|
|
540
512
|
if self._cnt == 0:
|
|
541
513
|
if start is None:
|
|
@@ -555,14 +527,12 @@ class CA[I]():
|
|
|
555
527
|
return acc
|
|
556
528
|
|
|
557
529
|
def foldr[R](self, f: Callable[[I, R], R], start: R | None = None) -> R:
|
|
558
|
-
"""
|
|
559
|
-
Fold right with a function and an optional starting item.
|
|
560
|
-
|
|
561
|
-
:param f: second argument to f is for the accumulator
|
|
562
|
-
:param start: optional starting item
|
|
563
|
-
:returns: reduced value produced by the right fold
|
|
564
|
-
:raises ValueError: when circular array empty and no starting item given
|
|
530
|
+
"""Fold right with a function and an optional starting item.
|
|
565
531
|
|
|
532
|
+
:param f: Folding function, second argument to ``f`` is for the accumulator.
|
|
533
|
+
:param start: Optional starting item.
|
|
534
|
+
:returns: Reduced value produced by the right fold.
|
|
535
|
+
:raises ValueError: When circular array empty and no starting item given.
|
|
566
536
|
"""
|
|
567
537
|
if self._cnt == 0:
|
|
568
538
|
if start is None:
|
|
@@ -582,17 +552,14 @@ class CA[I]():
|
|
|
582
552
|
return acc
|
|
583
553
|
|
|
584
554
|
def capacity(self) -> int:
|
|
585
|
-
"""
|
|
586
|
-
Return current storage capacity of the circular array.
|
|
587
|
-
|
|
588
|
-
:returns: current storage capacity
|
|
555
|
+
"""Return current storage capacity of the circular array.
|
|
589
556
|
|
|
557
|
+
:returns: Current storage capacity.
|
|
590
558
|
"""
|
|
591
559
|
return self._cap
|
|
592
560
|
|
|
593
561
|
def empty(self) -> None:
|
|
594
|
-
"""
|
|
595
|
-
Empty the circular array, keep current storage capacity."""
|
|
562
|
+
"""Empty the circular array, keep current storage capacity."""
|
|
596
563
|
(
|
|
597
564
|
self._items,
|
|
598
565
|
self._front,
|
|
@@ -606,22 +573,18 @@ class CA[I]():
|
|
|
606
573
|
)
|
|
607
574
|
|
|
608
575
|
def fraction_filled(self) -> float:
|
|
609
|
-
"""
|
|
610
|
-
Find fraction of the storage capacity which is filled.
|
|
611
|
-
|
|
612
|
-
:returns: the ratio count/capacity
|
|
576
|
+
"""Find fraction of the storage capacity which is filled.
|
|
613
577
|
|
|
578
|
+
:returns: The ratio count/capacity.
|
|
614
579
|
"""
|
|
615
580
|
return self._cnt / self._cap
|
|
616
581
|
|
|
617
582
|
def resize(self, minimum_capacity: int = 2) -> None:
|
|
618
|
-
"""
|
|
619
|
-
Compact circular array and, if necessary, resize to a minimum
|
|
583
|
+
"""Compact circular array and, if necessary, resize to a minimum
|
|
620
584
|
storage capacity. To just compact the circular array, do not
|
|
621
585
|
provide ``minimum_capacity``.
|
|
622
586
|
|
|
623
|
-
:param minimum_capacity:
|
|
624
|
-
|
|
587
|
+
:param minimum_capacity: Minimum storage capacity to compact the circular array.
|
|
625
588
|
"""
|
|
626
589
|
self._compact_storage_capacity()
|
|
627
590
|
if (min_cap := minimum_capacity) > self._cap:
|
|
@@ -637,11 +600,9 @@ class CA[I]():
|
|
|
637
600
|
|
|
638
601
|
|
|
639
602
|
def ca[T](*items: T) -> CA[T]:
|
|
640
|
-
"""
|
|
641
|
-
Produce circular array from a variable number of arguments.
|
|
642
|
-
|
|
643
|
-
:param items: initial items for a new circular array
|
|
644
|
-
:returns: new variable storage capacity circular array
|
|
603
|
+
"""Produce circular array from a variable number of arguments.
|
|
645
604
|
|
|
605
|
+
:param items: Initial items for a new auto-resizing circular array.
|
|
606
|
+
:returns: New variable storage capacity circular array.
|
|
646
607
|
"""
|
|
647
608
|
return CA(items)
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
Fixed Storage Capacity
|
|
17
17
|
======================
|
|
18
18
|
|
|
19
|
-
Circular array with fixed storage capacity
|
|
19
|
+
**Circular array with fixed storage capacity.**
|
|
20
20
|
|
|
21
21
|
- O(1) pops and pushes either end
|
|
22
22
|
- O(1) indexing, does not support slicing
|
|
@@ -24,7 +24,7 @@ Circular array with fixed storage capacity.
|
|
|
24
24
|
- iterable, can safely mutate while iterators continue iterating over previous state
|
|
25
25
|
- comparisons compare identity before equality, like builtins
|
|
26
26
|
- in boolean context, falsy when either empty or full, otherwise truthy
|
|
27
|
-
- factory function caf produces a fixed storage capacity circular array from its arguments
|
|
27
|
+
- factory function ``caf`` produces a fixed storage capacity circular array from its arguments
|
|
28
28
|
|
|
29
29
|
"""
|
|
30
30
|
from collections.abc import Callable, Iterable, Iterator
|
|
@@ -43,13 +43,9 @@ class CAF[I]():
|
|
|
43
43
|
capacity: int = 2
|
|
44
44
|
) -> None:
|
|
45
45
|
"""
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
:param items: optional iterable to initial populate circular array
|
|
50
|
-
:param capacity: fixed storage capacity of circular array
|
|
51
|
-
:raises TypeError: if items is not Iterable
|
|
52
|
-
|
|
46
|
+
:param items: Optional iterable to initial populate circular array.
|
|
47
|
+
:param capacity: Fixed storage capacity of circular array.
|
|
48
|
+
:raises TypeError: When ``items`` not Iterable,
|
|
53
49
|
"""
|
|
54
50
|
capacity = max(2, capacity)
|
|
55
51
|
if items is None:
|
|
@@ -201,12 +197,10 @@ class CAF[I]():
|
|
|
201
197
|
return True
|
|
202
198
|
|
|
203
199
|
def pushl(self, item: I) -> None:
|
|
204
|
-
"""
|
|
205
|
-
Push single item onto left side (front) of circular array.
|
|
206
|
-
|
|
207
|
-
:param item: single item pushed onto circular array from left
|
|
208
|
-
:raises ValueError: when called on a full CAF
|
|
200
|
+
"""Push ``item`` on from left.
|
|
209
201
|
|
|
202
|
+
:param item: Single item pushed onto circular array from left (front).
|
|
203
|
+
:raises ValueError: When called on a full ``CAF``.
|
|
210
204
|
"""
|
|
211
205
|
if self._cnt == self._cap:
|
|
212
206
|
msg = 'Method pushl called on a full CAF'
|
|
@@ -223,12 +217,10 @@ class CAF[I]():
|
|
|
223
217
|
)
|
|
224
218
|
|
|
225
219
|
def pushr(self, item: I) -> None:
|
|
226
|
-
"""
|
|
227
|
-
Push a single item onto right side (rear) of circular array.
|
|
228
|
-
|
|
229
|
-
:param item: single item pushed onto circular array from right
|
|
230
|
-
:raises ValueError: when called on a full fixed storage capacity circular array
|
|
220
|
+
"""Push ``item`` on from Right.
|
|
231
221
|
|
|
222
|
+
:param item: Single ``item`` pushed onto circular array from right (rear).
|
|
223
|
+
:raises ValueError: When called on a full fixed storage capacity circular array.
|
|
232
224
|
"""
|
|
233
225
|
if self._cnt == self._cap:
|
|
234
226
|
msg = 'Method pushr called on a full CAF'
|
|
@@ -245,12 +237,10 @@ class CAF[I]():
|
|
|
245
237
|
)
|
|
246
238
|
|
|
247
239
|
def popl(self) -> I:
|
|
248
|
-
"""
|
|
249
|
-
Pop item off left side (front) of circular array.
|
|
250
|
-
|
|
251
|
-
:returns: item popped from left side of circular array
|
|
252
|
-
:raises ValueError: when called on an empty circular array
|
|
240
|
+
"""Pop single item off from left side.
|
|
253
241
|
|
|
242
|
+
:returns: Item popped from left side (front) of circular array.
|
|
243
|
+
:raises ValueError: When called on an empty circular array.
|
|
254
244
|
"""
|
|
255
245
|
if self._cnt > 1:
|
|
256
246
|
(
|
|
@@ -284,12 +274,10 @@ class CAF[I]():
|
|
|
284
274
|
return cast(I, d)
|
|
285
275
|
|
|
286
276
|
def popr(self) -> I:
|
|
287
|
-
"""
|
|
288
|
-
Pop item off right side (rear) of circular array.
|
|
289
|
-
|
|
290
|
-
:returns: item popped from right side of circular array
|
|
291
|
-
:raises ValueError: when called on an empty circular array
|
|
277
|
+
"""Pop single item off from right side.
|
|
292
278
|
|
|
279
|
+
:returns: Item popped from right side (rear) of circular array.
|
|
280
|
+
:raises ValueError: When called on an empty circular array.
|
|
293
281
|
"""
|
|
294
282
|
if self._cnt > 1:
|
|
295
283
|
(
|
|
@@ -323,13 +311,11 @@ class CAF[I]():
|
|
|
323
311
|
return cast(I, d)
|
|
324
312
|
|
|
325
313
|
def popld(self, default: I) -> I:
|
|
326
|
-
"""
|
|
327
|
-
Pop one item from left side of the circular array, provide
|
|
314
|
+
"""Pop one item from left side of the circular array, provide
|
|
328
315
|
a mandatory default value. "Safe" version of popl.
|
|
329
316
|
|
|
330
|
-
:param default:
|
|
331
|
-
:returns:
|
|
332
|
-
|
|
317
|
+
:param default: Item returned if circular array is empty.
|
|
318
|
+
:returns: Item popped from left side or default item if empty.
|
|
333
319
|
"""
|
|
334
320
|
try:
|
|
335
321
|
return self.popl()
|
|
@@ -337,13 +323,11 @@ class CAF[I]():
|
|
|
337
323
|
return default
|
|
338
324
|
|
|
339
325
|
def poprd(self, default: I) -> I:
|
|
340
|
-
"""
|
|
341
|
-
Pop one item from right side of the circular array, provide
|
|
326
|
+
"""Pop one item from right side of the circular array, provide
|
|
342
327
|
a mandatory default value. "Safe" version of popr.
|
|
343
328
|
|
|
344
|
-
:param default:
|
|
345
|
-
:returns:
|
|
346
|
-
|
|
329
|
+
:param default: Item returned if circular array is empty.
|
|
330
|
+
:returns: Item popped from right side or default item if empty.
|
|
347
331
|
"""
|
|
348
332
|
try:
|
|
349
333
|
return self.popr()
|
|
@@ -351,12 +335,10 @@ class CAF[I]():
|
|
|
351
335
|
return default
|
|
352
336
|
|
|
353
337
|
def poplt(self, maximum: int) -> tuple[I, ...]:
|
|
354
|
-
"""
|
|
355
|
-
Pop multiple items from left side of circular array.
|
|
356
|
-
|
|
357
|
-
:param maximum: maximum number of items to pop, may pop less if not enough items
|
|
358
|
-
:returns: items in the order popped, left to right
|
|
338
|
+
"""Pop multiple items from left side of circular array.
|
|
359
339
|
|
|
340
|
+
:param maximum: Maximum number of items to pop, may pop less if not enough items.
|
|
341
|
+
:returns: Tuple of items in the order popped, left to right.
|
|
360
342
|
"""
|
|
361
343
|
item_list: list[I] = []
|
|
362
344
|
|
|
@@ -371,12 +353,10 @@ class CAF[I]():
|
|
|
371
353
|
return tuple(item_list)
|
|
372
354
|
|
|
373
355
|
def poprt(self, maximum: int) -> tuple[I, ...]:
|
|
374
|
-
"""
|
|
375
|
-
Pop multiple items from right side of circular array.
|
|
376
|
-
|
|
377
|
-
:param maximum: maximum number of items to pop, may pop less if not enough items
|
|
378
|
-
:returns: items in the order popped, right to left
|
|
356
|
+
"""Pop multiple items from right side of circular array.
|
|
379
357
|
|
|
358
|
+
:param maximum: Maximum number of items to pop, may pop less if not enough items.
|
|
359
|
+
:returns: Tuple of items in the order popped, right to left.
|
|
380
360
|
"""
|
|
381
361
|
item_list: list[I] = []
|
|
382
362
|
while maximum > 0:
|
|
@@ -389,11 +369,9 @@ class CAF[I]():
|
|
|
389
369
|
return tuple(item_list)
|
|
390
370
|
|
|
391
371
|
def rotl(self, n: int = 1) -> None:
|
|
392
|
-
"""
|
|
393
|
-
Rotate items to the left.
|
|
394
|
-
|
|
395
|
-
:param n: number of times to shift elements to the left
|
|
372
|
+
"""Rotate items to the left.
|
|
396
373
|
|
|
374
|
+
:param n: Number of times to shift elements to the left.
|
|
397
375
|
"""
|
|
398
376
|
if self._cnt < 2:
|
|
399
377
|
return
|
|
@@ -401,11 +379,9 @@ class CAF[I]():
|
|
|
401
379
|
self.pushr(self.popl())
|
|
402
380
|
|
|
403
381
|
def rotr(self, n: int = 1) -> None:
|
|
404
|
-
"""
|
|
405
|
-
Rotate items to the right.
|
|
406
|
-
|
|
407
|
-
:param n: number of times to shift elements to the right
|
|
382
|
+
"""Rotate items to the right.
|
|
408
383
|
|
|
384
|
+
:param n: Number of times to shift elements to the right.
|
|
409
385
|
"""
|
|
410
386
|
if self._cnt < 2:
|
|
411
387
|
return
|
|
@@ -413,24 +389,20 @@ class CAF[I]():
|
|
|
413
389
|
self.pushl(self.popr())
|
|
414
390
|
|
|
415
391
|
def map[U](self, f: Callable[[I], U]) -> "CAF[U]":
|
|
416
|
-
"""
|
|
417
|
-
Apply function ``f`` over the circular array's contents,
|
|
418
|
-
|
|
419
|
-
:param f: callable from type I to type U
|
|
420
|
-
:returns: new fixed circular array instance
|
|
392
|
+
"""Apply function ``f`` over the circular array's contents,
|
|
421
393
|
|
|
394
|
+
:param f: Callable from type ``I`` to type ``U``.
|
|
395
|
+
:returns: New fixed capacity circular array instance.
|
|
422
396
|
"""
|
|
423
397
|
return CAF(map(f, self), self._cap)
|
|
424
398
|
|
|
425
399
|
def foldl[L](self, f: Callable[[L, I], L], start: L | None = None) -> L:
|
|
426
|
-
"""
|
|
427
|
-
Fold left with a function and optional stating item.
|
|
428
|
-
|
|
429
|
-
:param f: first argument to f is for the accumulator
|
|
430
|
-
:param start: optional starting item
|
|
431
|
-
:returns: reduced value produced by the left fold
|
|
432
|
-
:raises ValueError: when circular array empty and no starting item given
|
|
400
|
+
"""Fold left with a function and optional stating item.
|
|
433
401
|
|
|
402
|
+
:param f: Folding function, first argument to ``f`` is for the accumulator.
|
|
403
|
+
:param start: Optional starting item.
|
|
404
|
+
:returns: Reduced value produced by the left fold.
|
|
405
|
+
:raises ValueError: When circular array empty and no starting item given.
|
|
434
406
|
"""
|
|
435
407
|
if self._cnt == 0:
|
|
436
408
|
if start is None:
|
|
@@ -450,14 +422,12 @@ class CAF[I]():
|
|
|
450
422
|
return acc
|
|
451
423
|
|
|
452
424
|
def foldr[R](self, f: Callable[[I, R], R], start: R | None = None) -> R:
|
|
453
|
-
"""
|
|
454
|
-
Fold right with a function and an optional starting item.
|
|
455
|
-
|
|
456
|
-
:param f: second argument to f is for the accumulator
|
|
457
|
-
:param start: optional starting item
|
|
458
|
-
:returns: reduced value produced by the right fold
|
|
459
|
-
:raises ValueError: when circular array empty and no starting item given
|
|
425
|
+
"""Fold right with a function and an optional starting item.
|
|
460
426
|
|
|
427
|
+
:param f: Folding function, second argument to ``f`` is for the accumulator.
|
|
428
|
+
:param start: Optional starting item.
|
|
429
|
+
:returns: Reduced value produced by the right fold.
|
|
430
|
+
:raises ValueError: When circular array empty and no starting item given.
|
|
461
431
|
"""
|
|
462
432
|
if self._cnt == 0:
|
|
463
433
|
if start is None:
|
|
@@ -477,17 +447,14 @@ class CAF[I]():
|
|
|
477
447
|
return acc
|
|
478
448
|
|
|
479
449
|
def capacity(self) -> int:
|
|
480
|
-
"""
|
|
481
|
-
Return fixed storage capacity of the circular array.
|
|
482
|
-
|
|
483
|
-
:returns: fixed storage capacity
|
|
450
|
+
"""Return fixed storage capacity of the circular array.
|
|
484
451
|
|
|
452
|
+
:returns: Fixed storage capacity.
|
|
485
453
|
"""
|
|
486
454
|
return self._cap
|
|
487
455
|
|
|
488
456
|
def empty(self) -> None:
|
|
489
|
-
"""
|
|
490
|
-
Empty the circular array."""
|
|
457
|
+
"""Empty the circular array."""
|
|
491
458
|
(
|
|
492
459
|
self._items,
|
|
493
460
|
self._front,
|
|
@@ -501,22 +468,18 @@ class CAF[I]():
|
|
|
501
468
|
)
|
|
502
469
|
|
|
503
470
|
def fraction_filled(self) -> float:
|
|
504
|
-
"""
|
|
505
|
-
Find fraction of the storage capacity which is filled.
|
|
506
|
-
|
|
507
|
-
:returns: the ratio count/capacity
|
|
471
|
+
"""Find fraction of the storage capacity which is filled.
|
|
508
472
|
|
|
473
|
+
:returns: The ratio count/capacity.
|
|
509
474
|
"""
|
|
510
475
|
return self._cnt / self._cap
|
|
511
476
|
|
|
512
477
|
|
|
513
478
|
def caf[T](*items: T, capacity: int = 2) -> CAF[T]:
|
|
514
|
-
"""
|
|
515
|
-
Produce a circular array from a variable number of arguments.
|
|
516
|
-
|
|
517
|
-
:param items: initial items for a new circular array
|
|
518
|
-
:param capacity: the minimum storage capacity to set
|
|
519
|
-
:returns: new fixed storage capacity circular array
|
|
479
|
+
"""Produce a circular array from a variable number of arguments.
|
|
520
480
|
|
|
481
|
+
:param items: Initial items for a new fixed capacity :circular array.
|
|
482
|
+
:param capacity: The minimum storage capacity to set.
|
|
483
|
+
:returns: New fixed storage capacity circular array.
|
|
521
484
|
"""
|
|
522
485
|
return CAF(items, capacity = capacity)
|
{pythonic_fp_circulararray-5.3.2.dist-info → pythonic_fp_circulararray-5.3.3.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pythonic-fp-circulararray
|
|
3
|
-
Version: 5.3.
|
|
3
|
+
Version: 5.3.3
|
|
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>
|
|
@@ -16,7 +16,7 @@ Classifier: Typing :: Typed
|
|
|
16
16
|
License-File: LICENSE
|
|
17
17
|
Requires-Dist: pytest>=8.4.1 ; extra == "test"
|
|
18
18
|
Project-URL: Changelog, https://github.com/grscheller/pythonic-fp-circulararray/blob/main/CHANGELOG.rst
|
|
19
|
-
Project-URL: Documentation, https://grscheller.github.io/pythonic-fp/circulararray/development/build/html/
|
|
19
|
+
Project-URL: Documentation, https://grscheller.github.io/pythonic-fp/circulararray/development/build/html/index.html
|
|
20
20
|
Project-URL: Homepage, https://github.com/grscheller/pythonic-fp/blob/main/README.md
|
|
21
21
|
Project-URL: Source, https://github.com/grscheller/pythonic-fp-circulararray
|
|
22
22
|
Provides-Extra: test
|
|
@@ -0,0 +1,11 @@
|
|
|
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=_rZhOsC3PGs97j15qM4vXpkpRDTfVkxEGwYyBi9uAQU,19334
|
|
4
|
+
pythonic_fp/circulararray/auto.pyi,sha256=yfQ2kzIiXFb2Bpg3cMwHwv2oSlyOUMTgmdPZM_-oU_8,1669
|
|
5
|
+
pythonic_fp/circulararray/fixed.py,sha256=nzwPnaVOh-KKv503_c--f_m0SkOaUI6mSe1Bo5WACCA,15316
|
|
6
|
+
pythonic_fp/circulararray/fixed.pyi,sha256=y_7eMvH18B1lpLPp2P-VkN-xcQVKJn6cOisp9LSBBRk,1362
|
|
7
|
+
pythonic_fp/circulararray/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
pythonic_fp_circulararray-5.3.3.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
|
|
9
|
+
pythonic_fp_circulararray-5.3.3.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
10
|
+
pythonic_fp_circulararray-5.3.3.dist-info/METADATA,sha256=rdgGmosD6wF1Cfye7QBuZJXGnjs3uDgPzmYYvVpUx-M,2180
|
|
11
|
+
pythonic_fp_circulararray-5.3.3.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
pythonic_fp/circulararray/__init__.py,sha256=4RaMexsQxHwp80j3Z75_td8PGRqLoz1yMvK_ZZ07vi8,1516
|
|
2
|
-
pythonic_fp/circulararray/auto.py,sha256=YIBKvnjerpCg8hmcAS-HSSjGRZSD4C7S_RyCNH4FwoE,19502
|
|
3
|
-
pythonic_fp/circulararray/auto.pyi,sha256=yfQ2kzIiXFb2Bpg3cMwHwv2oSlyOUMTgmdPZM_-oU_8,1669
|
|
4
|
-
pythonic_fp/circulararray/fixed.py,sha256=G58qee_2Rl9e-4hG3vZrQIJTDbpqoECpT-d2M98BcgY,15494
|
|
5
|
-
pythonic_fp/circulararray/fixed.pyi,sha256=y_7eMvH18B1lpLPp2P-VkN-xcQVKJn6cOisp9LSBBRk,1362
|
|
6
|
-
pythonic_fp/circulararray/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
pythonic_fp_circulararray-5.3.2.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
|
|
8
|
-
pythonic_fp_circulararray-5.3.2.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
9
|
-
pythonic_fp_circulararray-5.3.2.dist-info/METADATA,sha256=DJnFE-yTJU7yhdQNjXA4lTc4tsWWp1zULxsBlN5e46w,2183
|
|
10
|
-
pythonic_fp_circulararray-5.3.2.dist-info/RECORD,,
|
{pythonic_fp_circulararray-5.3.2.dist-info → pythonic_fp_circulararray-5.3.3.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|