* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System / System.Collections.Generic / Queue.cs
index 854cd3e24f92383ff341778a3cc77468cd20b4a8..dee0b5f2469b59f9d88c83a8b6e7e0582706a48f 100644 (file)
@@ -38,23 +38,29 @@ using System.Runtime.InteropServices;
 namespace System.Collections.Generic
 {
        [ComVisible(false)]
-       public class Queue<T> : ICollection<T>, ICollection
+       [Serializable]
+       public class Queue<T> : IEnumerable <T>, ICollection, IEnumerable
        {
                T [] data;
                int head;
                int tail;
                int size;
                int version;
+               int defaultCapacity;
+
+               private readonly static int INITIAL_SIZE = 16;
                
                public Queue ()
                {
+                       defaultCapacity = INITIAL_SIZE;
                }
                
                public Queue (int count)
                {
                        if (count < 0)
                                throw new ArgumentOutOfRangeException ("count");
-                       
+
+                       defaultCapacity = count;
                        data = new T [count];
                }
                
@@ -63,8 +69,9 @@ namespace System.Collections.Generic
                        if (collection == null)
                                throw new ArgumentNullException ("collection");
                        
-                               foreach (T t in collection)
-                                       Enqueue (t);
+                       foreach (T t in collection)
+                               Enqueue (t);
+                       defaultCapacity = size;
                }
                
                public void Clear ()
@@ -186,10 +193,11 @@ namespace System.Collections.Generic
                        CopyTo (t, 0);
                        return t;
                }
-               
-               public void TrimToSize ()
+
+               public void TrimExcess ()
                {
-                       SetCapacity (size);
+                       if (data != null && (size < data.Length * 0.9))
+                               Array.Resize <T> (ref data, size == 0 ? defaultCapacity : size);
                }
                
                void SetCapacity (int new_size)
@@ -214,11 +222,6 @@ namespace System.Collections.Generic
                        get { return size; }
                }
                
-               
-               bool ICollection <T>.IsReadOnly {
-                       get { return false; }
-               }
-               
                bool ICollection.IsSynchronized {
                        get { return false; }
                }
@@ -227,17 +230,6 @@ namespace System.Collections.Generic
                        get { return this; }
                }
                
-               void ICollection <T>.Add (T t)
-               {
-                       Enqueue (t);
-               }
-               
-               bool ICollection <T>.Remove (T t)
-               {
-                       throw new InvalidOperationException ("");
-               }
-               
-
                public Enumerator GetEnumerator ()
                {
                        return new Enumerator (this);