67 lines
1.3 KiB
C#
67 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CaeGlobals
|
|
{
|
|
public class UniqueQueue<T> : IEnumerable<T>
|
|
{
|
|
private HashSet<T> hashSet;
|
|
private Queue<T> queue;
|
|
|
|
public UniqueQueue()
|
|
{
|
|
hashSet = new HashSet<T>();
|
|
queue = new Queue<T>();
|
|
}
|
|
|
|
public int Count
|
|
{
|
|
get
|
|
{
|
|
return hashSet.Count;
|
|
}
|
|
}
|
|
public void Clear()
|
|
{
|
|
hashSet.Clear();
|
|
queue.Clear();
|
|
}
|
|
|
|
|
|
public bool Contains(T item)
|
|
{
|
|
return hashSet.Contains(item);
|
|
}
|
|
public void Enqueue(T item)
|
|
{
|
|
if (hashSet.Add(item))
|
|
{
|
|
queue.Enqueue(item);
|
|
}
|
|
}
|
|
public T Dequeue()
|
|
{
|
|
T item = queue.Dequeue();
|
|
hashSet.Remove(item);
|
|
return item;
|
|
}
|
|
public T Peek()
|
|
{
|
|
return queue.Peek();
|
|
}
|
|
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
return queue.GetEnumerator();
|
|
}
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
|
{
|
|
return queue.GetEnumerator();
|
|
}
|
|
}
|
|
}
|