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
TThe type of elements contained in the deque.
- Inheritance
-
objectDeque<T>
- Implements
-
IList<T>ICollection<T>IEnumerable<T>
- 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
capacityintThe 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
Exceptions
- InvalidOperationException
Capacitycannot 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
indexintThe index of the item to get or set.
Property Value
- T
Exceptions
- ArgumentOutOfRangeException
indexis 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
valueTThe element to insert.
AddToFront(T)
Inserts a single element at the front of this deque.
public void AddToFront(T value)
Parameters
valueTThe 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
valueT
Returns
- int
The zero-based index of
valuein this sorted Deque<T>, ifvalueis found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger thanvalueor, 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
valueTcomparerTComparer
Returns
- int
The zero-based index of
valuein this sorted Deque<T>, ifvalueis found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger thanvalueor, 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
compareris 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
itemTThe object to locate in this list.
Returns
- int
The index of
itemif 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
indexintThe zero-based index at which
itemshould be inserted.itemTThe object to insert into this list.
Exceptions
- ArgumentOutOfRangeException
indexis 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
indexintThe index at which the collection is inserted.
collectionIEnumerable<T>The collection of elements to insert.
Exceptions
- ArgumentOutOfRangeException
indexis 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
itemTThe object to remove from this list.
Returns
- bool
true if
itemwas successfully removed from this list; otherwise, false. This method also returns false ifitemis 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
indexintThe zero-based index of the item to remove.
Exceptions
- ArgumentOutOfRangeException
indexis 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
offsetintThe index into the deque at which the range begins.
countintThe number of elements to remove.
Exceptions
- ArgumentOutOfRangeException
Either
offsetorcountis less than 0.- ArgumentException
The range [
offset,offset+count) is not within the range [0, Count).