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.
Namespace: X3Platform.Collections
The DequeT type exposes the following members.
Name | Description | |
---|---|---|
![]() | DequeT |
Create a new Deque that is initially empty.
|
![]() | DequeT(IEnumerableT) |
Create a new Deque initialized with the items from the passed collection,
in order.
|
Name | Description | |
---|---|---|
![]() | Add |
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).) |
![]() | AddManyToBack |
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.
|
![]() | AddManyToFront |
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.
|
![]() | AddToBack |
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.
|
![]() | AddToFront |
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.
|
![]() | AsReadOnly |
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.) |
![]() | Clear |
Removes all items from the Deque.
(Overrides ListBaseTClear.) |
![]() | Clone |
Creates a new Deque that is a copy of this one.
|
![]() | CloneContents |
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.
|
![]() | Contains |
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.) |
![]() | ConvertAllTOutput |
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.) |
![]() | CopyTo(T) |
Copies all the items in the list, in order, to array,
starting at index 0.
(Inherited from ListBaseT.) |
![]() | CopyTo(T, Int32) |
Copies all the items in the Deque into an array.
(Overrides CollectionBaseTCopyTo(T, Int32).) |
![]() | CopyTo(Int32, T, Int32, Int32) |
Copies a range of elements from the list to array,
starting at arrayIndex.
(Inherited from ListBaseT.) |
![]() | CountWhere |
Counts the number of items in the collection that satisfy the condition
defined by predicate.
(Inherited from CollectionBaseT.) |
![]() | Equals | (Inherited from Object.) |
![]() | Exists |
Determines if the collection contains any item that satisfies the condition
defined by predicate.
(Inherited from CollectionBaseT.) |
![]() | Finalize | (Inherited from Object.) |
![]() | Find |
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.) |
![]() | FindAll |
Enumerates the items in the collection that satisfy the condition defined
by predicate.
(Inherited from CollectionBaseT.) |
![]() | FindIndex(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.) |
![]() | FindIndex(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.) |
![]() | FindIndex(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.) |
![]() | FindLast |
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.) |
![]() | FindLastIndex(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.) |
![]() | FindLastIndex(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.) |
![]() | FindLastIndex(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.) |
![]() | ForEach |
Performs the specified action on each item in this collection.
(Inherited from CollectionBaseT.) |
![]() | GetAtBack |
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).
|
![]() | GetAtFront |
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).
|
![]() | GetEnumerator |
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.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() | IndexOf(T) |
Finds the index of the first item in the list that is equal to item.
(Inherited from ListBaseT.) |
![]() | IndexOf(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.) |
![]() | IndexOf(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.) |
![]() | Insert |
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).) |
![]() | InsertRange |
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.
|
![]() | LastIndexOf(T) |
Finds the index of the last item in the list that is equal to item.
(Inherited from ListBaseT.) |
![]() | LastIndexOf(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.) |
![]() | LastIndexOf(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.) |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | Range |
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.) |
![]() | Remove |
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.) |
![]() | RemoveAll |
Removes all the items in the collection that satisfy the condition
defined by predicate.
(Inherited from CollectionBaseT.) |
![]() | RemoveAt |
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).) |
![]() | RemoveFromBack |
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.
|
![]() | RemoveFromFront |
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.
|
![]() | RemoveRange |
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.
|
![]() | ToArray |
Creates an array of the correct size, and copies all the items in the
collection into the array, by calling CopyTo.
(Inherited from CollectionBaseT.) |
![]() | ToString |
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.) |
![]() | TrimToSize |
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.
|
![]() | TrueForAll |
Determines if all of the items in the collection satisfy the condition
defined by predicate.
(Inherited from CollectionBaseT.) |
![]() | TryFind |
Finds the first item in the list that satisfies the condition
defined by predicate.
(Inherited from ListBaseT.) |
![]() | TryFindLast |
Finds the last item in the list that satisfies the condition
defined by predicate.
(Inherited from ListBaseT.) |
Name | Description | |
---|---|---|
![]() | Capacity |
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.
|
![]() | Count |
Gets the number of items currently stored in the Deque. The last item
in the Deque has index Count-1.
(Overrides ListBaseTCount.) |
![]() | Item |
Gets or sets an item at a particular index in the Deque.
(Overrides ListBaseTItemInt32.) |
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.