Class ExposedQueue<T>
- Namespace
- Aplib.Core.Collections
- Assembly
- Aplib.Core.dll
A queue with all elements exposed. Functionally works like a queue with indexing. It has a MaxCount and Count. MaxCount being the maximal length of the queue, and Count being the actual number of elements in the queue.
public class ExposedQueue<T> : ICollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
T
- Inheritance
-
ExposedQueue<T>
- Implements
-
ICollection<T>IEnumerable<T>
- Inherited Members
Remarks
When adding an element to a full queue, all other elements are shifted one place like so: [4, 3, 2, 1], Put(5) => [5, 4, 3, 2]
Constructors
ExposedQueue(int)
Initializes a new empty instance of the ExposedQueue<T> class.
public ExposedQueue(int size)
Parameters
size
intThe maximum size of the queue.
ExposedQueue(T[])
Initializes a new instance of the ExposedQueue<T> class with an array.
public ExposedQueue(T[] array)
Parameters
array
T[]The array to initialize the queue with.
Remarks
The array will be copied to the queue, and the head will be set to the last element of the array. This method expects the array to be filled.
Exceptions
- ArgumentOutOfRangeException
Thrown when the max count is negative.
ExposedQueue(T[], int)
Initializes a new instance of the ExposedQueue<T> class with an array.
public ExposedQueue(T[] array, int maxCount)
Parameters
array
T[]The array to initialize the queue with.
maxCount
intThe maximum count of the queue.
Remarks
The array will be copied to the queue, and the head will be set to the last element of the array. This method expects the array to be filled.
Exceptions
- ArgumentOutOfRangeException
Thrown when the max count is negative.
Properties
Count
Actual number of elements in the array.
public int Count { get; }
Property Value
IsReadOnly
Gets a value indicating whether the ICollection<T> is read-only.
public bool IsReadOnly { get; }
Property Value
- bool
true if the ICollection<T> is read-only; otherwise, false.
this[int]
Gets the element at the specified index. Throws an exception if the index is out of bounds.
public T this[int index] { get; }
Parameters
index
intThe index of the element to get.
Property Value
- T
The element at the specified index.
Exceptions
- ArgumentOutOfRangeException
Thrown when the index is out of range.
MaxCount
The length of the array.
public int MaxCount { get; }
Property Value
Methods
Add(T)
Adds an item to the ICollection<T>.
public void Add(T item)
Parameters
item
TThe object to add to the ICollection<T>.
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
Clear()
Removes all items from the ICollection<T>.
public void Clear()
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
Contains(T)
Determines whether the ICollection<T> contains a specific value.
public bool Contains(T item)
Parameters
item
TThe object to locate in the ICollection<T>.
Returns
- bool
true if
item
is found in the ICollection<T>; otherwise, false.
CopyTo(T[], int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
public void CopyTo(T[] array, int arrayIndex)
Parameters
array
T[]The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.
arrayIndex
intThe zero-based index in
array
at which copying begins.
Exceptions
- ArgumentNullException
array
is null.- ArgumentOutOfRangeException
arrayIndex
is less than 0.- ArgumentException
The number of elements in the source ICollection<T> is greater than the available space from
arrayIndex
to the end of the destinationarray
.
CopyTo(T[], int, int)
Copies the ExposedQueue to an array. The head should be the last element of the array. Copies from start to end inclusive.
public void CopyTo(T[] array, int arrayIndex, int endIndex)
Parameters
array
T[]The array to copy to."
arrayIndex
intThe start index of the range to copy.
endIndex
intThe end index of the range to copy.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An enumerator that can be used to iterate through the collection.
GetFirst()
Gets the first element of the queue.
public T GetFirst()
Returns
- T
The first element of the queue.
GetLast()
Gets the element at the end of the queue.
public T GetLast()
Returns
- T
The element at the end of the queue.
Put(T)
Puts an element at the start of the queue.
public void Put(T value)
Parameters
value
TThe element to add to the queue.
Remove(T)
Removes the specified item from the queue and shifts remaining elements to the left. For example, given the queue [4, 3, 2, 1], if you call Remove(3), the resulting queue will be [4, 2, 1].
public bool Remove(T item)
Parameters
item
TThe item to remove.
Returns
- bool
True if the item was successfully removed; otherwise, false.
Remarks
The MaxCount will not change, but the Count will decrease by one.
ToArray()
Converts the ExposedQueue to an array. Only returns the used slots.
public T[] ToArray()
Returns
- T[]
An array containing the elements within the specified range.
ToArray(int, int)
Converts the ExposedQueue to an array.
public T[] ToArray(int start, int end)
Parameters
Returns
- T[]
An array containing the elements within the specified range.