Class StackSet<T>
- Namespace
- Garyon.DataStructures
- Assembly
- Garyon.dll
Represents a set whose elements are stored in a stack. This data structure encapsulates a Stack<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 StackSet<T> : BaseSetLinearCollection<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
TThe type of the stored elements.
- Inheritance
-
StackSet<T>
- Implements
-
IEnumerable<T>
- Inherited Members
- Extension Methods
Constructors
StackSet()
Initializes a new empty instance of the StackSet<T> class.
public StackSet()
StackSet(IEqualityComparer<T>)
Initializes a new empty instance of the StackSet<T> class with a given comparer for the HashSet<T>.
public StackSet(IEqualityComparer<T> comparer)
Parameters
comparerIEqualityComparer<T>The comparer that HashSet<T> will use for the elements.
StackSet(int)
Initializes a new empty instance of the StackSet<T> class with a given initial capacity.
public StackSet(int capacity)
Parameters
capacityintThe capacity of both the contained Stack<T> and the HashSet<T>.
StackSet(int, IEqualityComparer<T>)
Initializes a new empty instance of the StackSet<T> class with a given initial capacity and a given comparer for the HashSet<T>.
public StackSet(int capacity, IEqualityComparer<T> comparer)
Parameters
capacityintThe capacity of both the contained Stack<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.
GetEnumerator()
Gets the enumerator for this stack set, which is the enumerator for the stack.
public override IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
The stack'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.
Pop()
Pops the item at the top of the stack, and also removes it from the set.
public T Pop()
Returns
- T
The popped item.
PopRange(int)
Pops a number of items from the stack set, and returns them in the order they were popped.
public IEnumerable<T> PopRange(int count)
Parameters
countintThe number of items to pop from the stack set. If the stack 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 popped from the stack set.
Push(T)
Pushes an item in the stack set, if it is not already stored.
public bool Push(T item)
Parameters
itemTThe item to push.
Returns
- bool
true if the item was not contained anywhere in the stack set and was successfully pushed, otherwise false.
PushRange(IEnumerable<T>)
Pushes a collection of items to the stack set. The order at which each item is pushed is determined by the enumeration order of the provided collection.
public void PushRange(IEnumerable<T> items)
Parameters
itemsIEnumerable<T>The collection of items to push to the stack set.
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.