Class Deque<T>
Python's collections.deque as the wrappers use it: a sequence that keeps the last MaxLen items,
dropping the oldest as new ones are appended (RecordEpisodeStatistics's return_queue). Indexing and
repr follow Python: queue[-1] is the newest, and it prints deque([1.0, 2.0], maxlen=100).
public sealed class Deque<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
TThe item type.
- Inheritance
-
Deque<T>
- Implements
-
IEnumerable<T>
- Inherited Members
- Extension Methods
Remarks
A ring buffer: appending is O(1) and never allocates once the deque is full. Not synchronized, like Python's (whose single appends happen to be atomic under the GIL); one wrapper fills it from one thread. Reference: collections.deque.
Constructors
Deque(int?)
A deque of at most maxLen items, or unbounded for null (Python's deque(maxlen=n)).
public Deque(int? maxLen = null)
Parameters
maxLenint?The bound; 0 keeps nothing, as in Python.
Exceptions
- ValueError
Thrown for a negative bound:
maxlen must be non-negative.
Properties
Count
The number of items held, len(d).
public int Count { get; }
Property Value
this[int]
Python's d[i]: the index-th oldest item, counting from the newest for a negative index
(-1 is the newest).
public T this[int index] { get; }
Parameters
indexintThe index, negative from the end.
Property Value
- T
The item.
Exceptions
- IndexError
Thrown outside the deque:
deque index out of range.
MaxLen
The bound (maxlen), or null when unbounded.
public int? MaxLen { get; }
Property Value
- int?
Methods
Append(T)
Python's d.append(item): adds the item as the newest; a full bounded deque drops its oldest item first, so
it always holds the last MaxLen appended.
public void Append(T item)
Parameters
itemTThe item.
Clear()
Python's d.clear(): drops every item.
public void Clear()
GetEnumerator()
Enumerates the items, oldest first.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
The enumerator.
ToString()
Python's repr(d): deque([1.0, 2.0], maxlen=100), or deque([1.0, 2.0]) when unbounded.
public override string ToString()
Returns
- string
The text.