mirror of
https://github.com/AlexMacocian/SystemExtensions.git
synced 2026-07-15 14:19:29 +00:00
Implemented queue interface for standardization.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SystemExtensions.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of a queue based on a circular array. Efficient implementation when capacity is known from before.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Provided type.</typeparam>
|
||||
class CircularQueue<T> : IQueue<T>
|
||||
{
|
||||
#region Fields
|
||||
int count;
|
||||
int capacity;
|
||||
int insertLocation;
|
||||
int readLocation;
|
||||
T[] items;
|
||||
#endregion
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Returns the number of items in the queue.
|
||||
/// </summary>
|
||||
public int Count { get => count; }
|
||||
/// <summary>
|
||||
/// Capacity of the queue.
|
||||
/// </summary>
|
||||
public int Capacity { get => capacity;
|
||||
set
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Constructors
|
||||
public CircularQueue()
|
||||
{
|
||||
count = 0;
|
||||
capacity = 10;
|
||||
items = new T[capacity];
|
||||
}
|
||||
public CircularQueue(int capacity)
|
||||
{
|
||||
this.capacity = capacity;
|
||||
count = 0;
|
||||
items = new T[capacity];
|
||||
}
|
||||
#endregion
|
||||
#region Public Methods
|
||||
/// <summary>
|
||||
/// Clears the queue.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Checks if provided item is present into the queue.
|
||||
/// </summary>
|
||||
/// <param name="item">Item to be checked.</param>
|
||||
/// <returns>True if item is present. False otherwise.</returns>
|
||||
public bool Contains(T item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes and returns the first item from the queue.
|
||||
/// </summary>
|
||||
/// <returns>First item from the queue.</returns>
|
||||
public T Dequeue()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Inserts provided item into the queue.
|
||||
/// </summary>
|
||||
/// <param name="item">Item to be inserted.</param>
|
||||
public void Enqueue(T item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Checks and returns the first item from the queue without removing it.
|
||||
/// </summary>
|
||||
/// <returns>The first item from the queue.</returns>
|
||||
public T Peek()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region Private Methods
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SystemExtensions.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for queue implementations.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Provided type.</typeparam>
|
||||
public interface IQueue<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the number of items in the queue.
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
/// <summary>
|
||||
/// Inserts item into the queue.
|
||||
/// </summary>
|
||||
/// <param name="item">Item to be inserted.</param>
|
||||
void Enqueue(T item);
|
||||
/// <summary>
|
||||
/// Remove the first item in the queue.
|
||||
/// </summary>
|
||||
/// <returns>First item in the queue.</returns>
|
||||
T Dequeue();
|
||||
/// <summary>
|
||||
/// Looks up the first item from the queue without removing it.
|
||||
/// </summary>
|
||||
/// <returns>First item from the queue.</returns>
|
||||
T Peek();
|
||||
/// <summary>
|
||||
/// Clears the contents of the queue.
|
||||
/// </summary>
|
||||
void Clear();
|
||||
/// <summary>
|
||||
/// Checks if queue contains an item.
|
||||
/// </summary>
|
||||
/// <param name="item">Item to be checked.</param>
|
||||
/// <returns>True if queue contains provided item. False otherwise.</returns>
|
||||
bool Contains(T item);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace SystemExtensions.Collections
|
||||
/// Exposes some of the functionality of the Binary Heap as a queue.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Provided type.</typeparam>
|
||||
public class PriorityQueue<T>
|
||||
public class PriorityQueue<T> : IQueue<T>
|
||||
{
|
||||
#region Fields
|
||||
private BinaryHeap<T> binaryHeap;
|
||||
@@ -77,6 +77,15 @@ namespace SystemExtensions.Collections
|
||||
{
|
||||
binaryHeap.Clear();
|
||||
}
|
||||
/// <summary>
|
||||
/// Checks if queue contains provided item.
|
||||
/// </summary>
|
||||
/// <param name="item">Item to be checked.</param>
|
||||
/// <returns>True if queue contains the provided item. False otherwise.</returns>
|
||||
public bool Contains(T item)
|
||||
{
|
||||
return binaryHeap.Contains(item);
|
||||
}
|
||||
#endregion
|
||||
#region Private Methods
|
||||
#endregion
|
||||
|
||||
@@ -46,12 +46,15 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Collections\BinaryHeap.cs" />
|
||||
<Compile Include="Collections\CircularQueue.cs" />
|
||||
<Compile Include="Collections\FibonacciHeap.cs" />
|
||||
<Compile Include="Collections\IQueue.cs" />
|
||||
<Compile Include="Collections\PriorityQueue.cs" />
|
||||
<Compile Include="Collections\Treap.cs" />
|
||||
<Compile Include="Comparators.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Threading\PriorityThreadPool.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user