Table of Contents

Class Deque<T>

Namespace
Stride.Core.Collections
Assembly
Stride.Core.dll

A double-ended queue (deque), which provides O(1) indexed access, O(1) removals from the front and back, amortized O(1) insertions to the front and back, and O(N) insertions and removals anywhere else (with the operations getting slower as the index approaches the middle).

public sealed class Deque<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable

Type Parameters

T

The type of elements contained in the deque.

Inheritance
object
Deque<T>
Implements
Extension Methods

Constructors

Deque()

Initializes a new instance of the Deque<T> class.

public Deque()

Deque(int)

Initializes a new instance of the Deque<T> class with the specified capacity.

public Deque(int capacity)

Parameters

capacity int

The initial capacity. Must be a power of two greater than 0.

Properties

Capacity

Gets or sets the capacity for this deque. This value must always be greater than zero, and this property cannot be set to a value less than Count.

public int Capacity { get; set; }

Property Value

int

Exceptions

InvalidOperationException

Capacity cannot be set to a value less than Count.

Count

Gets the number of elements contained in this deque.

public int Count { get; }

Property Value

int

The number of elements contained in this deque.

this[int]

Gets or sets the item at the specified index.

public T this[int index] { get; set; }

Parameters

index int

The index of the item to get or set.

Property Value

T

Exceptions

ArgumentOutOfRangeException

index is not a valid index in this list.

NotSupportedException

This property is set and the list is read-only.

Methods

AddToBack(T)

Inserts a single element at the back of this deque.

public void AddToBack(T value)

Parameters

value T

The element to insert.

AddToFront(T)

Inserts a single element at the front of this deque.

public void AddToFront(T value)

Parameters

value T

The element to insert.

BinarySearch(T)

Perform a binary search over this Deque<T> to find value using the default comparer.

public int BinarySearch(T value)

Parameters

value T

Returns

int

The zero-based index of value in this sorted Deque<T>, if value is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than value or, if there is no larger element, the bitwise complement of Count.

Remarks

Result is undefined when the items in this Deque<T> are unordered.

BinarySearch<TComparer>(T, TComparer)

Perform a binary search over this Deque<T> to find value using comparer.

public int BinarySearch<TComparer>(T value, TComparer comparer) where TComparer : IComparer<T>, allows ref struct

Parameters

value T
comparer TComparer

Returns

int

The zero-based index of value in this sorted Deque<T>, if value is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than value or, if there is no larger element, the bitwise complement of Count.

Type Parameters

TComparer

Remarks

Result is undefined when the items in this Deque<T> are unordered.

Exceptions

ArgumentNullException

comparer is null.

Clear()

Removes all items from this deque.

public void Clear()

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

A IEnumerator<T> that can be used to iterate through the collection.

IndexOf(T)

Determines the index of a specific item in this list.

public int IndexOf(T item)

Parameters

item T

The object to locate in this list.

Returns

int

The index of item if found in this list; otherwise, -1.

Insert(int, T)

Inserts an item to this list at the specified index.

public void Insert(int index, T item)

Parameters

index int

The zero-based index at which item should be inserted.

item T

The object to insert into this list.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in this list.

NotSupportedException

This list is read-only.

InsertRange(int, IEnumerable<T>)

Inserts a collection of elements into this deque.

public void InsertRange(int index, IEnumerable<T> collection)

Parameters

index int

The index at which the collection is inserted.

collection IEnumerable<T>

The collection of elements to insert.

Exceptions

ArgumentOutOfRangeException

index is not a valid index to an insertion point for the source.

Remove(T)

Removes the first occurrence of a specific object from this list.

public bool Remove(T item)

Parameters

item T

The object to remove from this list.

Returns

bool

true if item was successfully removed from this list; otherwise, false. This method also returns false if item is not found in this list.

Exceptions

NotSupportedException

This list is read-only.

RemoveAt(int)

Removes the item at the specified index.

public void RemoveAt(int index)

Parameters

index int

The zero-based index of the item to remove.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in this list.

NotSupportedException

This list is read-only.

RemoveFromBack()

Removes and returns the last element of this deque.

public T RemoveFromBack()

Returns

T

The former last element.

Exceptions

InvalidOperationException

The deque is empty.

RemoveFromFront()

Removes and returns the first element of this deque.

public T RemoveFromFront()

Returns

T

The former first element.

Exceptions

InvalidOperationException

The deque is empty.

RemoveRange(int, int)

Removes a range of elements from this deque.

public void RemoveRange(int offset, int count)

Parameters

offset int

The index into the deque at which the range begins.

count int

The number of elements to remove.

Exceptions

ArgumentOutOfRangeException

Either offset or count is less than 0.

ArgumentException

The range [offset, offset + count) is not within the range [0, Count).