10 [DebuggerTypeProxy(typeof(QueueDebugView))]
11 [DebuggerDisplay(
"Count = {Count}")]
16 private class SynchronizedQueue :
Queue 24 public override object SyncRoot => root;
26 public override int Count 37 internal SynchronizedQueue(
Queue q)
43 public override void Clear()
51 public override object Clone()
55 return new SynchronizedQueue((
Queue)_q.
Clone());
59 public override bool Contains(
object obj)
67 public override void CopyTo(
Array array,
int arrayIndex)
71 _q.
CopyTo(array, arrayIndex);
75 public override void Enqueue(
object value)
83 public override object Dequeue()
99 public override object Peek()
107 public override object[]
ToArray()
131 private int _version;
133 private object currentElement;
135 public virtual object Current
139 if (currentElement == _q._array)
147 return currentElement;
151 internal QueueEnumerator(
Queue q)
154 _version = _q._version;
156 currentElement = _q._array;
163 public object Clone()
165 return MemberwiseClone();
168 public virtual bool MoveNext()
170 if (_version != _q._version)
176 currentElement = _q._array;
179 currentElement = _q.GetElement(_index);
181 if (_index == _q._size)
188 public virtual void Reset()
190 if (_version != _q._version)
202 currentElement = _q._array;
206 internal class QueueDebugView
211 public object[] Items
215 return queue.ToArray();
219 public QueueDebugView(
Queue queue)
229 private object[] _array;
237 private int _growFactor;
239 private int _version;
242 private object _syncRoot;
244 private const int _MinimumGrow = 4;
246 private const int _ShrinkThreshold = 32;
263 if (_syncRoot ==
null)
292 public Queue(
int capacity,
float growFactor)
298 if (!((
double)growFactor >= 1.0) || !((double)growFactor <= 10.0))
302 _array =
new object[capacity];
306 _growFactor = (int)(growFactor * 100f);
314 : this(col?.
Count ?? 32)
334 int num = (_array.Length - _head < size) ? (_array.Length - _head) : size;
335 Array.
Copy(_array, _head, queue._array, 0, num);
339 Array.
Copy(_array, 0, queue._array, _array.Length - _head, size);
341 queue._version = _version;
354 Array.
Clear(_array, _head, _array.Length - _head);
387 int length = array.Length;
388 if (length - index < _size)
395 int num = (_array.Length - _head < size) ? (_array.Length - _head) : size;
396 Array.
Copy(_array, _head, array, index, num);
400 Array.
Copy(_array, 0, array, index + _array.Length - _head, size);
409 if (_size == _array.Length)
411 int num = (int)((
long)_array.Length * (long)_growFactor / 100);
412 if (num < _array.Length + 4)
414 num = _array.Length + 4;
419 _tail = (_tail + 1) % _array.Length;
428 return new QueueEnumerator(
this);
440 object result = _array[_head];
441 _array[_head] =
null;
442 _head = (_head + 1) % _array.Length;
457 return _array[_head];
465 [HostProtection(
SecurityAction.LinkDemand, Synchronization =
true)]
472 return new SynchronizedQueue(queue);
487 if (_array[num] ==
null)
492 else if (_array[num] !=
null && _array[num].Equals(obj))
496 num = (num + 1) % _array.Length;
501 internal object GetElement(
int i)
503 return _array[(_head + i) % _array.Length];
510 object[] array =
new object[_size];
517 Array.
Copy(_array, _head, array, 0, _size);
521 Array.
Copy(_array, _head, array, 0, _array.Length - _head);
522 Array.
Copy(_array, 0, array, _array.Length - _head, _tail);
527 private void SetCapacity(
int capacity)
529 object[] array =
new object[capacity];
534 Array.
Copy(_array, _head, array, 0, _size);
538 Array.
Copy(_array, _head, array, 0, _array.Length - _head);
539 Array.
Copy(_array, 0, array, _array.Length - _head, _tail);
544 _tail = ((_size != capacity) ? _size : 0);
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
bool MoveNext()
Advances the enumerator to the next element of the collection.
virtual void Clear()
Removes all objects from the T:System.Collections.Queue.
static void Clear(Array array, int index, int length)
Sets a range of elements in an array to the default value of each element type.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
virtual object Clone()
Creates a shallow copy of the T:System.Collections.Queue.
virtual object Peek()
Returns the object at the beginning of the T:System.Collections.Queue without removing it.
virtual void Enqueue(object obj)
Adds an object to the end of the T:System.Collections.Queue.
virtual object [] ToArray()
Copies the T:System.Collections.Queue elements to a new array.
Queue(int capacity, float growFactor)
Initializes a new instance of the T:System.Collections.Queue class that is empty, has the specified i...
virtual bool Contains(object obj)
Determines whether an element is in the T:System.Collections.Queue.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Provides information about, and means to manipulate, the current environment and platform....
static Queue Synchronized(Queue queue)
Returns a new T:System.Collections.Queue that wraps the original queue, and is thread safe.
virtual int Count
Gets the number of elements contained in the T:System.Collections.Queue.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
object Current
Gets the element in the collection at the current position of the enumerator.
virtual IEnumerator GetEnumerator()
Returns an enumerator that iterates through the T:System.Collections.Queue.
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Represents a first-in, first-out collection of objects.
virtual object SyncRoot
Gets an object that can be used to synchronize access to the T:System.Collections....
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
The exception that is thrown when one of the arguments provided to a method is not valid.
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
virtual void CopyTo(Array array, int index)
Copies the T:System.Collections.Queue elements to an existing one-dimensional T:System....
virtual bool IsSynchronized
Gets a value indicating whether access to the T:System.Collections.Queue is synchronized (thread safe...
Specifies that the class can be serialized.
The exception that is thrown when a method call is invalid for the object's current state.
Queue()
Initializes a new instance of the T:System.Collections.Queue class that is empty, has the default ini...
Defines size, enumerators, and synchronization methods for all nongeneric collections.
virtual void TrimToSize()
Sets the capacity to the actual number of elements in the T:System.Collections.Queue.
virtual object Dequeue()
Removes and returns the object at the beginning of the T:System.Collections.Queue.
DebuggerBrowsableState
Provides display instructions for the debugger.
Provides atomic operations for variables that are shared by multiple threads.
Supports a simple iteration over a non-generic collection.
Queue(int capacity)
Initializes a new instance of the T:System.Collections.Queue class that is empty, has the specified i...