using System;
using System.Runtime.InteropServices;
namespace System.Collections.Generic
{
/// Represents a first-in, first-out collection of objects.
/// Specifies the type of elements in the queue.
/// 1
// Token: 0x0200000E RID: 14
[ComVisible(false)]
[Serializable]
public class Queue : IEnumerable, ICollection, IEnumerable
{
/// Initializes a new instance of the class that is empty and has the default initial capacity.
// Token: 0x06000043 RID: 67 RVA: 0x00002CB8 File Offset: 0x00000EB8
public Queue()
{
this._array = new T[0];
}
/// Initializes a new instance of the class that is empty and has the specified initial capacity.
/// The initial number of elements that the can contain.
///
/// is less than zero.
// Token: 0x06000044 RID: 68 RVA: 0x00002CCC File Offset: 0x00000ECC
public Queue(int count)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException("count");
}
this._array = new T[count];
}
/// Initializes a new instance of the class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.
/// The collection whose elements are copied to the new .
///
/// is null.
// Token: 0x06000045 RID: 69 RVA: 0x00002D00 File Offset: 0x00000F00
public Queue(IEnumerable collection)
{
if (collection == null)
{
throw new ArgumentNullException("collection");
}
ICollection collection2 = collection as ICollection;
int num = ((collection2 == null) ? 0 : collection2.Count);
this._array = new T[num];
foreach (T t in collection)
{
this.Enqueue(t);
}
}
/// Copies the elements of the to an , starting at a particular index.
/// The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing.
/// The zero-based index in at which copying begins.
///
/// is null.
///
/// is less than zero.
///
/// is multidimensional.-or- does not have zero-based indexing.-or-The number of elements in the source is greater than the available space from to the end of the destination .-or-The type of the source cannot be cast automatically to the type of the destination .
// Token: 0x06000046 RID: 70 RVA: 0x00002D9C File Offset: 0x00000F9C
void ICollection.CopyTo(Array array, int idx)
{
if (array == null)
{
throw new ArgumentNullException();
}
if (idx > array.Length)
{
throw new ArgumentOutOfRangeException();
}
if (array.Length - idx < this._size)
{
throw new ArgumentOutOfRangeException();
}
if (this._size == 0)
{
return;
}
try
{
int num = this._array.Length;
int num2 = num - this._head;
Array.Copy(this._array, this._head, array, idx, Math.Min(this._size, num2));
if (this._size > num2)
{
Array.Copy(this._array, 0, array, idx + num2, this._size - num2);
}
}
catch (ArrayTypeMismatchException)
{
throw new ArgumentException();
}
}
/// Gets a value indicating whether access to the is synchronized (thread safe).
/// true if access to the is synchronized (thread safe); otherwise, false. In the default implementation of , this property always returns false.
// Token: 0x17000010 RID: 16
// (get) Token: 0x06000047 RID: 71 RVA: 0x00002E70 File Offset: 0x00001070
bool ICollection.IsSynchronized
{
get
{
return false;
}
}
/// Gets an object that can be used to synchronize access to the .
/// An object that can be used to synchronize access to the . In the default implementation of , this property always returns the current instance.
// Token: 0x17000011 RID: 17
// (get) Token: 0x06000048 RID: 72 RVA: 0x00002E74 File Offset: 0x00001074
object ICollection.SyncRoot
{
get
{
return this;
}
}
// Token: 0x06000049 RID: 73 RVA: 0x00002E78 File Offset: 0x00001078
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
/// Returns an enumerator that iterates through a collection.
/// An that can be used to iterate through the collection.
// Token: 0x0600004A RID: 74 RVA: 0x00002E88 File Offset: 0x00001088
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
/// Removes all objects from the .
/// 1
// Token: 0x0600004B RID: 75 RVA: 0x00002E98 File Offset: 0x00001098
public void Clear()
{
Array.Clear(this._array, 0, this._array.Length);
this._head = (this._tail = (this._size = 0));
this._version++;
}
/// Determines whether an element is in the .
/// true if is found in the ; otherwise, false.
/// The object to locate in the . The value can be null for reference types.
// Token: 0x0600004C RID: 76 RVA: 0x00002EE0 File Offset: 0x000010E0
public bool Contains(T item)
{
if (item == null)
{
foreach (T t in this)
{
if (t == null)
{
return true;
}
}
}
else
{
foreach (T t2 in this)
{
if (item.Equals(t2))
{
return true;
}
}
}
return false;
}
/// Copies the elements to an existing one-dimensional , starting at the specified array index.
/// The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing.
/// The zero-based index in at which copying begins.
///
/// is null.
///
/// is less than zero.
/// The number of elements in the source is greater than the available space from to the end of the destination .
// Token: 0x0600004D RID: 77 RVA: 0x00002FCC File Offset: 0x000011CC
public void CopyTo(T[] array, int idx)
{
if (array == null)
{
throw new ArgumentNullException();
}
((ICollection)this).CopyTo(array, idx);
}
/// Removes and returns the object at the beginning of the .
/// The object that is removed from the beginning of the .
/// The is empty.
// Token: 0x0600004E RID: 78 RVA: 0x00002FE4 File Offset: 0x000011E4
public T Dequeue()
{
T t = this.Peek();
this._array[this._head] = default(T);
if (++this._head == this._array.Length)
{
this._head = 0;
}
this._size--;
this._version++;
return t;
}
/// Returns the object at the beginning of the without removing it.
/// The object at the beginning of the .
/// The is empty.
// Token: 0x0600004F RID: 79 RVA: 0x00003054 File Offset: 0x00001254
public T Peek()
{
if (this._size == 0)
{
throw new InvalidOperationException();
}
return this._array[this._head];
}
/// Adds an object to the end of the .
/// The object to add to the . The value can be null for reference types.
// Token: 0x06000050 RID: 80 RVA: 0x00003084 File Offset: 0x00001284
public void Enqueue(T item)
{
if (this._size == this._array.Length || this._tail == this._array.Length)
{
this.SetCapacity(Math.Max(Math.Max(this._size, this._tail) * 2, 4));
}
this._array[this._tail] = item;
if (++this._tail == this._array.Length)
{
this._tail = 0;
}
this._size++;
this._version++;
}
/// Copies the elements to a new array.
/// A new array containing elements copied from the .
// Token: 0x06000051 RID: 81 RVA: 0x0000312C File Offset: 0x0000132C
public T[] ToArray()
{
T[] array = new T[this._size];
this.CopyTo(array, 0);
return array;
}
/// Sets the capacity to the actual number of elements in the , if that number is less than 90 percent of current capacity.
// Token: 0x06000052 RID: 82 RVA: 0x00003150 File Offset: 0x00001350
public void TrimExcess()
{
if ((double)this._size < (double)this._array.Length * 0.9)
{
this.SetCapacity(this._size);
}
}
// Token: 0x06000053 RID: 83 RVA: 0x00003180 File Offset: 0x00001380
private void SetCapacity(int new_size)
{
if (new_size == this._array.Length)
{
return;
}
if (new_size < this._size)
{
throw new InvalidOperationException("shouldnt happen");
}
T[] array = new T[new_size];
if (this._size > 0)
{
this.CopyTo(array, 0);
}
this._array = array;
this._tail = this._size;
this._head = 0;
this._version++;
}
/// Gets the number of elements contained in the .
/// The number of elements contained in the .
// Token: 0x17000012 RID: 18
// (get) Token: 0x06000054 RID: 84 RVA: 0x000031F8 File Offset: 0x000013F8
public int Count
{
get
{
return this._size;
}
}
/// Returns an enumerator that iterates through the .
/// An for the .
// Token: 0x06000055 RID: 85 RVA: 0x00003200 File Offset: 0x00001400
public Queue.Enumerator GetEnumerator()
{
return new Queue.Enumerator(this);
}
// Token: 0x04000033 RID: 51
private T[] _array;
// Token: 0x04000034 RID: 52
private int _head;
// Token: 0x04000035 RID: 53
private int _tail;
// Token: 0x04000036 RID: 54
private int _size;
// Token: 0x04000037 RID: 55
private int _version;
/// Enumerates the elements of a .
// Token: 0x0200000F RID: 15
[Serializable]
public struct Enumerator : IEnumerator, IDisposable, IEnumerator
{
// Token: 0x06000056 RID: 86 RVA: 0x00003208 File Offset: 0x00001408
internal Enumerator(Queue q)
{
this.q = q;
this.idx = -2;
this.ver = q._version;
}
/// Sets the enumerator to its initial position, which is before the first element in the collection.
/// The collection was modified after the enumerator was created.
// Token: 0x06000057 RID: 87 RVA: 0x00003228 File Offset: 0x00001428
void IEnumerator.Reset()
{
if (this.ver != this.q._version)
{
throw new InvalidOperationException();
}
this.idx = -2;
}
/// Gets the element at the current position of the enumerator.
/// The element in the collection at the current position of the enumerator.
/// The enumerator is positioned before the first element of the collection or after the last element.
// Token: 0x17000013 RID: 19
// (get) Token: 0x06000058 RID: 88 RVA: 0x0000325C File Offset: 0x0000145C
object IEnumerator.Current
{
get
{
return this.Current;
}
}
/// Releases all resources used by the .
// Token: 0x06000059 RID: 89 RVA: 0x0000326C File Offset: 0x0000146C
public void Dispose()
{
this.idx = -2;
}
/// Advances the enumerator to the next element of the .
/// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
/// The collection was modified after the enumerator was created.
// Token: 0x0600005A RID: 90 RVA: 0x00003278 File Offset: 0x00001478
public bool MoveNext()
{
if (this.ver != this.q._version)
{
throw new InvalidOperationException();
}
if (this.idx == -2)
{
this.idx = this.q._size;
}
return this.idx != -1 && --this.idx != -1;
}
/// Gets the element at the current position of the enumerator.
/// The element in the at the current position of the enumerator.
/// The enumerator is positioned before the first element of the collection or after the last element.
// Token: 0x17000014 RID: 20
// (get) Token: 0x0600005B RID: 91 RVA: 0x000032E8 File Offset: 0x000014E8
public T Current
{
get
{
if (this.idx < 0)
{
throw new InvalidOperationException();
}
return this.q._array[(this.q._size - 1 - this.idx + this.q._head) % this.q._array.Length];
}
}
// Token: 0x04000038 RID: 56
private const int NOT_STARTED = -2;
// Token: 0x04000039 RID: 57
private const int FINISHED = -1;
// Token: 0x0400003A RID: 58
private Queue q;
// Token: 0x0400003B RID: 59
private int idx;
// Token: 0x0400003C RID: 60
private int ver;
}
}
}