Table of Contents

Class BaseSetLinearCollection<T>

Namespace
Garyon.DataStructures
Assembly
Garyon.dll

Represents a linear collection accompanied by a set. This data structure encapsulates an ordered linear collection data type that has a specific insertion and removal order (e.g. Queue<T>, 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 abstract class BaseSetLinearCollection<T> : IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable

Type Parameters

T

The type of the stored elements.

Inheritance
BaseSetLinearCollection<T>
Implements
Derived
Inherited Members
Extension Methods

Constructors

BaseSetLinearCollection()

Initializes a new empty instance of the BaseSetLinearCollection<T> class.

protected BaseSetLinearCollection()

BaseSetLinearCollection(IEqualityComparer<T>)

Initializes a new empty instance of the BaseSetLinearCollection<T> class with a given comparer for the HashSet<T>.

protected BaseSetLinearCollection(IEqualityComparer<T> comparer)

Parameters

comparer IEqualityComparer<T>

The comparer that HashSet<T> will use for the elements.

BaseSetLinearCollection(int)

Initializes a new empty instance of the BaseSetLinearCollection<T> class with a given initial capacity.

protected BaseSetLinearCollection(int capacity)

Parameters

capacity int

The capacity of both the contained linear collection and the HashSet<T>.

BaseSetLinearCollection(int, IEqualityComparer<T>)

Initializes a new empty instance of the BaseSetLinearCollection<T> class with a given initial capacity and a given comparer for the HashSet<T>.

protected BaseSetLinearCollection(int capacity, IEqualityComparer<T> comparer)

Parameters

capacity int

The capacity of both the contained linear collection and the HashSet<T>.

comparer IEqualityComparer<T>

The comparer that HashSet<T> will use for the elements.

Properties

Count

The count of elements in the setted linear collection.

public int Count { get; }

Property Value

int

IsEmpty

Determines whether the setted linear collection is empty or not.

public bool IsEmpty { get; }

Property Value

bool

Methods

Add(T)

Adds an item in the setted linear collection, if it is not already stored.

public bool Add(T item)

Parameters

item T

The item to add.

Returns

bool

true if the item was not contained anywhere in the setted linear collection and was successfully added, otherwise false.

AddRange(IEnumerable<T>)

Adds a collection of items to the setted linear collection. The order at which each item is added is determined by the enumeration order of the provided collection.

public void AddRange(IEnumerable<T> items)

Parameters

items IEnumerable<T>

The collection of items to add to the setted linear collection.

AddToLinearCollection(T)

Adds an item to the linear collection.

protected abstract void AddToLinearCollection(T item)

Parameters

item T

The item to add to the linear collection.

Remarks

It should only perform the necessary operations to the linear collection.

Clear()

Clears the setted linear collection, emptying the linear collection and the set individually.

public void Clear()

ClearLinearCollection()

Clears the linear collection. It should call the respective Clear method for the linear collection instance that backs the data structure.

protected abstract void ClearLinearCollection()

Contains(T)

Determines whether an item is contained in the setted linear collection.

public bool Contains(T item)

Parameters

item T

The item to find in the setted linear collection.

Returns

bool

true if the item is contained in the set, otherwise false.

CopyTo(T[], int)

Copies the elements of the linear collection in the provided T[] starting from the given array index.

public abstract void CopyTo(T[] array, int arrayIndex)

Parameters

array T[]

The array in which to copy the elements of the linear collection in the order they would be removed.

arrayIndex int

The index of the first element that will be copied from the linear collection into.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public abstract IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

An enumerator that can be used to iterate through the collection.

Peek()

Peeks the linear collection. This does not remove any items from the setted linear collection.

public abstract T Peek()

Returns

T

The item that was peeked from the linear collection. It is the item that will be removed next.

Remove()

Removes the item from the linear collection, and also removes it from the set.

public T Remove()

Returns

T

The removed item.

RemoveFromLinearCollection()

Removes the next item to be removed from the linear collection.

protected abstract 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.

RemoveRange(int)

Removes a number of items from the setted linear collection, and returns them in the order they were removed.

public IEnumerable<T> RemoveRange(int count)

Parameters

count int

The number of items to remove from the setted linear collection. If the setted linear collection 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 removed from the setted linear collection.