Table of Contents

Class Deque<T>

Namespace
Gym.Utils
Assembly
Gym.dll

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

T

The item type.

Inheritance
Deque<T>
Implements
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

maxLen int?

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

int

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

index int

The 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

item T

The 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.