de¶
- class pythonic_fp.queues.de.DEQueue¶
Bases:
GenericDEQueue
Stateful Double-Ended (DE) Queue data structure.
has a left and a right side
O(1) pops each end
O(1) amortized pushes each end
O(1) length determination
in a Boolean context, truthy if not empty, falsy if empty
will automatically increase storage capacity when needed
neither indexable nor sliceable by design
- __init__(*ds: Iterable) None¶
Initializer
Initialize
DEQueuewith 0 or 1 iterables to populate the queue left (front) to right (rear).- Parameters:
ds – Takes 0 or 1 iterable parameters.
- Raises:
ValueError – When more than one parameter is provided.
TypeError – When passed a non-iterable parameter.
- __bool__() bool¶
Truthiness
Queue truthy when non-empty, falsy when empty.
- __len__() int¶
Get length
Return the number of data elements in the
DEQueue.
- __eq__(other: object) bool¶
Equality comparison
If
otheris aDEQueueand the corresponding elements ofselfandothercompare as equal, then returnTrue. Otherwise returnFalse.- Returns:
self == other
- __iter__() Iterator¶
Iteration
Iterate over current state left to right.
- Returns:
An iterator of the data.
- __reversed__() Iterator¶
Iteration
Iterate over current state right to left.
- Returns:
An iterator of the data.
- __repr__() str¶
String representation
Construct string ‘DEQueue(d₁, d₂, … dₙ)’ where
d₁, d₂, … dₙ are the contents displayed with
repr()
- Returns:
A string to reproduce the
DEQueue.
- __str__() str¶
User string
Construct string ‘>< d₁ | d₂ | … | dₙ ><’ where
d₁, d₂, …, dₙ are the contents displayed with
str()
- Returns:
A string meaningful to an end user.
- copy() DEQueue[D]¶
Copy
Shallow copy the
DEQueue.- Returns:
New
DEQueueinstance containing the same references.
- pushl(*ds: D) None¶
Push left
Push data onto left side of
DEQueue.- Parameters:
ds – Data to be pushed onto
DEQueuefrom the left.
- pushr(*ds: D) None¶
Push right
Push data onto right side of
DEQueue.- Parameters:
ds – Data to be pushed onto
DEQueuefrom the right.
- popl() MayBe¶
Pop left
Pop next item from left side
DEQueue, if it exists.- Returns:
MayBeof popped item if queue was not empty, emptyMayBeotherwise.
- popr() MayBe¶
Pop right
Pop next item off right side ‘’DEQueue``, if it exists.
- Returns:
MayBeof popped item if queue was not empty, emptyMayBeotherwise.
- peakl() MayBe¶
Peak left
Peak left side of
DEQueue. Does not consume item.- Returns:
MayBeof leftmost item if queue not empty, emptyMayBeotherwise.
- peakr() MayBe¶
Peak right
Peak right side of
DEQueue. Does not consume item.- Returns:
MayBeof rightmost item if queue not empty, emptyMayBeotherwise.
- foldl(f: Callable[[D, D], D]) MayBe[D]¶
- foldl(f: Callable[[L, D], L], start: L) MayBe[L]
Fold left
Reduce
DEQueueleft to right.- Parameters:
f – Reducing function, first argument is for accumulator.
start – Optional starting value.
- Returns:
MayBeof reduced value withf, emptyMayBeif queue empty and no starting value given.
- foldr(f: Callable[[D, D], D]) MayBe[D]¶
- foldr(f: Callable[[D, R], R], start: R) MayBe[R]
Fold right
Reduce
DEQueueright to left.- Parameters:
f – Reducing function, second argument is for accumulator.
start – Optional starting value.
- Returns:
MayBeof reduced value withf, emptyMayBeif queue empty and no starting value given.