mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-01 10:58:29 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
52 lines
778 B
C#
52 lines
778 B
C#
namespace Sandbox.Utility;
|
|
|
|
internal class UniqueQueue<T> : IEnumerable<T>
|
|
{
|
|
private readonly HashSet<T> set;
|
|
private readonly Queue<T> queue;
|
|
|
|
public UniqueQueue()
|
|
{
|
|
set = new HashSet<T>();
|
|
queue = new Queue<T>();
|
|
}
|
|
|
|
public int Count => queue.Count;
|
|
|
|
public void Enqueue( T item )
|
|
{
|
|
if ( set.Add( item ) )
|
|
{
|
|
queue.Enqueue( item );
|
|
}
|
|
}
|
|
|
|
public T Dequeue()
|
|
{
|
|
T item = queue.Dequeue();
|
|
set.Remove( item );
|
|
return item;
|
|
}
|
|
|
|
public bool Contains( T item )
|
|
{
|
|
return set.Contains( item );
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
set.Clear();
|
|
queue.Clear();
|
|
}
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
return queue.GetEnumerator();
|
|
}
|
|
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
|
{
|
|
return queue.GetEnumerator();
|
|
}
|
|
}
|