-//
+//
// System.Collections.Queue
//
// Author:
-// Ricardo Fernández Pascual
+// Ricardo Fernández Pascual
//
-// (C) 2001 Ricardo Fernández Pascual
+// (C) 2001 Ricardo Fernández Pascual
//
//
using System;
using System.Collections;
+using System.Runtime.InteropServices;
namespace System.Collections {
+ [ComVisible(true)]
+ [System.Diagnostics.DebuggerDisplay ("Count={Count}")]
+ [System.Diagnostics.DebuggerTypeProxy (typeof (CollectionDebuggerView))]
[Serializable]
- public class Queue : ICollection, IEnumerable, ICloneable {
+#if INSIDE_CORLIB
+ public
+#else
+ internal
+#endif
+ class Queue : ICollection, IEnumerable, ICloneable {
private object[] _array;
private int _head = 0; // points to the first used slot
private int _version = 0;
public Queue () : this (32, 2.0F) {}
- public Queue (int initialCapacity) : this (initialCapacity, 2.0F) {}
+
+ public Queue (int capacity) : this (capacity, 2.0F) {}
+
public Queue(ICollection col) : this (col == null ? 32 : col.Count)
{
if (col == null)
throw new ArgumentNullException ("col");
- _size = _array.Length;
- _tail = _size;
- col.CopyTo (_array, 0);
+ // We have to do this because msft seems to call the
+ // enumerator rather than CopyTo. This affects classes
+ // like bitarray.
+ foreach (object o in col)
+ Enqueue (o);
}
- public Queue (int initialCapacity, float growFactor) {
- if (initialCapacity < 0)
+ public Queue (int capacity, float growFactor) {
+ if (capacity < 0)
throw new ArgumentOutOfRangeException("capacity", "Needs a non-negative number");
if (!(growFactor >= 1.0F && growFactor <= 10.0F))
throw new ArgumentOutOfRangeException("growFactor", "Queue growth factor must be between 1.0 and 10.0, inclusive");
- _array = new object[initialCapacity];
+ _array = new object[capacity];
this._growFactor = (int)(growFactor * 100);
}
CopyTo (trimmed, 0);
_array = trimmed;
_head = 0;
- _tail = _head + _size;
+ _tail = 0;
}
// private methods
private void grow () {
int newCapacity = (_array.Length * _growFactor) / 100;
+ if (newCapacity < _array.Length + 1)
+ newCapacity = _array.Length + 1;
object[] newContents = new object[newCapacity];
CopyTo (newContents, 0);
_array = newContents;