Click or drag to resize
DequeT Class

The Deque class implements a type of list known as a Double Ended Queue. A Deque is quite similar to a List, in that items have indices (starting at 0), and the item at any index can be efficiently retrieved. The difference between a List and a Deque lies in the efficiency of inserting elements at the beginning. In a List, items can be efficiently added to the end, but inserting an item at the beginning of the List is slow, taking time proportional to the size of the List. In a Deque, items can be added to the beginning or end equally efficiently, regardless of the number of items in the Deque. As a trade-off for this increased flexibility, Deque is somewhat slower than List (but still constant time) when being indexed to get or retrieve elements.

Inheritance Hierarchy
SystemObject
  X3Platform.CollectionsCollectionBaseT
    X3Platform.CollectionsListBaseT
      X3Platform.CollectionsDequeT

Namespace: X3Platform.Collections
Assembly: X3Platform.Support (in X3Platform.Support.dll) Version: 1.0.0.0 (2.0.0.0)
Syntax
[SerializableAttribute]
public class Deque<T> : ListBase<T>, ICloneable

Type Parameters

T
The type of items stored in the Deque.

The DequeT type exposes the following members.

Constructors
Methods
  NameDescription
Public methodAdd
Adds an item to the back of the Deque. The indices of all existing items in the Deque are unchanged. This method is equivalent to AddToBack(item).
(Overrides ListBaseTAdd(T).)
Public methodAddManyToBack
Adds a collection of items to the back of the Deque. The indices of all existing items in the Deque are unchanged. The last item in the added collection becomes the last item in the Deque.
Public methodAddManyToFront
Adds a collection of items to the front of the Deque. The indices of all existing items in the Deque are increased by the number of items inserted. The first item in the added collection becomes the first item in the Deque.
Public methodAddToBack
Adds an item to the back of the Deque. The indices of all existing items in the Deque are unchanged. This method is equivalent to Insert(Count, item) but is a little more efficient.
Public methodAddToFront
Adds an item to the front of the Deque. The indices of all existing items in the Deque are increased by 1. This method is equivalent to Insert(0, item) but is a little more efficient.
Public methodAsReadOnly
Provides a read-only view of this list. The returned IList<T> provides a view of the list that prevents modifications to the list. Use the method to provide access to the list without allowing changes. Since the returned object is just a view, changes to the list will be reflected in the view.
(Inherited from ListBaseT.)
Public methodClear
Removes all items from the Deque.
(Overrides ListBaseTClear.)
Public methodClone
Creates a new Deque that is a copy of this one.
Public methodCloneContents
Makes a deep clone of this Deque. A new Deque is created with a clone of each element of this set, by calling ICloneable.Clone on each element. If T is a value type, then each element is copied as if by simple assignment.
Public methodContains
Determines if the list contains any item that compares equal to item. The implementation simply checks whether IndexOf(item) returns a non-negative value.
(Inherited from ListBaseT.)
Public methodConvertAllTOutput
Convert this collection of items by applying a delegate to each item in the collection. The resulting enumeration contains the result of applying converter to each item in this collection, in order.
(Inherited from CollectionBaseT.)
Public methodCopyTo(T)
Copies all the items in the list, in order, to array, starting at index 0.
(Inherited from ListBaseT.)
Public methodCopyTo(T, Int32)
Copies all the items in the Deque into an array.
(Overrides CollectionBaseTCopyTo(T, Int32).)
Public methodCopyTo(Int32, T, Int32, Int32)
Copies a range of elements from the list to array, starting at arrayIndex.
(Inherited from ListBaseT.)
Public methodCountWhere
Counts the number of items in the collection that satisfy the condition defined by predicate.
(Inherited from CollectionBaseT.)
Public methodEquals (Inherited from Object.)
Public methodExists
Determines if the collection contains any item that satisfies the condition defined by predicate.
(Inherited from CollectionBaseT.)
Protected methodFinalize (Inherited from Object.)
Public methodFind
Finds the first item in the list that satisfies the condition defined by predicate. If no item matches the condition, than the default value for T (null or all-zero) is returned.
(Inherited from ListBaseT.)
Public methodFindAll
Enumerates the items in the collection that satisfy the condition defined by predicate.
(Inherited from CollectionBaseT.)
Public methodFindIndex(PredicateT)
Finds the index of the first item in the list that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.
(Inherited from ListBaseT.)
Public methodFindIndex(Int32, PredicateT)
Finds the index of the first item, in the range of items extending from index to the end, that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.
(Inherited from ListBaseT.)
Public methodFindIndex(Int32, Int32, PredicateT)
Finds the index of the first item, in the range of count items starting from index, that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.
(Inherited from ListBaseT.)
Public methodFindLast
Finds the last item in the list that satisfies the condition defined by predicate. If no item matches the condition, than the default value for T (null or all-zero) is returned.
(Inherited from ListBaseT.)
Public methodFindLastIndex(PredicateT)
Finds the index of the last item in the list that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.
(Inherited from ListBaseT.)
Public methodFindLastIndex(Int32, PredicateT)
Finds the index of the last item, in the range of items extending from the beginning of the list to index, that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.
(Inherited from ListBaseT.)
Public methodFindLastIndex(Int32, Int32, PredicateT)
Finds the index of the last item, in the range of count items ending at index, that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.
(Inherited from ListBaseT.)
Public methodForEach
Performs the specified action on each item in this collection.
(Inherited from CollectionBaseT.)
Public methodGetAtBack
Retreives the item currently at the back of the Deque. The Deque is unchanged. This method is equivalent to deque[deque.Count - 1] (except that a different exception is thrown).
Public methodGetAtFront
Retreives the item currently at the front of the Deque. The Deque is unchanged. This method is equivalent to deque[0] (except that a different exception is thrown).
Public methodGetEnumerator
Enumerates all of the items in the list, in order. The item at index 0 is enumerated first, then the item at index 1, and so on. If the items are added to or removed from the Deque during enumeration, the enumeration ends with an InvalidOperationException.
(Overrides ListBaseTGetEnumerator.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodIndexOf(T)
Finds the index of the first item in the list that is equal to item.
(Inherited from ListBaseT.)
Public methodIndexOf(T, Int32)
Finds the index of the first item, in the range of items extending from index to the end, that is equal to item.
(Inherited from ListBaseT.)
Public methodIndexOf(T, Int32, Int32)
Finds the index of the first item, in the range of count items starting from index, that is equal to item.
(Inherited from ListBaseT.)
Public methodInsert
Inserts a new item at the given index in the Deque. All items at indexes equal to or greater than index move up one index in the Deque.
(Overrides ListBaseTInsert(Int32, T).)
Public methodInsertRange
Inserts a collection of items at the given index in the Deque. All items at indexes equal to or greater than index increase their indices in the Deque by the number of items inserted.
Public methodLastIndexOf(T)
Finds the index of the last item in the list that is equal to item.
(Inherited from ListBaseT.)
Public methodLastIndexOf(T, Int32)
Finds the index of the last item, in the range of items extending from the beginning of the list to index, that is equal to item.
(Inherited from ListBaseT.)
Public methodLastIndexOf(T, Int32, Int32)
Finds the index of the last item, in the range of count items ending at index, that is equal to item.
(Inherited from ListBaseT.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodRange
Returns a view onto a sub-range of this list. Items are not copied; the returned IList<T> is simply a different view onto the same underlying items. Changes to this list are reflected in the view, and vice versa. Insertions and deletions in the view change the size of the view, but insertions and deletions in the underlying list do not.
(Inherited from ListBaseT.)
Public methodRemove
Searches the list for the first item that compares equal to item. If one is found, it is removed. Otherwise, the list is unchanged.
(Inherited from ListBaseT.)
Public methodRemoveAll
Removes all the items in the collection that satisfy the condition defined by predicate.
(Inherited from CollectionBaseT.)
Public methodRemoveAt
Removes the item at the given index in the Deque. All items at indexes greater than index move down one index in the Deque.
(Overrides ListBaseTRemoveAt(Int32).)
Public methodRemoveFromBack
Removes an item from the back of the Deque. The indices of all existing items in the Deque are unchanged. This method is equivalent to RemoveAt(Count-1) but is a little more efficient.
Public methodRemoveFromFront
Removes an item from the front of the Deque. The indices of all existing items in the Deque are decreased by 1. This method is equivalent to RemoveAt(0) but is a little more efficient.
Public methodRemoveRange
Removes a range of items at the given index in the Deque. All items at indexes greater than index move down count indices in the Deque.
Public methodToArray
Creates an array of the correct size, and copies all the items in the collection into the array, by calling CopyTo.
(Inherited from CollectionBaseT.)
Public methodToString
Shows the string representation of the collection. The string representation contains a list of the items in the collection. Contained collections (except string) are expanded recursively.
(Inherited from CollectionBaseT.)
Public methodTrimToSize
Trims the amount of memory used by the Deque by changing the Capacity to be equal to Count. If no more items will be added to the Deque, calling TrimToSize will reduce the amount of memory used by the Deque.
Public methodTrueForAll
Determines if all of the items in the collection satisfy the condition defined by predicate.
(Inherited from CollectionBaseT.)
Public methodTryFind
Finds the first item in the list that satisfies the condition defined by predicate.
(Inherited from ListBaseT.)
Public methodTryFindLast
Finds the last item in the list that satisfies the condition defined by predicate.
(Inherited from ListBaseT.)
Top
Properties
  NameDescription
Public propertyCapacity
Gets or sets the capacity of the Deque. The Capacity is the number of items that this Deque can hold without expanding its internal buffer. Since Deque will automatically expand its buffer when necessary, in almost all cases it is unnecessary to worry about the capacity. However, if it is known that a Deque will contain exactly 1000 items eventually, it can slightly improve efficiency to set the capacity to 1000 up front, so that the Deque does not have to expand automatically.
Public propertyCount
Gets the number of items currently stored in the Deque. The last item in the Deque has index Count-1.
(Overrides ListBaseTCount.)
Public propertyItem
Gets or sets an item at a particular index in the Deque.
(Overrides ListBaseTItemInt32.)
Top
Remarks

The Deque class can also be used as a more flexible alternative to the Queue and Stack classes. Deque is as efficient as Queue and Stack for adding or removing items, but is more flexible: it allows access to all items in the queue, and allows adding or removing from either end.

Deque is implemented as a ring buffer, which is grown as necessary. The size of the buffer is doubled whenever the existing capacity is too small to hold all the elements.

See Also