538 lines
17 KiB
C#
538 lines
17 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.Collections
|
|
{
|
|
/// <summary>Represents a simple last-in-first-out (LIFO) non-generic collection of objects.</summary>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x02000142 RID: 322
|
|
[DebuggerDisplay("Count={Count}")]
|
|
[DebuggerTypeProxy(typeof(CollectionDebuggerView))]
|
|
[ComVisible(true)]
|
|
[Serializable]
|
|
public class Stack : IEnumerable, ICloneable, ICollection
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Stack" /> class that is empty and has the default initial capacity.</summary>
|
|
// Token: 0x06001096 RID: 4246 RVA: 0x00044464 File Offset: 0x00042664
|
|
public Stack()
|
|
{
|
|
this.contents = new object[16];
|
|
this.capacity = 16;
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Stack" /> class that contains elements copied from the specified collection and has the same initial capacity as the number of elements copied.</summary>
|
|
/// <param name="col">The <see cref="T:System.Collections.ICollection" /> to copy elements from. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="col" /> is null. </exception>
|
|
// Token: 0x06001097 RID: 4247 RVA: 0x00044494 File Offset: 0x00042694
|
|
public Stack(ICollection col)
|
|
: this((col != null) ? col.Count : 16)
|
|
{
|
|
if (col == null)
|
|
{
|
|
throw new ArgumentNullException("col");
|
|
}
|
|
foreach (object obj in col)
|
|
{
|
|
this.Push(obj);
|
|
}
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Stack" /> class that is empty and has the specified initial capacity or the default initial capacity, whichever is greater.</summary>
|
|
/// <param name="initialCapacity">The initial number of elements that the <see cref="T:System.Collections.Stack" /> can contain. </param>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">
|
|
/// <paramref name="initialCapacity" /> is less than zero. </exception>
|
|
// Token: 0x06001098 RID: 4248 RVA: 0x00044524 File Offset: 0x00042724
|
|
public Stack(int initialCapacity)
|
|
{
|
|
if (initialCapacity < 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException("initialCapacity");
|
|
}
|
|
this.capacity = initialCapacity;
|
|
this.contents = new object[this.capacity];
|
|
}
|
|
|
|
// Token: 0x06001099 RID: 4249 RVA: 0x00044560 File Offset: 0x00042760
|
|
private void Resize(int ncapacity)
|
|
{
|
|
ncapacity = Math.Max(ncapacity, 16);
|
|
object[] array = new object[ncapacity];
|
|
Array.Copy(this.contents, array, this.count);
|
|
this.capacity = ncapacity;
|
|
this.contents = array;
|
|
}
|
|
|
|
/// <summary>Returns a synchronized (thread safe) wrapper for the <see cref="T:System.Collections.Stack" />.</summary>
|
|
/// <returns>A synchronized wrapper around the <see cref="T:System.Collections.Stack" />.</returns>
|
|
/// <param name="stack">The <see cref="T:System.Collections.Stack" /> to synchronize. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="stack" /> is null. </exception>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x0600109A RID: 4250 RVA: 0x000445A0 File Offset: 0x000427A0
|
|
public static Stack Synchronized(Stack stack)
|
|
{
|
|
if (stack == null)
|
|
{
|
|
throw new ArgumentNullException("stack");
|
|
}
|
|
return new Stack.SyncStack(stack);
|
|
}
|
|
|
|
/// <summary>Gets the number of elements contained in the <see cref="T:System.Collections.Stack" />.</summary>
|
|
/// <returns>The number of elements contained in the <see cref="T:System.Collections.Stack" />.</returns>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x170002C2 RID: 706
|
|
// (get) Token: 0x0600109B RID: 4251 RVA: 0x000445BC File Offset: 0x000427BC
|
|
public virtual int Count
|
|
{
|
|
get
|
|
{
|
|
return this.count;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets a value indicating whether access to the <see cref="T:System.Collections.Stack" /> is synchronized (thread safe).</summary>
|
|
/// <returns>true, if access to the <see cref="T:System.Collections.Stack" /> is synchronized (thread safe); otherwise, false. The default is false.</returns>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x170002C3 RID: 707
|
|
// (get) Token: 0x0600109C RID: 4252 RVA: 0x000445C4 File Offset: 0x000427C4
|
|
public virtual bool IsSynchronized
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets an object that can be used to synchronize access to the <see cref="T:System.Collections.Stack" />.</summary>
|
|
/// <returns>An <see cref="T:System.Object" /> that can be used to synchronize access to the <see cref="T:System.Collections.Stack" />.</returns>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x170002C4 RID: 708
|
|
// (get) Token: 0x0600109D RID: 4253 RVA: 0x000445C8 File Offset: 0x000427C8
|
|
public virtual object SyncRoot
|
|
{
|
|
get
|
|
{
|
|
return this;
|
|
}
|
|
}
|
|
|
|
/// <summary>Removes all objects from the <see cref="T:System.Collections.Stack" />.</summary>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x0600109E RID: 4254 RVA: 0x000445CC File Offset: 0x000427CC
|
|
public virtual void Clear()
|
|
{
|
|
this.modCount++;
|
|
for (int i = 0; i < this.count; i++)
|
|
{
|
|
this.contents[i] = null;
|
|
}
|
|
this.count = 0;
|
|
this.current = -1;
|
|
}
|
|
|
|
/// <summary>Creates a shallow copy of the <see cref="T:System.Collections.Stack" />.</summary>
|
|
/// <returns>A shallow copy of the <see cref="T:System.Collections.Stack" />.</returns>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x0600109F RID: 4255 RVA: 0x00044618 File Offset: 0x00042818
|
|
public virtual object Clone()
|
|
{
|
|
return new Stack(this.contents)
|
|
{
|
|
current = this.current,
|
|
count = this.count
|
|
};
|
|
}
|
|
|
|
/// <summary>Determines whether an element is in the <see cref="T:System.Collections.Stack" />.</summary>
|
|
/// <returns>true, if <paramref name="obj" /> is found in the <see cref="T:System.Collections.Stack" />; otherwise, false.</returns>
|
|
/// <param name="obj">The <see cref="T:System.Object" /> to locate in the <see cref="T:System.Collections.Stack" />. The value can be null. </param>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x060010A0 RID: 4256 RVA: 0x0004464C File Offset: 0x0004284C
|
|
public virtual bool Contains(object obj)
|
|
{
|
|
if (this.count == 0)
|
|
{
|
|
return false;
|
|
}
|
|
if (obj == null)
|
|
{
|
|
for (int i = 0; i < this.count; i++)
|
|
{
|
|
if (this.contents[i] == null)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int j = 0; j < this.count; j++)
|
|
{
|
|
if (obj.Equals(this.contents[j]))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>Copies the <see cref="T:System.Collections.Stack" /> to an existing one-dimensional <see cref="T:System.Array" />, starting at the specified array index.</summary>
|
|
/// <param name="array">The one-dimensional <see cref="T:System.Array" /> that is the destination of the elements copied from <see cref="T:System.Collections.Stack" />. The <see cref="T:System.Array" /> must have zero-based indexing. </param>
|
|
/// <param name="index">The zero-based index in <paramref name="array" /> at which copying begins. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="array" /> is null. </exception>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">
|
|
/// <paramref name="index" /> is less than zero. </exception>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="array" /> is multidimensional.-or- The number of elements in the source <see cref="T:System.Collections.Stack" /> is greater than the available space from <paramref name="index" /> to the end of the destination <paramref name="array" />. </exception>
|
|
/// <exception cref="T:System.InvalidCastException">The type of the source <see cref="T:System.Collections.Stack" /> cannot be cast automatically to the type of the destination <paramref name="array" />. </exception>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x060010A1 RID: 4257 RVA: 0x000446C4 File Offset: 0x000428C4
|
|
public virtual void CopyTo(Array array, int index)
|
|
{
|
|
if (array == null)
|
|
{
|
|
throw new ArgumentNullException("array");
|
|
}
|
|
if (index < 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException("index");
|
|
}
|
|
if (array.Rank > 1 || (array.Length > 0 && index >= array.Length) || this.count > array.Length - index)
|
|
{
|
|
throw new ArgumentException();
|
|
}
|
|
for (int num = this.current; num != -1; num--)
|
|
{
|
|
array.SetValue(this.contents[num], this.count - (num + 1) + index);
|
|
}
|
|
}
|
|
|
|
/// <summary>Returns an <see cref="T:System.Collections.IEnumerator" /> for the <see cref="T:System.Collections.Stack" />.</summary>
|
|
/// <returns>An <see cref="T:System.Collections.IEnumerator" /> for the <see cref="T:System.Collections.Stack" />.</returns>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x060010A2 RID: 4258 RVA: 0x00044764 File Offset: 0x00042964
|
|
public virtual IEnumerator GetEnumerator()
|
|
{
|
|
return new Stack.Enumerator(this);
|
|
}
|
|
|
|
/// <summary>Returns the object at the top of the <see cref="T:System.Collections.Stack" /> without removing it.</summary>
|
|
/// <returns>The <see cref="T:System.Object" /> at the top of the <see cref="T:System.Collections.Stack" />.</returns>
|
|
/// <exception cref="T:System.InvalidOperationException">The <see cref="T:System.Collections.Stack" /> is empty. </exception>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x060010A3 RID: 4259 RVA: 0x0004476C File Offset: 0x0004296C
|
|
public virtual object Peek()
|
|
{
|
|
if (this.current == -1)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
return this.contents[this.current];
|
|
}
|
|
|
|
/// <summary>Removes and returns the object at the top of the <see cref="T:System.Collections.Stack" />.</summary>
|
|
/// <returns>The <see cref="T:System.Object" /> removed from the top of the <see cref="T:System.Collections.Stack" />.</returns>
|
|
/// <exception cref="T:System.InvalidOperationException">The <see cref="T:System.Collections.Stack" /> is empty. </exception>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x060010A4 RID: 4260 RVA: 0x00044790 File Offset: 0x00042990
|
|
public virtual object Pop()
|
|
{
|
|
if (this.current == -1)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
this.modCount++;
|
|
object obj = this.contents[this.current];
|
|
this.contents[this.current] = null;
|
|
this.count--;
|
|
this.current--;
|
|
if (this.count <= this.capacity / 4 && this.count > 16)
|
|
{
|
|
this.Resize(this.capacity / 2);
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
/// <summary>Inserts an object at the top of the <see cref="T:System.Collections.Stack" />.</summary>
|
|
/// <param name="obj">The <see cref="T:System.Object" /> to push onto the <see cref="T:System.Collections.Stack" />. The value can be null. </param>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x060010A5 RID: 4261 RVA: 0x00044824 File Offset: 0x00042A24
|
|
public virtual void Push(object obj)
|
|
{
|
|
this.modCount++;
|
|
if (this.capacity == this.count)
|
|
{
|
|
this.Resize(this.capacity * 2);
|
|
}
|
|
this.count++;
|
|
this.current++;
|
|
this.contents[this.current] = obj;
|
|
}
|
|
|
|
/// <summary>Copies the <see cref="T:System.Collections.Stack" /> to a new array.</summary>
|
|
/// <returns>A new array containing copies of the elements of the <see cref="T:System.Collections.Stack" />.</returns>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x060010A6 RID: 4262 RVA: 0x00044888 File Offset: 0x00042A88
|
|
public virtual object[] ToArray()
|
|
{
|
|
object[] array = new object[this.count];
|
|
Array.Copy(this.contents, array, this.count);
|
|
Array.Reverse(array);
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x04000402 RID: 1026
|
|
private const int default_capacity = 16;
|
|
|
|
// Token: 0x04000403 RID: 1027
|
|
private object[] contents;
|
|
|
|
// Token: 0x04000404 RID: 1028
|
|
private int current = -1;
|
|
|
|
// Token: 0x04000405 RID: 1029
|
|
private int count;
|
|
|
|
// Token: 0x04000406 RID: 1030
|
|
private int capacity;
|
|
|
|
// Token: 0x04000407 RID: 1031
|
|
private int modCount;
|
|
|
|
// Token: 0x02000143 RID: 323
|
|
[Serializable]
|
|
private class SyncStack : Stack
|
|
{
|
|
// Token: 0x060010A7 RID: 4263 RVA: 0x000448BC File Offset: 0x00042ABC
|
|
internal SyncStack(Stack s)
|
|
{
|
|
this.stack = s;
|
|
}
|
|
|
|
// Token: 0x170002C5 RID: 709
|
|
// (get) Token: 0x060010A8 RID: 4264 RVA: 0x000448CC File Offset: 0x00042ACC
|
|
public override int Count
|
|
{
|
|
get
|
|
{
|
|
Stack stack = this.stack;
|
|
int count;
|
|
lock (stack)
|
|
{
|
|
count = this.stack.Count;
|
|
}
|
|
return count;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170002C6 RID: 710
|
|
// (get) Token: 0x060010A9 RID: 4265 RVA: 0x00044920 File Offset: 0x00042B20
|
|
public override bool IsSynchronized
|
|
{
|
|
get
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170002C7 RID: 711
|
|
// (get) Token: 0x060010AA RID: 4266 RVA: 0x00044924 File Offset: 0x00042B24
|
|
public override object SyncRoot
|
|
{
|
|
get
|
|
{
|
|
return this.stack.SyncRoot;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060010AB RID: 4267 RVA: 0x00044934 File Offset: 0x00042B34
|
|
public override void Clear()
|
|
{
|
|
Stack stack = this.stack;
|
|
lock (stack)
|
|
{
|
|
this.stack.Clear();
|
|
}
|
|
}
|
|
|
|
// Token: 0x060010AC RID: 4268 RVA: 0x00044984 File Offset: 0x00042B84
|
|
public override object Clone()
|
|
{
|
|
Stack stack = this.stack;
|
|
object obj;
|
|
lock (stack)
|
|
{
|
|
obj = Stack.Synchronized((Stack)this.stack.Clone());
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
// Token: 0x060010AD RID: 4269 RVA: 0x000449E4 File Offset: 0x00042BE4
|
|
public override bool Contains(object obj)
|
|
{
|
|
Stack stack = this.stack;
|
|
bool flag;
|
|
lock (stack)
|
|
{
|
|
flag = this.stack.Contains(obj);
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x060010AE RID: 4270 RVA: 0x00044A3C File Offset: 0x00042C3C
|
|
public override void CopyTo(Array array, int index)
|
|
{
|
|
Stack stack = this.stack;
|
|
lock (stack)
|
|
{
|
|
this.stack.CopyTo(array, index);
|
|
}
|
|
}
|
|
|
|
// Token: 0x060010AF RID: 4271 RVA: 0x00044A8C File Offset: 0x00042C8C
|
|
public override IEnumerator GetEnumerator()
|
|
{
|
|
Stack stack = this.stack;
|
|
IEnumerator enumerator;
|
|
lock (stack)
|
|
{
|
|
enumerator = new Stack.Enumerator(this.stack);
|
|
}
|
|
return enumerator;
|
|
}
|
|
|
|
// Token: 0x060010B0 RID: 4272 RVA: 0x00044AE0 File Offset: 0x00042CE0
|
|
public override object Peek()
|
|
{
|
|
Stack stack = this.stack;
|
|
object obj;
|
|
lock (stack)
|
|
{
|
|
obj = this.stack.Peek();
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
// Token: 0x060010B1 RID: 4273 RVA: 0x00044B34 File Offset: 0x00042D34
|
|
public override object Pop()
|
|
{
|
|
Stack stack = this.stack;
|
|
object obj;
|
|
lock (stack)
|
|
{
|
|
obj = this.stack.Pop();
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
// Token: 0x060010B2 RID: 4274 RVA: 0x00044B88 File Offset: 0x00042D88
|
|
public override void Push(object obj)
|
|
{
|
|
Stack stack = this.stack;
|
|
lock (stack)
|
|
{
|
|
this.stack.Push(obj);
|
|
}
|
|
}
|
|
|
|
// Token: 0x060010B3 RID: 4275 RVA: 0x00044BD8 File Offset: 0x00042DD8
|
|
public override object[] ToArray()
|
|
{
|
|
Stack stack = this.stack;
|
|
object[] array;
|
|
lock (stack)
|
|
{
|
|
array = this.stack.ToArray();
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x04000408 RID: 1032
|
|
private Stack stack;
|
|
}
|
|
|
|
// Token: 0x02000144 RID: 324
|
|
private class Enumerator : IEnumerator, ICloneable
|
|
{
|
|
// Token: 0x060010B4 RID: 4276 RVA: 0x00044C2C File Offset: 0x00042E2C
|
|
internal Enumerator(Stack s)
|
|
{
|
|
this.stack = s;
|
|
this.modCount = s.modCount;
|
|
this.current = -2;
|
|
}
|
|
|
|
// Token: 0x060010B5 RID: 4277 RVA: 0x00044C50 File Offset: 0x00042E50
|
|
public object Clone()
|
|
{
|
|
return base.MemberwiseClone();
|
|
}
|
|
|
|
// Token: 0x170002C8 RID: 712
|
|
// (get) Token: 0x060010B6 RID: 4278 RVA: 0x00044C58 File Offset: 0x00042E58
|
|
public virtual object Current
|
|
{
|
|
get
|
|
{
|
|
if (this.modCount != this.stack.modCount || this.current == -2 || this.current == -1 || this.current > this.stack.count)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
return this.stack.contents[this.current];
|
|
}
|
|
}
|
|
|
|
// Token: 0x060010B7 RID: 4279 RVA: 0x00044CC4 File Offset: 0x00042EC4
|
|
public virtual bool MoveNext()
|
|
{
|
|
if (this.modCount != this.stack.modCount)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
int num = this.current;
|
|
if (num == -2)
|
|
{
|
|
this.current = this.stack.current;
|
|
return this.current != -1;
|
|
}
|
|
if (num != -1)
|
|
{
|
|
this.current--;
|
|
return this.current != -1;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Token: 0x060010B8 RID: 4280 RVA: 0x00044D44 File Offset: 0x00042F44
|
|
public virtual void Reset()
|
|
{
|
|
if (this.modCount != this.stack.modCount)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
this.current = -2;
|
|
}
|
|
|
|
// Token: 0x04000409 RID: 1033
|
|
private const int EOF = -1;
|
|
|
|
// Token: 0x0400040A RID: 1034
|
|
private const int BOF = -2;
|
|
|
|
// Token: 0x0400040B RID: 1035
|
|
private Stack stack;
|
|
|
|
// Token: 0x0400040C RID: 1036
|
|
private int modCount;
|
|
|
|
// Token: 0x0400040D RID: 1037
|
|
private int current;
|
|
}
|
|
}
|
|
}
|