Class QueueSet<T>
- Namespace
- Garyon.DataStructures
- Assembly
- Garyon.dll
Represents a set whose elements are stored in a queue. This data structure encapsulates a Queue<T> and a HashSet<T>. Through the usage of the set, the data structure ensures that no elements are contained more than once.
public sealed class QueueSet<T> : BaseSetLinearCollection<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
TThe type of the stored elements.
- Inheritance
-
QueueSet<T>
- Implements
-
IEnumerable<T>
- Inherited Members
- Extension Methods
Constructors
QueueSet()
Initializes a new empty instance of the QueueSet<T> class.
public QueueSet()
QueueSet(IEqualityComparer<T>)
Initializes a new empty instance of the QueueSet<T> class with a given comparer for the HashSet<T>.
public QueueSet(IEqualityComparer<T> comparer)
Parameters
comparerIEqualityComparer<T>The comparer that HashSet<T> will use for the elements.
QueueSet(int)
Initializes a new empty instance of the QueueSet<T> class with a given initial capacity.
public QueueSet(int capacity)
Parameters
capacityintThe capacity of both the contained Queue<T> and the HashSet<T>.
QueueSet(int, IEqualityComparer<T>)
Initializes a new empty instance of the QueueSet<T> class with a given initial capacity and a given comparer for the HashSet<T>.
public QueueSet(int capacity, IEqualityComparer<T> comparer)
Parameters
capacityintThe capacity of both the contained Queue<T> and the HashSet<T>.
comparerIEqualityComparer<T>The comparer that HashSet<T> will use for the elements.
Methods
AddToLinearCollection(T)
Adds an item to the linear collection.
protected override void AddToLinearCollection(T item)
Parameters
itemTThe item to add to the linear collection.
Remarks
It should only perform the necessary operations to the linear collection.
ClearLinearCollection()
Clears the linear collection. It should call the respective Clear method for the linear collection instance that backs the data structure.
protected override void ClearLinearCollection()
CopyTo(T[], int)
Copies the elements of the linear collection in the provided
T[] starting from the given array index.
public override void CopyTo(T[] array, int arrayIndex)
Parameters
arrayT[]The array in which to copy the elements of the linear collection in the order they would be removed.
arrayIndexintThe index of the first element that will be copied from the linear collection into.
Dequeue()
Dequeues the item at the start of the queue, and also removes it from the set.
public T Dequeue()
Returns
- T
The dequeued item.
DequeueRange(int)
Dequeues a number of items from the queue set, and returns them in the order they were dequeued.
public IEnumerable<T> DequeueRange(int count)
Parameters
countintThe number of items to dequeue from the queue set. If the queue set contains less items than the provided count, it will be capped to the current item count.
Returns
- IEnumerable<T>
The collection of items that were dequeued from the queue set.
Enqueue(T)
Enqueues an item in the queue set, if it is not already stored.
public bool Enqueue(T item)
Parameters
itemTThe item to enqueue.
Returns
- bool
true if the item was not contained anywhere in the queue set and was successfully enqueued, otherwise false.
EnqueueRange(IEnumerable<T>)
Enqueues a collection of items to the queue set. The order at which each item is enqueued is determined by the enumeration order of the provided collection.
public void EnqueueRange(IEnumerable<T> items)
Parameters
itemsIEnumerable<T>The collection of items to enqueue to the queue set.
GetEnumerator()
Gets the enumerator for this queue set, which is the enumerator for the queue.
public override IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
The queue's enumerator.
Peek()
Peeks the linear collection. This does not remove any items from the setted linear collection.
public override T Peek()
Returns
- T
The item that was peeked from the linear collection. It is the item that will be removed next.
RemoveFromLinearCollection()
Removes the next item to be removed from the linear collection.
protected override T RemoveFromLinearCollection()
Returns
- T
The item that was removed from the linear collection.
Remarks
It should only perform the necessary operations to the linear collection.