Skip to content

Commit 8aeb1d7

Browse files
Deque as growable ring buffer
1 parent 9b0179f commit 8aeb1d7

File tree

6 files changed

+1192
-905
lines changed

6 files changed

+1192
-905
lines changed

Doc/library/collections.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ or subtracting from an empty counter.
479479
corresponding number of items are discarded from the opposite end. Bounded
480480
length deques provide functionality similar to the ``tail`` filter in
481481
Unix. They are also useful for tracking transactions and other pools of data
482-
where only the most recent activity is of interest.
482+
where only the most recent activity is of interest. Passing a *maxlen*
483+
greater than :data:`sys.maxsize` raises :exc:`ValueError`.
483484

484485

485486
Deque objects support the following methods:
@@ -591,9 +592,11 @@ or subtracting from an empty counter.
591592

592593
In addition to the above, deques support iteration, pickling, ``len(d)``,
593594
``reversed(d)``, ``copy.copy(d)``, ``copy.deepcopy(d)``, membership testing with
594-
the :keyword:`in` operator, and subscript references such as ``d[0]`` to access
595-
the first element. Indexed access is *O*\ (1) at both ends but slows to *O*\ (*n*) in
596-
the middle. For fast random access, use lists instead.
595+
the :keyword:`in` operator, subscript references such as ``d[0]`` to access
596+
the first element, and slicing notation like ``d[i:j:k]`` which returns a new
597+
deque of the same type (including subclasses) while preserving ``maxlen``.
598+
Indexed access is *O*\ (1). Slicing is *O*\ (k) where *k* is the number of
599+
elements in the slice.
597600

598601
Starting in version 3.5, deques support ``__add__()``, ``__mul__()``,
599602
and ``__imul__()``.

Lib/collections/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
except ImportError:
5555
pass
5656

57+
try:
58+
# Ditto for reverse iterators (used by pickle reducers)
59+
from _collections import _deque_reverse_iterator # noqa: F401
60+
except ImportError:
61+
pass
62+
5763
try:
5864
from _collections import defaultdict
5965
except ImportError:

0 commit comments

Comments
 (0)