diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 37245249..e551c098 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -115,6 +115,7 @@ jobs:
lib-nanoFramework.System.Math
lib-nanoFramework.TI.EasyLink
lib-nanoFramework.ResourceManager
+ lib-nanoFramework.System.Collections
Json.NetMF
condition: or( and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ), and( succeeded(), contains(variables['getCommitMessage.COMMIT_MESSAGE'], '***UPDATE_DEPENDENTS***') ), eq(variables['UPDATE_DEPENDENTS'], 'true') )
displayName: Update dependent class libs
diff --git a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj
index 588425c2..ca625534 100644
--- a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj
+++ b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj
@@ -64,17 +64,12 @@
-
-
-
-
-
diff --git a/source/nanoFramework.CoreLibrary/Friends.cs b/source/nanoFramework.CoreLibrary/Friends.cs
index d7254b75..e2692d89 100644
--- a/source/nanoFramework.CoreLibrary/Friends.cs
+++ b/source/nanoFramework.CoreLibrary/Friends.cs
@@ -7,3 +7,4 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Math, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("nanoFramework.ResourceManager, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")]
+[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("nanoFramework.System.Collections, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")]
diff --git a/source/nanoFramework.CoreLibrary/System/Array.cs b/source/nanoFramework.CoreLibrary/System/Array.cs
index f848a744..e8af1b53 100644
--- a/source/nanoFramework.CoreLibrary/System/Array.cs
+++ b/source/nanoFramework.CoreLibrary/System/Array.cs
@@ -158,6 +158,11 @@ extern Object IList.this[int index]
set;
}
+ internal void SetByIndex(int index, object value)
+ {
+ ((IList)this)[index] = value;
+ }
+
int IList.Add(Object value)
{
throw new NotSupportedException();
diff --git a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs
index ad149b7d..806a0916 100644
--- a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs
+++ b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs
@@ -14,4 +14,4 @@
[assembly: AssemblyProduct("nanoFramework mscorlib")]
[assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")]
-[assembly: AssemblyNativeVersion("100.4.1.0")]
+[assembly: AssemblyNativeVersion("100.4.3.0")]
diff --git a/source/nanoFramework.CoreLibrary/System/Collections/DictionaryEntry.cs b/source/nanoFramework.CoreLibrary/System/Collections/DictionaryEntry.cs
deleted file mode 100644
index e4c7a512..00000000
--- a/source/nanoFramework.CoreLibrary/System/Collections/DictionaryEntry.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-// Copyright (c) 2017 The nanoFramework project contributors
-// Portions Copyright (c) Microsoft Corporation. All rights reserved.
-// See LICENSE file in the project root for full license information.
-//
-
-namespace System.Collections
-{
- ///
- /// Defines a dictionary key/value pair that can be set or retrieved.
- ///
- public class DictionaryEntry
- {
- ///
- /// Gets or sets the key in the key/value pair.
- ///
- /// The key in the key/value pair.
- public Object Key;
- ///
- /// Gets or sets the value in the key/value pair.
- ///
- /// The value in the key/value pair.
- public Object Value;
-
- ///
- /// Initializes an instance of the DictionaryEntry type with the specified key and value.
- ///
- /// The object defined in each key/value pair.
- /// The definition associated with key.
- public DictionaryEntry(Object key, Object value)
- {
- Key = key;
- Value = value;
- }
- }
-}
diff --git a/source/nanoFramework.CoreLibrary/System/Collections/HashTable.cs b/source/nanoFramework.CoreLibrary/System/Collections/HashTable.cs
deleted file mode 100644
index 3ecd8200..00000000
--- a/source/nanoFramework.CoreLibrary/System/Collections/HashTable.cs
+++ /dev/null
@@ -1,673 +0,0 @@
-//
-// Copyright (c) 2017 The nanoFramework project contributors
-// Portions Copyright (c) Microsoft Corporation. All rights reserved.
-// See LICENSE file in the project root for full license information.
-//
-
-namespace System.Collections
-{
- ///
- /// HashTable is an Associative Container.
- /// Created in March 2010.
- /// by Eric Harlow.
- ///
- public class Hashtable : ICloneable, IDictionary
- {
- private Entry[] _buckets;
- private int _numberOfBuckets;
- private int _count;
- private int _loadFactor;
- private int _maxLoadFactor;
- private double _growthFactor;
- private const int _defaultCapacity = 4;
- private const int _defaultLoadFactor = 2;
-
- ///
- /// Initializes a new, empty instance of the Hashtable class using the default initial capacity and load factor.
- ///
- public Hashtable()
- {
- InitializeHashTable(_defaultCapacity, _defaultLoadFactor);
- }
-
- ///
- /// Initializes a new, empty instance of the Hashtable class using the specified initial capacity,
- /// and the default load factor.
- ///
- /// The initial capacity of the HashTable
- public Hashtable(int capacity)
- {
- InitializeHashTable(capacity, _defaultLoadFactor);
- }
-
- ///
- /// Initializes a new, empty instance of the Hashtable class using the specified initial capacity,
- /// load factor.
- ///
- /// The initial capacity of the HashTable
- /// The load factor to cause a rehash
- public Hashtable(int capacity, int maxLoadFactor)
- {
- InitializeHashTable(capacity, maxLoadFactor);
- }
-
- //initialize attributes
- private void InitializeHashTable(int capacity, int maxLoadFactor)
- {
- _buckets = new Entry[capacity];
- _numberOfBuckets = capacity;
- _maxLoadFactor = maxLoadFactor;
- _growthFactor = 2;
- }
-
-#pragma warning disable S2292 // Trivial properties should be auto-implemented
- ///
- /// MaxLoadFactor Property is the value used to trigger a rehash.
- /// Default value is 2.
- /// A higher number can decrease lookup performance for large collections.
- /// While a value of 1 maintains a constant time complexity at the cost of increased memory requirements.
- ///
- public int MaxLoadFactor
-#pragma warning restore S2292 // Trivial properties should be auto-implemented
- {
- get { return _maxLoadFactor; }
- set { _maxLoadFactor = value; }
- }
-
-#pragma warning disable S2292 // Trivial properties should be auto-implemented
- ///
- /// GrowthFactor Property is a multiplier to increase the HashTable size by during a rehash.
- /// Default value is 2.
- ///
- public double GrowthFactor
-#pragma warning restore S2292 // Trivial properties should be auto-implemented
- {
- get { return _growthFactor; }
- set { _growthFactor = value; }
- }
-
- //adding for internal purposes
- private void Add(ref Entry[] buckets, object key, object value, bool overwrite)
- {
- var whichBucket = Hash(key, _numberOfBuckets);
- var match = EntryForKey(key, buckets[whichBucket]);
-
- if (match != null && overwrite)
- {
- //i.e. already exists in table
- match.value = value;
- return;
- }
- else if ((match != null && !overwrite))
- {
- throw new ArgumentException("key exists");
- }
- else
- { // insert at front
- var newOne = new Entry(key, value, ref buckets[whichBucket]);
- buckets[whichBucket] = newOne;
- _count++;
- }
-
- _loadFactor = _count / _numberOfBuckets;
- }
-
- // Hash function.
- private int Hash(object key, int numOfBuckets)
- {
- var hashcode = key.GetHashCode();
-
- if (hashcode < 0)
- {
- // don't know how to mod with a negative number
- hashcode = hashcode * -1;
- }
-
- return hashcode % numOfBuckets;
- }
-
- //looks up value in bucket
- private Entry EntryForKey(object key, Entry head)
- {
- for (Entry cur = head; cur != null; cur = cur.next)
- {
- if (cur.key.Equals(key))
- {
- return cur;
- }
- }
-
- return null;
- }
-
- //Rehashes the table to reduce the load factor
- private void Rehash(int newSize)
- {
- Entry[] newTable = new Entry[newSize];
- _numberOfBuckets = newSize;
- _count = 0;
-
- for (var i = 0; i < _buckets.Length; i++)
- {
- if (_buckets[i] != null)
- {
- for (Entry cur = _buckets[i]; cur != null; cur = cur.next)
- {
- Add(ref newTable, cur.key, cur.value, false);
- }
- }
- }
-
- _buckets = newTable;
- }
-
- //implementation for KeyCollection and ValueCollection copyTo method
- private void CopyToCollection(Array array, int index, EnumeratorType type)
- {
- if (index < 0 && index > _numberOfBuckets)
- {
-#pragma warning disable S112 // General exceptions should never be thrown
- throw new IndexOutOfRangeException("index");
-#pragma warning restore S112 // General exceptions should never be thrown
- }
-
- for (int i = index; i < _numberOfBuckets; i++)
- {
- var j = 0;
-
- for (Entry cur = _buckets[i]; cur != null && j < array.Length; cur = cur.next)
- {
- if (type == EnumeratorType.KEY)
- {
- ((IList)array)[j] = cur.key;
- }
- else
- {
- ((IList)array)[j] = cur.value;
- }
-
- j++;
- }
- }
- }
-
- #region ICloneable Members
- ///
- /// Make a new object which is a copy of the object instanced.
- ///
- /// A new object that represents a clone of the object.
- public object Clone()
- {
- var ht = new Hashtable();
- ht.InitializeHashTable(_numberOfBuckets, _maxLoadFactor);
- ht._count = _count;
- ht._loadFactor = _loadFactor;
- Array.Copy(_buckets, ht._buckets, _numberOfBuckets);
- return ht;
- }
-
- #endregion ICloneable Members
-
- #region IEnumerable Members
-
- ///
- /// Returns an enumerator that iterates through a collection.
- ///
- /// An IEnumerator object that can be used to iterate through the collection.
- public IEnumerator GetEnumerator()
- {
- return new HashtableEnumerator(this, EnumeratorType.DE);
- }
-
- #endregion IEnumerable Members
-
- #region ICollection Members
-
- ///
- /// Gets the number of elements contained in the ICollection.
- ///
- ///
- /// The number of elements contained in the ICollection.
- ///
- public int Count
- {
- get { return _count; }
- }
-
- ///
- /// Gets a value indicating whether access to the ICollection is synchronized (thread safe).
- ///
- ///
- /// true if access to the ICollection is synchronized (thread safe); otherwise, false.
- ///
- public bool IsSynchronized
- {
- get { return false; }
- }
-
- ///
- /// Gets an object that can be used to synchronize access to the ICollection.
- ///
- ///
- /// An object that can be used to synchronize access to the ICollection.
- ///
- public object SyncRoot
- {
- get { return this; }
- }
-
- ///
- /// Copies the elements of the ICollection to an Array, starting at a particular Array index.
- ///
- /// The one-dimensional Array that is the destination of the elements copied from ICollection. The Array must have zero-based indexing.
- /// The zero-based index in array at which copying begins.
- public void CopyTo(Array array, int index)
- {
- if (index < 0 && index > _buckets.Length)
-#pragma warning disable S112 // General exceptions should never be thrown
- throw new IndexOutOfRangeException("index");
-#pragma warning restore S112 // General exceptions should never be thrown
-
- for (int i = index; i < _buckets.Length; i++)
- {
- var j = 0;
-
- for (Entry cur = _buckets[i]; cur != null && j < array.Length; cur = cur.next)
- {
- ((IList)array)[j] = new DictionaryEntry(cur.key, cur.value);
- j++;
- }
- }
- }
-
- #endregion ICollection Members
-
- #region IDictionary Members
-
- ///
- /// Gets a value indicating whether the IDictionary object is read-only.
- ///
- ///
- /// true if the IDictionary object is read-only; otherwise, false.
- ///
- public bool IsReadOnly
- {
- get { return false; }
- }
-
- ///
- /// Gets a value indicating whether the IDictionary object has a fixed size.
- ///
- ///
- /// true if the IDictionary object has a fixed size; otherwise, false.
- ///
- public bool IsFixedSize
- {
- get { return false; }
- }
-
- ///
- /// Gets an ICollection object containing the keys of the IDictionary object.
- ///
- ///
- /// An ICollection object containing the keys of the IDictionary object.
- ///
- public ICollection Keys
- {
- get
- {
- return new KeyCollection(this);
- }
- }
-
- ///
- /// Gets an ICollection object containing the values in the IDictionary object.
- ///
- ///
- /// An ICollection object containing the values in the IDictionary object.
- ///
- public ICollection Values
- {
- get
- {
- return new ValueCollection(this);
- }
- }
-
- ///
- /// Gets or sets the element with the specified key.
- ///
- /// The key of the element to get or set.
- /// The element with the specified key, or if the key does not exist.
- public object this[object key]
- {
- get
- {
- if (key == null)
- {
- throw new ArgumentNullException("key is null");
- }
-
- var whichBucket = Hash(key, _numberOfBuckets);
- var match = EntryForKey(key, _buckets[whichBucket]);
-
- if (match != null)
- {
- return match.value;
- }
-
- return null;
- }
- set
- {
- if (key == null)
- {
- throw new ArgumentNullException("key is null");
- }
-
- Add(ref _buckets ,key,value,true);
-
- if (_loadFactor >= _maxLoadFactor)
- {
- Rehash((int)(_numberOfBuckets * _growthFactor));
- }
- }
- }
-
- ///
- /// Adds an element with the provided key and value to the IDictionary object.
- ///
- /// The Object to use as the key of the element to add.
- /// The Object to use as the value of the element to add.
- public void Add(object key, object value)
- {
- if (key == null) throw new ArgumentNullException("key is null");
-
- Add(ref _buckets, key, value, false);
-
- if (_loadFactor >= _maxLoadFactor)
- {
- Rehash((int)(_numberOfBuckets * _growthFactor));
- }
- }
-
- ///
- /// Removes all elements from the IDictionary object.
- ///
- public void Clear()
- {
- _buckets = new Entry[_defaultCapacity];
- _numberOfBuckets = _defaultCapacity;
- _loadFactor = 0;
- _count = 0;
- }
-
- ///
- /// Determines whether the IDictionary object contains an element with the specified key.
- ///
- /// The key to locate in the IDictionary object.
- /// true if the IDictionary contains an element with the key; otherwise, false.
- public bool Contains(object key)
- {
- if (key == null)
- {
- throw new ArgumentNullException("key is null");
- }
-
- var whichBucket = Hash(key, _numberOfBuckets);
- var match = EntryForKey(key, _buckets[whichBucket]);
-
- if (match != null)
- {
- return true;
- }
-
- return false;
- }
-
- ///
- /// Removes the element with the specified key from the IDictionary object.
- ///
- /// The key of the element to remove.
- public void Remove(object key)
- {
- if (key == null)
- {
- throw new ArgumentNullException("key is null");
- }
-
- var whichBucket = Hash(key, _numberOfBuckets);
- var match = EntryForKey(key, _buckets[whichBucket]);
-
- //does entry exist?
- if (match == null)
- {
- return;
- }
-
- //is entry at front?
- if (_buckets[whichBucket] == match)
- {
- _buckets[whichBucket] = match.next;
- _count--;
- return;
- }
-
- //handle entry in middle and at the end
- for (Entry cur = _buckets[whichBucket]; cur != null; cur = cur.next)
- {
- if (cur.next == match)
- {
- cur.next = match.next;
- _count--;
- return;
- }
- }
- }
-
- #endregion IDictionary Members
-
- private class Entry
- {
- public Object key;
- public Object value;
- public Entry next;
-
- public Entry(object key, object value, ref Entry n)
- {
- this.key = key;
- this.value = value;
- next = n;
- }
- }
-
- private class HashtableEnumerator : IEnumerator
- {
- Hashtable ht;
- Entry temp;
- Int32 index = -1;
- EnumeratorType returnType;
-
- public HashtableEnumerator(Hashtable hashtable, EnumeratorType type)
- {
- ht = hashtable;
- returnType = type;
- }
-
- // Return the current item.
- public Object Current
- {
- get
- {
- switch (returnType)
- {
- case EnumeratorType.DE:
- return new DictionaryEntry(temp.key, temp.value);
-
- case EnumeratorType.KEY:
- return temp.key;
-
- case EnumeratorType.VALUE:
- return temp.value;
-
- default:
- break;
- }
- return new DictionaryEntry(temp.key, temp.value);
- }
- }
-
- // Advance to the next item.
- public Boolean MoveNext()
- {
- startLoop:
- //iterate index or list
- if (temp == null)
- {
- index++;
- if (index < ht._numberOfBuckets)
- {
- temp = ht._buckets[index];
- }
- else
- {
- return false;
- }
- }
- else
- {
- temp = temp.next;
- }
-
- //null check
- if (temp == null)
- {
- goto startLoop;
- }
-
- return true;
- }
-
- // Reset the index to restart the enumeration.
- public void Reset()
- {
- index = -1;
- }
- }
-
- // EnumeratorType - Enum that describes which object the Enumerator's Current property will return.
- private enum EnumeratorType
- {
- // DictionaryEntry object.
- DE,
- // Key object.
- KEY,
- // Value object.
- VALUE
- }
-
- private class KeyCollection : ICollection
- {
- Hashtable ht;
-
- public KeyCollection(Hashtable hashtable)
- {
- ht = hashtable;
- }
-
- #region ICollection Members
-
- public int Count
- {
- get
- {
- return ht._count;
- }
- }
-
- public bool IsSynchronized
- {
- get
- {
- return ht.IsSynchronized;
- }
- }
-
- public object SyncRoot
- {
- get
- {
- return ht.SyncRoot;
- }
- }
-
- public void CopyTo(Array array, int index)
- {
- ht.CopyToCollection(array, index, EnumeratorType.KEY);
- }
-
- #endregion
-
- #region IEnumerable Members
-
- public IEnumerator GetEnumerator()
- {
- return new HashtableEnumerator(ht, EnumeratorType.KEY);
- }
-
- #endregion
- }
-
- private class ValueCollection : ICollection
- {
- Hashtable ht;
-
- public ValueCollection(Hashtable hashtable)
- {
- ht = hashtable;
- }
-
- #region ICollection Members
-
- public int Count
- {
- get
- {
- return ht._count;
- }
- }
-
- public bool IsSynchronized
- {
- get
- {
- return ht.IsSynchronized;
- }
- }
-
- public object SyncRoot
- {
- get
- {
- return ht.SyncRoot;
- }
- }
-
- public void CopyTo(Array array, int index)
- {
- ht.CopyToCollection(array, index, EnumeratorType.VALUE);
- }
-
- #endregion
-
- #region IEnumerable Members
-
- public IEnumerator GetEnumerator()
- {
- return new HashtableEnumerator(ht, EnumeratorType.VALUE);
- }
-
- #endregion
- }
- }
-}
diff --git a/source/nanoFramework.CoreLibrary/System/Collections/IDictionary.cs b/source/nanoFramework.CoreLibrary/System/Collections/IDictionary.cs
deleted file mode 100644
index 6ff611b8..00000000
--- a/source/nanoFramework.CoreLibrary/System/Collections/IDictionary.cs
+++ /dev/null
@@ -1,75 +0,0 @@
-//
-// Copyright (c) 2017 The nanoFramework project contributors
-// Portions Copyright (c) Microsoft Corporation. All rights reserved.
-// See LICENSE file in the project root for full license information.
-//
-
-namespace System.Collections
-{
- ///
- /// Represents a nongeneric collection of key/value pairs.
- ///
- public interface IDictionary : ICollection
- {
- ///
- /// Gets a value indicating whether the IDictionary object is read-only.
- ///
- ///
- /// true if the IDictionary object is read-only; otherwise, false.
- ///
- bool IsReadOnly { get; }
- ///
- /// Gets a value indicating whether the IDictionary object has a fixed size.
- ///
- ///
- /// true if the IDictionary object has a fixed size; otherwise, false.
- ///
- bool IsFixedSize { get; }
- ///
- /// Gets an ICollection object containing the keys of the IDictionary object.
- ///
- ///
- /// An ICollection object containing the keys of the IDictionary object.
- ///
- ICollection Keys { get; }
- ///
- /// Gets an ICollection object containing the values in the IDictionary object.
- ///
- ///
- /// An ICollection object containing the values in the IDictionary object.
- ///
- ICollection Values { get; }
-
- ///
- /// Gets or sets the element with the specified key.
- ///
- /// The key of the element to get or set.
- /// The element with the specified key, or if the key does not exist.
- object this[object key] { get; set; }
-
- ///
- /// Adds an element with the provided key and value to the IDictionary object.
- ///
- /// The Object to use as the key of the element to add.
- /// The Object to use as the value of the element to add.
- void Add(object key, object value);
-
- ///
- /// Removes all elements from the IDictionary object.
- ///
- void Clear();
-
- ///
- /// Determines whether the IDictionary object contains an element with the specified key.
- ///
- /// The key to locate in the IDictionary object.
- /// true if the IDictionary contains an element with the key; otherwise, false.
- bool Contains(object key);
-
- ///
- /// Removes the element with the specified key from the IDictionary object.
- ///
- /// The key of the element to remove.
- void Remove(object key);
- }
-}
diff --git a/source/nanoFramework.CoreLibrary/System/Collections/IList.cs b/source/nanoFramework.CoreLibrary/System/Collections/IList.cs
index 973d2b93..2ddafb83 100644
--- a/source/nanoFramework.CoreLibrary/System/Collections/IList.cs
+++ b/source/nanoFramework.CoreLibrary/System/Collections/IList.cs
@@ -21,7 +21,7 @@ public interface IList : ICollection
///
/// The zero-based index of the element to get or set.
/// The element at the specified index.
- Object this[int index]
+ object this[int index]
{
get;
set;
diff --git a/source/nanoFramework.CoreLibrary/System/Collections/Queue.cs b/source/nanoFramework.CoreLibrary/System/Collections/Queue.cs
deleted file mode 100644
index b47348a9..00000000
--- a/source/nanoFramework.CoreLibrary/System/Collections/Queue.cs
+++ /dev/null
@@ -1,179 +0,0 @@
-//
-// Copyright (c) 2017 The nanoFramework project contributors
-// Portions Copyright (c) Microsoft Corporation. All rights reserved.
-// See LICENSE file in the project root for full license information.
-//
-
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Collections
-{
- ///
- /// A circular-array implementation of a queue. Enqueue can be O(n). Dequeue is O(1).
- ///
-#if NANOCLR_REFLECTION
- [DebuggerDisplay("Count = {Count}")]
-#endif // NANOCLR_REFLECTION
- [Serializable]
- public class Queue : ICollection, ICloneable
- {
- private Object[] _array;
- private int _head; // First valid element in the queue
- private int _tail; // Last valid element in the queue
- private int _size; // Number of elements.
-
- // Keep in-sync with c_DefaultCapacity in CLR_RT_HeapBlock_Queue in NANOCLR_Runtime__HeapBlock.h
- private const int DefaultCapacity = 4;
-
- ///
- /// Initializes a new instance of the Queue class that is empty, has the default initial
- /// capacity, and uses the default growth factor (2x).
- ///
- public Queue()
- {
- _array = new Object[DefaultCapacity];
- _head = 0;
- _tail = 0;
- _size = 0;
- }
-
- ///
- /// Gets the number of elements contained in the Queue.
- ///
- public virtual int Count
- {
- get { return _size; }
- }
-
- ///
- /// Creates a shallow copy of the Queue.
- ///
- /// A shallow copy of the Queue.
- public virtual Object Clone()
- {
- var q = new Queue();
-
- if (_size > DefaultCapacity)
- {
- // only re-allocate a new array if the size isn't what we need.
- // otherwise, the one allocated in the constructor will be just fine
- q._array = new Object[_size];
- }
- else
- {
- // if size is not the same as capacity, we need to adjust tail accordingly
- q._tail = _size % DefaultCapacity;
- }
-
- q._size = _size;
-
- CopyTo(q._array, 0);
-
- return q;
- }
-
- ///
- /// Gets a value indicating whether access to the Queue is synchronized (thread safe).
- /// Always return false.
- ///
- public virtual bool IsSynchronized
- {
- get { return false; }
- }
-
- ///
- /// Gets an object that can be used to synchronize access to the Queue.
- ///
- public virtual Object SyncRoot
- {
- get { return this; }
- }
-
- ///
- /// Removes all objects from the Queue.
- ///
- [MethodImpl(MethodImplOptions.InternalCall)]
-#pragma warning disable S4200 // Native methods should be wrapped
- public virtual extern void Clear();
-#pragma warning restore S4200 // Native methods should be wrapped
-
- ///
- /// Copies the Queue elements to an existing one-dimensional Array, starting at
- /// the specified array index.
- ///
- /// The one-dimensional Array that is the destination of the elements copied from Queue.
- /// The zero-based index in array at which copying begins.
- [MethodImpl(MethodImplOptions.InternalCall)]
-#pragma warning disable S4200 // Native methods should be wrapped
- public virtual extern void CopyTo(Array array, int index);
-#pragma warning restore S4200 // Native methods should be wrapped
-
- ///
- /// Adds an object to the end of the Queue.
- ///
- /// The object to add to the Queue.
- [MethodImpl(MethodImplOptions.InternalCall)]
-#pragma warning disable S4200 // Native methods should be wrapped
- public virtual extern void Enqueue(Object obj);
-#pragma warning restore S4200 // Native methods should be wrapped
-
- ///
- /// Returns an enumerator that iterates through the Queue.
- ///
- /// An IEnumerator for the Queue.
- public virtual IEnumerator GetEnumerator()
- {
- var endIndex = _tail;
-
- if (_size > 0 && _tail <= _head) endIndex += _array.Length;
-
- return new Array.SzArrayEnumerator(_array, _head, endIndex);
- }
-
- ///
- /// Removes and returns the object at the beginning of the Queue.
- ///
- /// The object that is removed from the beginning of the Queue.
- [MethodImpl(MethodImplOptions.InternalCall)]
-#pragma warning disable S4200 // Native methods should be wrapped
- public virtual extern Object Dequeue();
-#pragma warning restore S4200 // Native methods should be wrapped
-
- ///
- /// Returns the object at the beginning of the Queue without removing it.
- ///
- /// The object at the beginning of the Queue.
- [MethodImpl(MethodImplOptions.InternalCall)]
-#pragma warning disable S4200 // Native methods should be wrapped
- public virtual extern Object Peek();
-#pragma warning restore S4200 // Native methods should be wrapped
-
- ///
- /// Determines whether an element is in the Queue.
- ///
- /// The Object to locate in the Queue.
- /// true if obj is found in the Queue; otherwise, false.
- public virtual bool Contains(Object obj)
- {
- if (_size == 0) return false;
- if (_head < _tail) return Array.IndexOf(_array, obj, _head, _size) >= 0;
- return Array.IndexOf(_array, obj, _head, _array.Length - _head) >= 0 || Array.IndexOf(_array, obj, 0, _tail) >= 0;
- }
-
- ///
- /// Copies the Queue elements to a new array. The order of the elements in the new
- /// array is the same as the order of the elements from the beginning of the Queue
- /// to its end.
- ///
- /// A new array containing elements copied from the Queue.
- public virtual Object[] ToArray()
- {
- var arr = new Object[_size];
-
- CopyTo(arr, 0);
-
- return arr;
- }
- }
-}
diff --git a/source/nanoFramework.CoreLibrary/System/Collections/stack.cs b/source/nanoFramework.CoreLibrary/System/Collections/stack.cs
deleted file mode 100644
index dd80349b..00000000
--- a/source/nanoFramework.CoreLibrary/System/Collections/stack.cs
+++ /dev/null
@@ -1,160 +0,0 @@
-//
-// Copyright (c) 2017 The nanoFramework project contributors
-// Portions Copyright (c) Microsoft Corporation. All rights reserved.
-// See LICENSE file in the project root for full license information.
-//
-
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Collections
-{
- ///
- /// An array implementation of a stack. Push can be O(n). Pop is O(1).
- ///
- [Serializable]
-#if NANOCLR_REFLECTION
- [DebuggerDisplay("Count = {Count}")]
-#endif // NANOCLR_REFLECTION
- public class Stack : ICollection, ICloneable
- {
- private Object[] _array; // Storage for stack elements
- private int _size; // Number of items in the stack.
-
- // Keep in-sync with c_DefaultCapacity in CLR_RT_HeapBlock_Stack in NANOCLR_Runtime__HeapBlock.h
- private const int DefaultCapacity = 4;
-
- ///
- /// Initializes a new instance of the Stack class that is empty and has the default initial capacity.
- ///
- public Stack()
- {
- _array = new Object[DefaultCapacity];
- _size = 0;
- }
-
- ///
- /// Size of the stack
- ///
- public virtual int Count
- {
- get { return _size; }
- }
-
- ///
- /// Returns whether the current stack is synchornized. Always return false.
- ///
- public virtual bool IsSynchronized
- {
- get { return false; }
- }
-
- ///
- /// Gets an object that can be used to synchronize access to the Stack.
- ///
- public virtual Object SyncRoot
- {
- get { return this; }
- }
-
- ///
- /// Removes all Objects from the Stack.
- ///
- [MethodImpl(MethodImplOptions.InternalCall)]
-#pragma warning disable S4200 // Native methods should be wrapped
- public virtual extern void Clear();
-#pragma warning restore S4200 // Native methods should be wrapped
-
- ///
- /// Creates a shallow copy of the Stack.
- ///
- /// A shallow copy of the Stack.
- public virtual Object Clone()
- {
- var stack = new Stack();
- var capacity = DefaultCapacity;
-
- if (_size > DefaultCapacity)
- {
- // only re-allocate a new array if the size isn't what we need.
- // otherwise, the one allocated in the constructor will be just fine
- stack._array = new Object[_size];
- capacity = _size;
- }
-
- stack._size = _size;
- Array.Copy(_array, _array.Length - _size, stack._array, capacity - _size, _size);
- return stack;
- }
-
- ///
- /// Determines whether an element is in the Stack.
- ///
- /// The Object to locate in the Stack.
- /// true, if obj is found in the Stack; otherwise, false
- public virtual bool Contains(Object obj)
- {
- return Array.IndexOf(_array, obj, _array.Length - _size, _size) >= 0;
- }
-
- ///
- /// Copies the Stack to an existing one-dimensional Array, starting at the specified array index.
- ///
- /// The one-dimensional Array that is the destination of the elements copied from Stack.
- /// The zero-based index in array at which copying begins.
- public virtual void CopyTo(Array array, int index)
- {
- Array.Copy(_array, _array.Length - _size, array, index, _size);
- }
-
- ///
- /// Returns an IEnumerator for this Stack.
- ///
- /// An IEnumerator for the Stack.
- public virtual IEnumerator GetEnumerator()
- {
- var capacity = _array.Length;
- return new Array.SzArrayEnumerator(_array, capacity - _size, capacity);
- }
-
- ///
- /// Returns the object at the top of the Stack without removing it.
- ///
- /// The Object at the top of the Stack.
- [MethodImpl(MethodImplOptions.InternalCall)]
-#pragma warning disable S4200 // Native methods should be wrapped
- public virtual extern Object Peek();
-#pragma warning restore S4200 // Native methods should be wrapped
-
- ///
- /// Removes and returns the object at the top of the Stack.
- ///
- /// The Object removed from the top of the Stack.
- [MethodImpl(MethodImplOptions.InternalCall)]
-#pragma warning disable S4200 // Native methods should be wrapped
- public virtual extern Object Pop();
-#pragma warning restore S4200 // Native methods should be wrapped
-
- ///
- /// Inserts an object at the top of the Stack.
- ///
- /// The Object to push onto the Stack.
- [MethodImpl(MethodImplOptions.InternalCall)]
-#pragma warning disable S4200 // Native methods should be wrapped
- public virtual extern void Push(Object obj);
-#pragma warning restore S4200 // Native methods should be wrapped
-
- ///
- /// Copies the Stack to a new array, in the same order Pop would return the items.
- ///
- /// A new array containing copies of the elements of the Stack.
- public virtual Object[] ToArray()
- {
- var objArray = new Object[_size];
-
- Array.Copy(_array, _array.Length - _size, objArray, 0, _size);
-
- return objArray;
- }
- }
-}
diff --git a/source/version.json b/source/version.json
index 1dc1ace5..2b9d5950 100644
--- a/source/version.json
+++ b/source/version.json
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
- "version": "1.4.1-preview.{height}",
+ "version": "1.5.0-preview.{height}",
"assemblyVersion": {
"precision": "revision"
},