class · System
Queue<T>
public class Queue<T>
First in, first out: Enqueue at the end, Dequeue from the front (a ring buffer).
- Kind
- class
- Namespace
- System
- Assembly
- System.Core
- Access
- public
- Source file
List.ant
Type parameters
| Name | Constraints |
|---|---|
T | any type |
Inheritance
- Base classes
-
AnyQueue<T>
Constructors
new()
#
Properties
Methods
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
Queue<T> as Antril, decompiled from its Larva HIR.
// System.Queue — System.Core (decompiled from Larva HIR)
into namespace System
{
/// First in, first out: Enqueue at the end, Dequeue from the front (a ring buffer).
public class Queue<T>
{
T[] items;
i32 head;
i32 count;
[NoInline]
Grow()
{
T[] bigger = new T[items.Length * 2];
loop (i32 i = 0..count)
bigger[i] = items[(head + i) % items.Length];
items = bigger;
head = 0;
}
public:
new()
{
items = new T[8];
}
Enqueue(T item)
{
if (count == items.Length)
Grow();
i32 at = head + count;
if (at >= items.Length)
at -= items.Length;
items[at] = item;
count++;
}
Dequeue() : T
{
if (count == 0)
throw new InvalidOperationError("Dequeue on an empty queue");
T item = items[head];
items[head] = default(T);
head++;
if (head == items.Length)
head = 0;
count--;
return item;
}
Peek() : T
{
if (count == 0)
throw new InvalidOperationError("Peek on an empty queue");
return items[head];
}
Clear()
{
loop (i32 i = 0..count)
items[(head + i) % items.Length] = default(T);
head = 0;
count = 0;
}
i32 Count
{
get => count;
}
bool IsEmpty
{
get => count == 0;
}
}
}