diff --git a/archived_projects/src/System.Collections.Generic.MultiValueDictionary/System.Collections.Generic.MultiValueDictionary.csproj b/archived_projects/src/System.Collections.Generic.MultiValueDictionary/System.Collections.Generic.MultiValueDictionary.csproj
deleted file mode 100644
index 5246381ba5c..00000000000
--- a/archived_projects/src/System.Collections.Generic.MultiValueDictionary/System.Collections.Generic.MultiValueDictionary.csproj
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
- Dictionary allowing multiple values per key
- netstandard1.1
- .NET Core MultiValueDictionary MultiDictionary Dictionary corefxlab
-
-
-
-
- Properties.Resources
-
-
-
diff --git a/archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/Performance/Perf.MVD.cs b/archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/Performance/Perf.MVD.cs
deleted file mode 100644
index 64bfec7f9cf..00000000000
--- a/archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/Performance/Perf.MVD.cs
+++ /dev/null
@@ -1,263 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Collections.Generic;
-using Xunit;
-using Microsoft.Xunit.Performance;
-
-namespace System.Collections.Tests
-{
- public class Perf_MVD
- {
- public static MultiValueDictionary CreateMVD(int size)
- {
- MultiValueDictionary mvd = new MultiValueDictionary();
- Random rand = new Random(11231992);
-
- while (mvd.Count < size)
- mvd.Add(rand.Next(), rand.Next());
-
- return mvd;
- }
-
- [Benchmark]
- [InlineData(1000)]
- [InlineData(10000)]
- [InlineData(100000)]
- public void Add(int size)
- {
- MultiValueDictionary dict = CreateMVD(size);
- foreach (var iteration in Benchmark.Iterations)
- {
- MultiValueDictionary copyDict = new MultiValueDictionary(dict);
- using (iteration.StartMeasurement())
- for (int i = 0; i <= 20000; i++)
- {
- copyDict.Add(i * 10 + 1, 0); copyDict.Add(i * 10 + 2, 0); copyDict.Add(i * 10 + 3, 0);
- copyDict.Add(i * 10 + 4, 0); copyDict.Add(i * 10 + 5, 0); copyDict.Add(i * 10 + 6, 0);
- copyDict.Add(i * 10 + 7, 0); copyDict.Add(i * 10 + 8, 0); copyDict.Add(i * 10 + 9, 0);
- }
- }
- }
-
- [Benchmark]
- [InlineData(1000)]
- [InlineData(10000)]
- [InlineData(100000)]
- public void AddRange(int size)
- {
- List values = new List();
- for (int i = 0; i < size; i++)
- values.Add(i);
-
- foreach (var iteration in Benchmark.Iterations)
- {
- MultiValueDictionary empty = new MultiValueDictionary();
- using (iteration.StartMeasurement())
- for (int i = 0; i <= 20000; i++)
- empty.AddRange(i, values);
- }
- }
-
- [Benchmark]
- [InlineData(1000)]
- [InlineData(10000)]
- [InlineData(100000)]
- public void Remove(int size)
- {
- MultiValueDictionary dict = new MultiValueDictionary();
- for (int i = 0; i < size; i++)
- for (int j = 0; j < 100; j++)
- dict.Add(i, j);
-
- foreach (var iteration in Benchmark.Iterations)
- {
- MultiValueDictionary copyDict = new MultiValueDictionary(dict);
- using (iteration.StartMeasurement())
- for (int i = 0; i <= size; i++)
- {
- copyDict.Remove(i);
- }
- }
- }
-
- [Benchmark]
- [InlineData(1000)]
- [InlineData(10000)]
- [InlineData(100000)]
- public void RemoveItem(int size)
- {
- MultiValueDictionary dict = new MultiValueDictionary();
- for (int i = 0; i < size; i++)
- for (int j = 0; j < 100; j++)
- dict.Add(i, j);
-
- foreach (var iteration in Benchmark.Iterations)
- {
- MultiValueDictionary copyDict = new MultiValueDictionary(dict);
- using (iteration.StartMeasurement())
- for (int i = 0; i <= size; i++)
- for (int j = 0; j <= 100; j++)
- copyDict.RemoveItem(i, j);
- }
- }
-
- [Benchmark]
- [InlineData(1000)]
- [InlineData(10000)]
- [InlineData(100000)]
- public void Clear(int size)
- {
- MultiValueDictionary dict = CreateMVD(size);
- foreach (var iteration in Benchmark.Iterations)
- {
- MultiValueDictionary copyDict = new MultiValueDictionary(dict);
- using (iteration.StartMeasurement())
- copyDict.Clear();
- }
- }
-
- [Benchmark]
- public void ctor()
- {
- foreach (var iteration in Benchmark.Iterations)
- using (iteration.StartMeasurement())
- for (int i = 0; i <= 20000; i++)
- {
- new MultiValueDictionary(); new MultiValueDictionary(); new MultiValueDictionary();
- new MultiValueDictionary(); new MultiValueDictionary(); new MultiValueDictionary();
- new MultiValueDictionary(); new MultiValueDictionary(); new MultiValueDictionary();
- }
- }
-
- [Benchmark]
- [InlineData(0)]
- [InlineData(1024)]
- [InlineData(4096)]
- [InlineData(16384)]
- public void ctor_int(int size)
- {
- foreach (var iteration in Benchmark.Iterations)
- using (iteration.StartMeasurement())
- for (int i = 0; i <= 500; i++)
- {
- new MultiValueDictionary(size); new MultiValueDictionary(size); new MultiValueDictionary(size);
- new MultiValueDictionary(size); new MultiValueDictionary(size); new MultiValueDictionary(size);
- new MultiValueDictionary(size); new MultiValueDictionary(size); new MultiValueDictionary(size);
- }
- }
-
- [Benchmark]
- [InlineData(1000)]
- [InlineData(10000)]
- [InlineData(100000)]
- public void GetItem(int size)
- {
- MultiValueDictionary dict = CreateMVD(size);
-
- // Setup
- IReadOnlyCollection retrieved;
- for (int i = 1; i <= 9; i++)
- dict.Add(i, 0);
-
- // Actual perf testing
- foreach (var iteration in Benchmark.Iterations)
- {
- using (iteration.StartMeasurement())
- for (int i = 0; i <= 10000; i++)
- {
- retrieved = dict[1]; retrieved = dict[2]; retrieved = dict[3];
- retrieved = dict[4]; retrieved = dict[5]; retrieved = dict[6];
- retrieved = dict[7]; retrieved = dict[8]; retrieved = dict[9];
- }
- }
- }
-
- [Benchmark]
- [InlineData(1000)]
- [InlineData(10000)]
- [InlineData(100000)]
- public void GetKeys(int size)
- {
- MultiValueDictionary dict = CreateMVD(size);
- IEnumerable result;
- foreach (var iteration in Benchmark.Iterations)
- using (iteration.StartMeasurement())
- for (int i = 0; i <= 20000; i++)
- {
- result = dict.Keys; result = dict.Keys; result = dict.Keys;
- result = dict.Keys; result = dict.Keys; result = dict.Keys;
- result = dict.Keys; result = dict.Keys; result = dict.Keys;
- }
- }
-
- [Benchmark]
- [InlineData(1000)]
- [InlineData(10000)]
- [InlineData(100000)]
- public void TryGetValue(int size)
- {
- MultiValueDictionary dict = CreateMVD(size);
- // Setup
- IReadOnlyCollection retrieved;
- Random rand = new Random(837322);
- int key = rand.Next(0, 400000);
- dict.Add(key, 12);
-
- // Actual perf testing
- foreach (var iteration in Benchmark.Iterations)
- using (iteration.StartMeasurement())
- for (int i = 0; i <= 1000; i++)
- {
- dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved);
- dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved);
- dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved);
- dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved);
- }
- }
-
- [Benchmark]
- [InlineData(1000)]
- [InlineData(10000)]
- [InlineData(100000)]
- public void ContainsKey(int size)
- {
- MultiValueDictionary dict = CreateMVD(size);
-
- // Setup
- Random rand = new Random(837322);
- int key = rand.Next(0, 400000);
- dict.Add(key, 12);
-
- // Actual perf testing
- foreach (var iteration in Benchmark.Iterations)
- using (iteration.StartMeasurement())
- for (int i = 0; i <= 10000; i++)
- {
- dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key);
- dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key);
- dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key);
- dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key);
- }
- }
-
- [Benchmark]
- [InlineData(1000)]
- [InlineData(10000)]
- [InlineData(100000)]
- public void ContainsValue(int size)
- {
- MultiValueDictionary dict = CreateMVD(size);
- foreach (var iteration in Benchmark.Iterations)
- {
- using (iteration.StartMeasurement())
- for (int i = 0; i <= 20000; i++)
- {
- dict.ContainsValue(i); dict.ContainsValue(i); dict.ContainsValue(i);
- dict.ContainsValue(i); dict.ContainsValue(i); dict.ContainsValue(i);
- dict.ContainsValue(i); dict.ContainsValue(i); dict.ContainsValue(i);
- }
- }
- }
- }
-}
diff --git a/corefxlab.sln b/corefxlab.sln
index 8e3729339e8..97faaf35723 100644
--- a/corefxlab.sln
+++ b/corefxlab.sln
@@ -102,6 +102,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Reflection.TypeLoade
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Reflection.TypeLoader.Tests", "tests\System.Reflection.TypeLoader.Tests\System.Reflection.TypeLoader.Tests.csproj", "{70873943-22E2-4254-9CE6-A0186586DCEC}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Experimental.Collections", "src\Microsoft.Experimental.Collections\Microsoft.Experimental.Collections.csproj", "{25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Experimental.Collections.Tests", "tests\Microsoft.Experimental.Collections.Tests\Microsoft.Experimental.Collections.Tests.csproj", "{71D6F42F-95F7-486D-A659-22503A6D3D46}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -640,6 +644,30 @@ Global
{70873943-22E2-4254-9CE6-A0186586DCEC}.Release|x64.Build.0 = Release|Any CPU
{70873943-22E2-4254-9CE6-A0186586DCEC}.Release|x86.ActiveCfg = Release|Any CPU
{70873943-22E2-4254-9CE6-A0186586DCEC}.Release|x86.Build.0 = Release|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Debug|x64.Build.0 = Debug|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Debug|x86.Build.0 = Debug|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Release|x64.ActiveCfg = Release|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Release|x64.Build.0 = Release|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Release|x86.ActiveCfg = Release|Any CPU
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE}.Release|x86.Build.0 = Release|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Debug|x64.Build.0 = Debug|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Debug|x86.Build.0 = Debug|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Release|Any CPU.Build.0 = Release|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Release|x64.ActiveCfg = Release|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Release|x64.Build.0 = Release|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Release|x86.ActiveCfg = Release|Any CPU
+ {71D6F42F-95F7-486D-A659-22503A6D3D46}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -689,6 +717,8 @@ Global
{969CE69E-159D-44BF-9331-53D94B5C990F} = {E1DE693E-C1FB-4A1F-B6D8-A071D86D7354}
{14CA043D-613F-4145-9276-E6116B2B4465} = {4B000021-5278-4F2A-B734-DE49F55D4024}
{70873943-22E2-4254-9CE6-A0186586DCEC} = {3079E458-D0E6-4F99-8CAB-80011D35C7DA}
+ {25E150ED-EAE6-4EB0-BA94-2FE25826EEDE} = {4B000021-5278-4F2A-B734-DE49F55D4024}
+ {71D6F42F-95F7-486D-A659-22503A6D3D46} = {3079E458-D0E6-4F99-8CAB-80011D35C7DA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9DD4022C-A010-4A9B-BCC5-171566D4CB17}
diff --git a/scripts/package.ps1 b/scripts/package.ps1
index 0496bff547a..1e9d01a8e4f 100644
--- a/scripts/package.ps1
+++ b/scripts/package.ps1
@@ -10,6 +10,7 @@ $nugetPath = "$repoRoot\nuget\nuget.exe"
$packagesPath = "$repoRoot\packages"
$env:DOTNET_MULTILEVEL_LOOKUP = 0
+$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
Function Ensure-Nuget-Exists {
if (!(Test-Path "$nugetPath")) {
@@ -22,7 +23,13 @@ Function Ensure-Nuget-Exists {
}
Write-Host "** Building all NuGet packages. **"
-foreach ($file in [System.IO.Directory]::EnumerateFiles("$repoRoot\src", "System*.csproj", "AllDirectories")) {
+foreach ($file in [System.IO.Directory]::EnumerateFiles("$repoRoot\src", "*.csproj", "AllDirectories")) {
+
+ $projectName = [System.IO.Path]::GetFileName($file);
+ if (!($projectName.startswith("System.") -or $projectName.startswith("Microsoft."))) {
+ continue;
+ }
+
Write-Host "Creating NuGet package for $file..."
Invoke-Expression "$dotnetExePath pack $file -c $Configuration -o $packagesPath --include-symbols --version-suffix $BuildVersion"
@@ -31,10 +38,10 @@ foreach ($file in [System.IO.Directory]::EnumerateFiles("$repoRoot\src", "System
}
}
-Ensure-Nuget-Exists
-
if ($ApiKey)
{
+ Ensure-Nuget-Exists
+
foreach ($file in [System.IO.Directory]::EnumerateFiles("$packagesPath", "*.nupkg")) {
try {
Write-Host "Pushing package $file to MyGet..."
diff --git a/src/Microsoft.Experimental.Collections/Microsoft.Experimental.Collections.csproj b/src/Microsoft.Experimental.Collections/Microsoft.Experimental.Collections.csproj
new file mode 100644
index 00000000000..fcc4b1cba41
--- /dev/null
+++ b/src/Microsoft.Experimental.Collections/Microsoft.Experimental.Collections.csproj
@@ -0,0 +1,24 @@
+
+
+
+ This package provides collections that are being considered for future versions of .NET Core.
+ netstandard2.0
+ collections system microsoft multivaluedictionary
+ 1.0.4
+
+
+
+
+ True
+ True
+ Strings.resx
+
+
+
+
+ ResXFileCodeGenerator
+ Strings.Designer.cs
+ System
+
+
+
diff --git a/archived_projects/src/System.Collections.Generic.MultiValueDictionary/System/Collections/Generic/MultiValueDictionary.cs b/src/Microsoft.Experimental.Collections/Microsoft/Collections/Extensions/MultiValueDictionary.cs
similarity index 80%
rename from archived_projects/src/System.Collections.Generic.MultiValueDictionary/System/Collections/Generic/MultiValueDictionary.cs
rename to src/Microsoft.Experimental.Collections/Microsoft/Collections/Extensions/MultiValueDictionary.cs
index 133ccf314aa..d1218eb1482 100644
--- a/archived_projects/src/System.Collections.Generic.MultiValueDictionary/System/Collections/Generic/MultiValueDictionary.cs
+++ b/src/Microsoft.Experimental.Collections/Microsoft/Collections/Extensions/MultiValueDictionary.cs
@@ -1,7 +1,11 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-namespace System.Collections.Generic
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Microsoft.Collections.Extensions
{
///
/// A MultiValueDictionary can be viewed as a that allows multiple
@@ -30,7 +34,7 @@ public class MultiValueDictionary :
///
/// The private dictionary that this class effectively wraps around
///
- private Dictionary dictionary;
+ private readonly Dictionary _dictionary;
///
/// The function to construct a new
@@ -42,7 +46,7 @@ public class MultiValueDictionary :
/// The current version of this MultiValueDictionary used to determine MultiValueDictionary modification
/// during enumeration
///
- private int version;
+ private int _version;
#endregion
@@ -58,7 +62,7 @@ public class MultiValueDictionary :
///
public MultiValueDictionary()
{
- dictionary = new Dictionary();
+ _dictionary = new Dictionary();
}
///
@@ -71,8 +75,8 @@ public MultiValueDictionary()
public MultiValueDictionary(int capacity)
{
if (capacity < 0)
- throw new ArgumentOutOfRangeException("capacity", Properties.Resources.ArgumentOutOfRange_NeedNonNegNum);
- dictionary = new Dictionary(capacity);
+ throw new ArgumentOutOfRangeException(nameof(capacity), Strings.ArgumentOutOfRange_NeedNonNegNum);
+ _dictionary = new Dictionary(capacity);
}
///
@@ -84,7 +88,7 @@ public MultiValueDictionary(int capacity)
/// If is set to null, then the default for is used.
public MultiValueDictionary(IEqualityComparer comparer)
{
- dictionary = new Dictionary(comparer);
+ _dictionary = new Dictionary(comparer);
}
///
@@ -99,8 +103,8 @@ public MultiValueDictionary(IEqualityComparer comparer)
public MultiValueDictionary(int capacity, IEqualityComparer comparer)
{
if (capacity < 0)
- throw new ArgumentOutOfRangeException("capacity", Properties.Resources.ArgumentOutOfRange_NeedNonNegNum);
- dictionary = new Dictionary(capacity, comparer);
+ throw new ArgumentOutOfRangeException(nameof(capacity), Strings.ArgumentOutOfRange_NeedNonNegNum);
+ _dictionary = new Dictionary(capacity, comparer);
}
///
@@ -126,9 +130,9 @@ public MultiValueDictionary(IEnumerable>> enumerable, IEqualityComparer comparer)
{
if (enumerable == null)
- throw new ArgumentNullException("enumerable");
+ throw new ArgumentNullException(nameof(enumerable));
- dictionary = new Dictionary(comparer);
+ _dictionary = new Dictionary(comparer);
foreach (var pair in enumerable)
AddRange(pair.Key, pair.Value);
}
@@ -164,11 +168,12 @@ public static MultiValueDictionary Create()
where TValueCollection : ICollection, new()
{
if (new TValueCollection().IsReadOnly)
- throw new InvalidOperationException(Properties.Resources.Create_TValueCollectionReadOnly);
+ throw new InvalidOperationException(Strings.Create_TValueCollectionReadOnly);
- var multiValueDictionary = new MultiValueDictionary();
- multiValueDictionary.NewCollectionFactory = () => new TValueCollection();
- return multiValueDictionary;
+ return new MultiValueDictionary
+ {
+ NewCollectionFactory = () => new TValueCollection()
+ };
}
///
@@ -197,13 +202,14 @@ public static MultiValueDictionary Create(int ca
where TValueCollection : ICollection, new()
{
if (capacity < 0)
- throw new ArgumentOutOfRangeException("capacity", Properties.Resources.ArgumentOutOfRange_NeedNonNegNum);
+ throw new ArgumentOutOfRangeException(nameof(capacity), Strings.ArgumentOutOfRange_NeedNonNegNum);
if (new TValueCollection().IsReadOnly)
- throw new InvalidOperationException(Properties.Resources.Create_TValueCollectionReadOnly);
+ throw new InvalidOperationException(Strings.Create_TValueCollectionReadOnly);
- var multiValueDictionary = new MultiValueDictionary(capacity);
- multiValueDictionary.NewCollectionFactory = () => new TValueCollection();
- return multiValueDictionary;
+ return new MultiValueDictionary(capacity)
+ {
+ NewCollectionFactory = () => new TValueCollection()
+ };
}
///
@@ -232,11 +238,12 @@ public static MultiValueDictionary Create(IEqual
where TValueCollection : ICollection, new()
{
if (new TValueCollection().IsReadOnly)
- throw new InvalidOperationException(Properties.Resources.Create_TValueCollectionReadOnly);
+ throw new InvalidOperationException(Strings.Create_TValueCollectionReadOnly);
- var multiValueDictionary = new MultiValueDictionary(comparer);
- multiValueDictionary.NewCollectionFactory = () => new TValueCollection();
- return multiValueDictionary;
+ return new MultiValueDictionary(comparer)
+ {
+ NewCollectionFactory = () => new TValueCollection()
+ };
}
///
@@ -267,13 +274,14 @@ public static MultiValueDictionary Create(int ca
where TValueCollection : ICollection, new()
{
if (capacity < 0)
- throw new ArgumentOutOfRangeException("capacity", Properties.Resources.ArgumentOutOfRange_NeedNonNegNum);
+ throw new ArgumentOutOfRangeException(nameof(capacity), Strings.ArgumentOutOfRange_NeedNonNegNum);
if (new TValueCollection().IsReadOnly)
- throw new InvalidOperationException(Properties.Resources.Create_TValueCollectionReadOnly);
+ throw new InvalidOperationException(Strings.Create_TValueCollectionReadOnly);
- var multiValueDictionary = new MultiValueDictionary(capacity, comparer);
- multiValueDictionary.NewCollectionFactory = () => new TValueCollection();
- return multiValueDictionary;
+ return new MultiValueDictionary(capacity, comparer)
+ {
+ NewCollectionFactory = () => new TValueCollection()
+ };
}
///
@@ -302,12 +310,14 @@ public static MultiValueDictionary Create(IEnume
where TValueCollection : ICollection, new()
{
if (enumerable == null)
- throw new ArgumentNullException("enumerable");
+ throw new ArgumentNullException(nameof(enumerable));
if (new TValueCollection().IsReadOnly)
- throw new InvalidOperationException(Properties.Resources.Create_TValueCollectionReadOnly);
+ throw new InvalidOperationException(Strings.Create_TValueCollectionReadOnly);
- var multiValueDictionary = new MultiValueDictionary();
- multiValueDictionary.NewCollectionFactory = () => new TValueCollection();
+ var multiValueDictionary = new MultiValueDictionary
+ {
+ NewCollectionFactory = () => new TValueCollection()
+ };
foreach (var pair in enumerable)
multiValueDictionary.AddRange(pair.Key, pair.Value);
return multiValueDictionary;
@@ -341,12 +351,14 @@ public static MultiValueDictionary Create(IEnume
where TValueCollection : ICollection, new()
{
if (enumerable == null)
- throw new ArgumentNullException("enumerable");
+ throw new ArgumentNullException(nameof(enumerable));
if (new TValueCollection().IsReadOnly)
- throw new InvalidOperationException(Properties.Resources.Create_TValueCollectionReadOnly);
+ throw new InvalidOperationException(Strings.Create_TValueCollectionReadOnly);
- var multiValueDictionary = new MultiValueDictionary(comparer);
- multiValueDictionary.NewCollectionFactory = () => new TValueCollection();
+ var multiValueDictionary = new MultiValueDictionary(comparer)
+ {
+ NewCollectionFactory = () => new TValueCollection()
+ };
foreach (var pair in enumerable)
multiValueDictionary.AddRange(pair.Key, pair.Value);
return multiValueDictionary;
@@ -385,11 +397,12 @@ public static MultiValueDictionary Create(Func
{
if (collectionFactory().IsReadOnly)
- throw new InvalidOperationException((Properties.Resources.Create_TValueCollectionReadOnly));
+ throw new InvalidOperationException((Strings.Create_TValueCollectionReadOnly));
- var multiValueDictionary = new MultiValueDictionary();
- multiValueDictionary.NewCollectionFactory = (Func>)(Delegate)collectionFactory;
- return multiValueDictionary;
+ return new MultiValueDictionary
+ {
+ NewCollectionFactory = (Func>)(Delegate)collectionFactory
+ };
}
///
@@ -420,13 +433,14 @@ public static MultiValueDictionary Create(int ca
where TValueCollection : ICollection
{
if (capacity < 0)
- throw new ArgumentOutOfRangeException("capacity", Properties.Resources.ArgumentOutOfRange_NeedNonNegNum);
+ throw new ArgumentOutOfRangeException(nameof(capacity), Strings.ArgumentOutOfRange_NeedNonNegNum);
if (collectionFactory().IsReadOnly)
- throw new InvalidOperationException((Properties.Resources.Create_TValueCollectionReadOnly));
+ throw new InvalidOperationException((Strings.Create_TValueCollectionReadOnly));
- var multiValueDictionary = new MultiValueDictionary(capacity);
- multiValueDictionary.NewCollectionFactory = (Func>)(Delegate)collectionFactory;
- return multiValueDictionary;
+ return new MultiValueDictionary(capacity)
+ {
+ NewCollectionFactory = (Func>)(Delegate)collectionFactory
+ };
}
///
@@ -457,11 +471,12 @@ public static MultiValueDictionary Create(IEqual
where TValueCollection : ICollection
{
if (collectionFactory().IsReadOnly)
- throw new InvalidOperationException((Properties.Resources.Create_TValueCollectionReadOnly));
+ throw new InvalidOperationException((Strings.Create_TValueCollectionReadOnly));
- var multiValueDictionary = new MultiValueDictionary(comparer);
- multiValueDictionary.NewCollectionFactory = (Func>)(Delegate)collectionFactory;
- return multiValueDictionary;
+ return new MultiValueDictionary(comparer)
+ {
+ NewCollectionFactory = (Func>)(Delegate)collectionFactory
+ };
}
///
@@ -494,13 +509,14 @@ public static MultiValueDictionary Create(int ca
where TValueCollection : ICollection
{
if (capacity < 0)
- throw new ArgumentOutOfRangeException("capacity", Properties.Resources.ArgumentOutOfRange_NeedNonNegNum);
+ throw new ArgumentOutOfRangeException(nameof(capacity), Strings.ArgumentOutOfRange_NeedNonNegNum);
if (collectionFactory().IsReadOnly)
- throw new InvalidOperationException((Properties.Resources.Create_TValueCollectionReadOnly));
+ throw new InvalidOperationException((Strings.Create_TValueCollectionReadOnly));
- var multiValueDictionary = new MultiValueDictionary(capacity, comparer);
- multiValueDictionary.NewCollectionFactory = (Func>)(Delegate)collectionFactory;
- return multiValueDictionary;
+ return new MultiValueDictionary(capacity, comparer)
+ {
+ NewCollectionFactory = (Func>)(Delegate)collectionFactory
+ };
}
///
@@ -531,12 +547,14 @@ public static MultiValueDictionary Create(IEnume
where TValueCollection : ICollection
{
if (enumerable == null)
- throw new ArgumentNullException("enumerable");
+ throw new ArgumentNullException(nameof(enumerable));
if (collectionFactory().IsReadOnly)
- throw new InvalidOperationException((Properties.Resources.Create_TValueCollectionReadOnly));
+ throw new InvalidOperationException((Strings.Create_TValueCollectionReadOnly));
- var multiValueDictionary = new MultiValueDictionary();
- multiValueDictionary.NewCollectionFactory = (Func>)(Delegate)collectionFactory;
+ var multiValueDictionary = new MultiValueDictionary
+ {
+ NewCollectionFactory = (Func>)(Delegate)collectionFactory
+ };
foreach (var pair in enumerable)
multiValueDictionary.AddRange(pair.Key, pair.Value);
return multiValueDictionary;
@@ -572,12 +590,14 @@ public static MultiValueDictionary Create(IEnume
where TValueCollection : ICollection
{
if (enumerable == null)
- throw new ArgumentNullException("enumerable");
+ throw new ArgumentNullException(nameof(enumerable));
if (collectionFactory().IsReadOnly)
- throw new InvalidOperationException((Properties.Resources.Create_TValueCollectionReadOnly));
+ throw new InvalidOperationException((Strings.Create_TValueCollectionReadOnly));
- var multiValueDictionary = new MultiValueDictionary(comparer);
- multiValueDictionary.NewCollectionFactory = (Func>)(Delegate)collectionFactory;
+ var multiValueDictionary = new MultiValueDictionary(comparer)
+ {
+ NewCollectionFactory = (Func>)(Delegate)collectionFactory
+ };
foreach (var pair in enumerable)
multiValueDictionary.AddRange(pair.Key, pair.Value);
return multiValueDictionary;
@@ -608,14 +628,14 @@ public static MultiValueDictionary Create(IEnume
public void Add(TKey key, TValue value)
{
if (key == null)
- throw new ArgumentNullException("key");
- if (!dictionary.TryGetValue(key, out InnerCollectionView collection))
+ throw new ArgumentNullException(nameof(key));
+ if (!_dictionary.TryGetValue(key, out InnerCollectionView collection))
{
collection = new InnerCollectionView(key, NewCollectionFactory());
- dictionary.Add(key, collection);
+ _dictionary.Add(key, collection);
}
collection.AddValue(value);
- version++;
+ _version++;
}
///
@@ -633,20 +653,20 @@ public void Add(TKey key, TValue value)
public void AddRange(TKey key, IEnumerable values)
{
if (key == null)
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
if (values == null)
- throw new ArgumentNullException("values");
+ throw new ArgumentNullException(nameof(values));
- if (!dictionary.TryGetValue(key, out InnerCollectionView collection))
+ if (!_dictionary.TryGetValue(key, out InnerCollectionView collection))
{
collection = new InnerCollectionView(key, NewCollectionFactory());
- dictionary.Add(key, collection);
+ _dictionary.Add(key, collection);
}
foreach (TValue value in values)
{
collection.AddValue(value);
}
- version++;
+ _version++;
}
///
@@ -659,11 +679,11 @@ public void AddRange(TKey key, IEnumerable values)
public bool Remove(TKey key)
{
if (key == null)
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
- if (dictionary.TryGetValue(key, out InnerCollectionView collection) && dictionary.Remove(key))
+ if (_dictionary.TryGetValue(key, out InnerCollectionView _) && _dictionary.Remove(key))
{
- version++;
+ _version++;
return true;
}
return false;
@@ -686,13 +706,13 @@ public bool Remove(TKey key)
public bool Remove(TKey key, TValue value)
{
if (key == null)
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
- if (dictionary.TryGetValue(key, out InnerCollectionView collection) && collection.RemoveValue(value))
+ if (_dictionary.TryGetValue(key, out InnerCollectionView collection) && collection.RemoveValue(value))
{
if (collection.Count == 0)
- dictionary.Remove(key);
- version++;
+ _dictionary.Remove(key);
+ _version++;
return true;
}
return false;
@@ -709,9 +729,9 @@ public bool Remove(TKey key, TValue value)
public bool Contains(TKey key, TValue value)
{
if (key == null)
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
- return (dictionary.TryGetValue(key, out InnerCollectionView collection) && collection.Contains(value));
+ return (_dictionary.TryGetValue(key, out InnerCollectionView collection) && collection.Contains(value));
}
///
@@ -721,7 +741,7 @@ public bool Contains(TKey key, TValue value)
/// true if the contains the ; otherwise false
public bool ContainsValue(TValue value)
{
- foreach (InnerCollectionView sublist in dictionary.Values)
+ foreach (InnerCollectionView sublist in _dictionary.Values)
if (sublist.Contains(value))
return true;
return false;
@@ -733,8 +753,8 @@ public bool ContainsValue(TValue value)
///
public void Clear()
{
- dictionary.Clear();
- version++;
+ _dictionary.Clear();
+ _version++;
}
#endregion
@@ -755,11 +775,11 @@ public void Clear()
public bool ContainsKey(TKey key)
{
if (key == null)
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
// Since modification to the MultiValueDictionary is only allowed through its own API, we
// can ensure that if a collection is in the internal dictionary then it must have at least one
// associated TValue, or else it would have been removed whenever its final TValue was removed.
- return dictionary.ContainsKey(key);
+ return _dictionary.ContainsKey(key);
}
///
@@ -771,13 +791,7 @@ public bool ContainsKey(TKey key)
/// in this that has one or more associated
/// .
///
- public IEnumerable Keys
- {
- get
- {
- return dictionary.Keys;
- }
- }
+ public IEnumerable Keys => _dictionary.Keys;
///
/// Attempts to get the associated with the given
@@ -796,9 +810,9 @@ public IEnumerable Keys
public bool TryGetValue(TKey key, out IReadOnlyCollection value)
{
if (key == null)
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
- var success = dictionary.TryGetValue(key, out InnerCollectionView collection);
+ var success = _dictionary.TryGetValue(key, out InnerCollectionView collection);
value = collection;
return success;
}
@@ -810,13 +824,7 @@ public bool TryGetValue(TKey key, out IReadOnlyCollection value)
///
/// An IEnumerable of each in this
///
- public IEnumerable> Values
- {
- get
- {
- return dictionary.Values;
- }
- }
+ public IEnumerable> Values => _dictionary.Values;
///
/// Get every associated with the given . If
@@ -840,12 +848,12 @@ public IReadOnlyCollection this[TKey key]
get
{
if (key == null)
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
- if (dictionary.TryGetValue(key, out InnerCollectionView collection))
+ if (_dictionary.TryGetValue(key, out InnerCollectionView collection))
return collection;
- else
- throw new KeyNotFoundException();
+
+ throw new KeyNotFoundException();
}
}
@@ -854,13 +862,7 @@ public IReadOnlyCollection this[TKey key]
/// in this .
///
/// The number of s in this .
- public int Count
- {
- get
- {
- return dictionary.Count;
- }
- }
+ public int Count => _dictionary.Count;
///
/// Get an Enumerator over the -
@@ -868,15 +870,9 @@ public int Count
///
/// an Enumerator over the -
/// pairs in this .
- public IEnumerator>> GetEnumerator()
- {
- return new Enumerator(this);
- }
+ public IEnumerator>> GetEnumerator() => new Enumerator(this);
- IEnumerator IEnumerable.GetEnumerator()
- {
- return new Enumerator(this);
- }
+ IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
#endregion
@@ -888,12 +884,10 @@ IEnumerator IEnumerable.GetEnumerator()
private class Enumerator :
IEnumerator>>
{
- private MultiValueDictionary multiValueDictionary;
- private int version;
- private KeyValuePair> current;
- private Dictionary.Enumerator enumerator;
- private enum EnumerationState { BeforeFirst, During, AfterLast };
- private EnumerationState state;
+ private readonly MultiValueDictionary _multiValueDictionary;
+ private readonly int _version;
+ private Dictionary.Enumerator _enumerator;
+ private EnumerationState _state;
///
/// Constructor for the enumerator
@@ -901,30 +895,27 @@ private enum EnumerationState { BeforeFirst, During, AfterLast };
/// A MultiValueDictionary to iterate over
internal Enumerator(MultiValueDictionary multiValueDictionary)
{
- this.multiValueDictionary = multiValueDictionary;
- this.version = multiValueDictionary.version;
- this.current = default;
- this.enumerator = multiValueDictionary.dictionary.GetEnumerator();
- this.state = EnumerationState.BeforeFirst; ;
+ _multiValueDictionary = multiValueDictionary;
+ _version = multiValueDictionary._version;
+ _enumerator = multiValueDictionary._dictionary.GetEnumerator();
+ _state = EnumerationState.BeforeFirst;
+ Current = default;
}
- public KeyValuePair> Current
- {
- get { return current; }
- }
+ public KeyValuePair> Current { get; private set; }
object IEnumerator.Current
{
get
{
- switch (state)
+ switch (_state)
{
case EnumerationState.BeforeFirst:
- throw new InvalidOperationException((Properties.Resources.InvalidOperation_EnumNotStarted));
+ throw new InvalidOperationException((Strings.InvalidOperation_EnumNotStarted));
case EnumerationState.AfterLast:
- throw new InvalidOperationException((Properties.Resources.InvalidOperation_EnumEnded));
+ throw new InvalidOperationException((Strings.InvalidOperation_EnumEnded));
default:
- return current;
+ return Current;
}
}
}
@@ -938,22 +929,19 @@ object IEnumerator.Current
/// The collection was modified after the enumerator was created.
public bool MoveNext()
{
- if (version != multiValueDictionary.version)
- {
- throw new InvalidOperationException(Properties.Resources.InvalidOperation_EnumFailedVersion);
- }
- else if (enumerator.MoveNext())
+ if (_version != _multiValueDictionary._version)
+ throw new InvalidOperationException(Strings.InvalidOperation_EnumFailedVersion);
+
+ if (_enumerator.MoveNext())
{
- current = new KeyValuePair>(enumerator.Current.Key, enumerator.Current.Value);
- state = EnumerationState.During;
+ Current = new KeyValuePair>(_enumerator.Current.Key, _enumerator.Current.Value);
+ _state = EnumerationState.During;
return true;
}
- else
- {
- current = default;
- state = EnumerationState.AfterLast;
- return false;
- }
+
+ Current = default;
+ _state = EnumerationState.AfterLast;
+ return false;
}
///
@@ -962,20 +950,24 @@ public bool MoveNext()
/// The collection was modified after the enumerator was created.
public void Reset()
{
- if (version != multiValueDictionary.version)
- throw new InvalidOperationException(Properties.Resources.InvalidOperation_EnumFailedVersion);
- enumerator.Dispose();
- enumerator = multiValueDictionary.dictionary.GetEnumerator();
- current = default;
- state = EnumerationState.BeforeFirst;
+ if (_version != _multiValueDictionary._version)
+ throw new InvalidOperationException(Strings.InvalidOperation_EnumFailedVersion);
+ _enumerator.Dispose();
+ _enumerator = _multiValueDictionary._dictionary.GetEnumerator();
+ Current = default;
+ _state = EnumerationState.BeforeFirst;
}
///
/// Frees resources associated with this Enumerator
///
- public void Dispose()
+ public void Dispose() => _enumerator.Dispose();
+
+ private enum EnumerationState
{
- enumerator.Dispose();
+ BeforeFirst,
+ During,
+ AfterLast
}
}
@@ -986,8 +978,7 @@ private class InnerCollectionView :
ICollection,
IReadOnlyCollection
{
- private TKey key;
- private ICollection collection;
+ private readonly ICollection _collection;
#region Private Concrete API
/*======================================================================
@@ -996,19 +987,13 @@ private class InnerCollectionView :
public InnerCollectionView(TKey key, ICollection collection)
{
- this.key = key;
- this.collection = collection;
+ Key = key;
+ _collection = collection;
}
- public void AddValue(TValue item)
- {
- collection.Add(item);
- }
+ public void AddValue(TValue item) => _collection.Add(item);
- public bool RemoveValue(TValue item)
- {
- return collection.Remove(item);
- }
+ public bool RemoveValue(TValue item) => _collection.Remove(item);
#endregion
@@ -1017,55 +1002,31 @@ public bool RemoveValue(TValue item)
** Shared API
======================================================================*/
- public bool Contains(TValue item)
- {
- return collection.Contains(item);
- }
+ public bool Contains(TValue item) => _collection.Contains(item);
public void CopyTo(TValue[] array, int arrayIndex)
{
if (array == null)
- throw new ArgumentNullException("array");
+ throw new ArgumentNullException(nameof(array));
if (arrayIndex < 0)
- throw new ArgumentOutOfRangeException("arrayIndex", Properties.Resources.ArgumentOutOfRange_NeedNonNegNum);
+ throw new ArgumentOutOfRangeException(nameof(arrayIndex), Strings.ArgumentOutOfRange_NeedNonNegNum);
if (arrayIndex > array.Length)
- throw new ArgumentOutOfRangeException("arrayIndex", Properties.Resources.ArgumentOutOfRange_Index);
- if (array.Length - arrayIndex < collection.Count)
- throw new ArgumentException(Properties.Resources.CopyTo_ArgumentsTooSmall, "arrayIndex");
+ throw new ArgumentOutOfRangeException(nameof(arrayIndex), Strings.ArgumentOutOfRange_Index);
+ if (array.Length - arrayIndex < _collection.Count)
+ throw new ArgumentException(Strings.CopyTo_ArgumentsTooSmall, nameof(arrayIndex));
- collection.CopyTo(array, arrayIndex);
+ _collection.CopyTo(array, arrayIndex);
}
- public int Count
- {
- get
- {
- return collection.Count;
- }
- }
+ public int Count => _collection.Count;
- public bool IsReadOnly
- {
- get
- {
- return true;
- }
- }
+ public bool IsReadOnly => true;
- public IEnumerator GetEnumerator()
- {
- return collection.GetEnumerator();
- }
+ public IEnumerator GetEnumerator() => _collection.GetEnumerator();
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.GetEnumerator();
- }
+ IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
- public TKey Key
- {
- get { return key; }
- }
+ public TKey Key { get; }
#endregion
@@ -1074,20 +1035,12 @@ public TKey Key
** Public-Facing API
======================================================================*/
- void ICollection.Add(TValue item)
- {
- throw new NotSupportedException(Properties.Resources.ReadOnly_Modification);
- }
+ void ICollection.Add(TValue item) => throw new NotSupportedException(Strings.ReadOnly_Modification);
+
- void ICollection.Clear()
- {
- throw new NotSupportedException(Properties.Resources.ReadOnly_Modification);
- }
+ void ICollection.Clear() => throw new NotSupportedException(Strings.ReadOnly_Modification);
- bool ICollection.Remove(TValue item)
- {
- throw new NotSupportedException(Properties.Resources.ReadOnly_Modification);
- }
+ bool ICollection.Remove(TValue item) => throw new NotSupportedException(Strings.ReadOnly_Modification);
#endregion
}
diff --git a/archived_projects/src/System.Collections.Generic.MultiValueDictionary/Properties/Resources.Designer.cs b/src/Microsoft.Experimental.Collections/Properties/Strings.Designer.cs
similarity index 98%
rename from archived_projects/src/System.Collections.Generic.MultiValueDictionary/Properties/Resources.Designer.cs
rename to src/Microsoft.Experimental.Collections/Properties/Strings.Designer.cs
index 68d962c3df1..a90bd8657d7 100644
--- a/archived_projects/src/System.Collections.Generic.MultiValueDictionary/Properties/Resources.Designer.cs
+++ b/src/Microsoft.Experimental.Collections/Properties/Strings.Designer.cs
@@ -8,9 +8,8 @@
//
//------------------------------------------------------------------------------
-namespace Properties {
+namespace System {
using System;
- using System.Reflection;
///
@@ -20,17 +19,17 @@ namespace Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources {
+ internal class Strings {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources() {
+ internal Strings() {
}
///
@@ -40,7 +39,7 @@ internal Resources() {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Properties.Resources", typeof(Resources).GetTypeInfo().Assembly);
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Experimental.Collections.Properties.Strings", typeof(Strings).Assembly);
resourceMan = temp;
}
return resourceMan;
diff --git a/archived_projects/src/System.Collections.Generic.MultiValueDictionary/Properties/Resources.resx b/src/Microsoft.Experimental.Collections/Properties/Strings.resx
similarity index 100%
rename from archived_projects/src/System.Collections.Generic.MultiValueDictionary/Properties/Resources.resx
rename to src/Microsoft.Experimental.Collections/Properties/Strings.resx
diff --git a/tests/Benchmarks/Benchmarks.csproj b/tests/Benchmarks/Benchmarks.csproj
index 8edf969a0ec..b46859e51bd 100644
--- a/tests/Benchmarks/Benchmarks.csproj
+++ b/tests/Benchmarks/Benchmarks.csproj
@@ -40,6 +40,7 @@
+
diff --git a/tests/Benchmarks/Microsoft.Experimental.Collections/MultiValueDictionaryPerformanceTests.cs b/tests/Benchmarks/Microsoft.Experimental.Collections/MultiValueDictionaryPerformanceTests.cs
new file mode 100644
index 00000000000..d15d4a05655
--- /dev/null
+++ b/tests/Benchmarks/Microsoft.Experimental.Collections/MultiValueDictionaryPerformanceTests.cs
@@ -0,0 +1,109 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Collections.Generic;
+using BenchmarkDotNet.Attributes;
+
+namespace Microsoft.Collections.Extensions.Tests
+{
+ [MemoryDiagnoser]
+ public class MultiValueDictionaryPerformanceTests
+ {
+ [Params(1000, 10_000, 100_000)]
+ public int Size { get; set; }
+
+ private int _randomKey;
+ private List _values;
+ private MultiValueDictionary _dict;
+ private int _value;
+
+ [GlobalSetup(Targets = new[] { nameof(Clear), nameof(GetKeys) })]
+ public void CreateMultiValueDictionary_SingleValues()
+ {
+ _dict = new MultiValueDictionary();
+ Random rand = new Random(11231992);
+
+ while (_dict.Count < Size)
+ _dict.Add(rand.Next(), rand.Next());
+ }
+
+ [GlobalSetup(Targets = new[] { nameof(TryGetValue), nameof(ContainsKey), nameof(GetItem) })]
+ public void CreateMultiValueDictionary_AddRandomKey()
+ {
+ CreateMultiValueDictionary_SingleValues();
+ _randomKey = new Random(837322).Next(0, 400000);
+ _dict.Add(_randomKey, 12);
+ }
+
+ [GlobalSetup(Target = nameof(Remove))]
+ public void Remove_CreateDictionaryMultipleRepeatedValues()
+ {
+ SetValue();
+ _dict = new MultiValueDictionary();
+ for (int i = 0; i < Size; i++)
+ for (int j = 0; j < 100; j++)
+ _dict.Add(i, j);
+ }
+
+ [IterationSetup(Targets = new[] { nameof(Add), nameof(ContainsValue) })]
+ public void AddContainsSetup()
+ {
+ SetValue();
+ CreateMultiValueDictionary_SingleValues();
+ }
+
+ [IterationSetup(Target = nameof(AddRange))]
+ public void AddRange_CreateListWithValues()
+ {
+ SetValue();
+ _values = new List();
+ for (int i = 0; i < Size; i++)
+ _values.Add(i);
+ _dict = new MultiValueDictionary();
+ }
+
+ private void SetValue()
+ {
+ if (Size >= 1024)
+ _value = 1024;
+ if (Size >= 4096)
+ _value = 4096;
+ if (Size >= 16384)
+ _value = 16384;
+ }
+
+ [Benchmark]
+ public void Add() => _dict.Add(_value, 0);
+
+ [Benchmark]
+ public void AddRange() => _dict.AddRange(_value, _values);
+
+ [Benchmark]
+ public bool Remove() => _dict.Remove(_value);
+
+ [Benchmark]
+ public void Clear() => _dict.Clear();
+
+ [Benchmark]
+ public MultiValueDictionary Ctor() => new MultiValueDictionary();
+
+ [Benchmark]
+ public MultiValueDictionary Ctor_Size() => new MultiValueDictionary(Size);
+
+ [Benchmark]
+ public IReadOnlyCollection GetItem() => _dict[_randomKey];
+
+ [Benchmark]
+ public IEnumerable GetKeys() => _dict.Keys;
+
+ [Benchmark]
+ public bool TryGetValue() => _dict.TryGetValue(_randomKey, out var _);
+
+ [Benchmark]
+ public bool ContainsKey() => _dict.ContainsKey(_randomKey);
+
+ [Benchmark]
+ public bool ContainsValue() => _dict.ContainsValue(_value);
+ }
+}
diff --git a/archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/System.Collections.Generic.MultiValueDictionary.Tests.csproj b/tests/Microsoft.Experimental.Collections.Tests/Microsoft.Experimental.Collections.Tests.csproj
similarity index 71%
rename from archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/System.Collections.Generic.MultiValueDictionary.Tests.csproj
rename to tests/Microsoft.Experimental.Collections.Tests/Microsoft.Experimental.Collections.Tests.csproj
index 8b15d5ea913..08ce74bf556 100644
--- a/archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/System.Collections.Generic.MultiValueDictionary.Tests.csproj
+++ b/tests/Microsoft.Experimental.Collections.Tests/Microsoft.Experimental.Collections.Tests.csproj
@@ -1,8 +1,7 @@
-
+
netcoreapp2.1
- False
../../tools/test_key.snk
true
true
@@ -14,11 +13,7 @@
False
- False
-
-
-
@@ -26,7 +21,7 @@
-
+
diff --git a/archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/Generic/MultiValueDictionary/MVD.TestBase.cs b/tests/Microsoft.Experimental.Collections.Tests/Microsoft/Collections/Extensions/MultiValueDictionaryTestBase.cs
similarity index 98%
rename from archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/Generic/MultiValueDictionary/MVD.TestBase.cs
rename to tests/Microsoft.Experimental.Collections.Tests/Microsoft/Collections/Extensions/MultiValueDictionaryTestBase.cs
index 738b78c787b..c106cdce680 100644
--- a/archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/Generic/MultiValueDictionary/MVD.TestBase.cs
+++ b/tests/Microsoft.Experimental.Collections.Tests/Microsoft/Collections/Extensions/MultiValueDictionaryTestBase.cs
@@ -1,12 +1,14 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using System;
+using System.Collections;
using System.Collections.Generic;
using Xunit;
-namespace System.Collections.Tests
+namespace Microsoft.Collections.Extensions.Tests
{
- public class MVD_TestBase
+ public class MultiValueDictionaryTestBase
{
private static Random rand = new Random(11231992);
diff --git a/archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/Generic/MultiValueDictionary/MVD.Tests.cs b/tests/Microsoft.Experimental.Collections.Tests/Microsoft/Collections/Extensions/MultiValueDictionaryTests.cs
similarity index 99%
rename from archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/Generic/MultiValueDictionary/MVD.Tests.cs
rename to tests/Microsoft.Experimental.Collections.Tests/Microsoft/Collections/Extensions/MultiValueDictionaryTests.cs
index fd325bd3b41..aabc4aba6bb 100644
--- a/archived_projects/tests/System.Collections.Generic.MultiValueDictionary.Tests/Generic/MultiValueDictionary/MVD.Tests.cs
+++ b/tests/Microsoft.Experimental.Collections.Tests/Microsoft/Collections/Extensions/MultiValueDictionaryTests.cs
@@ -1,14 +1,16 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using System;
+using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit;
-namespace System.Collections.Tests
+namespace Microsoft.Collections.Extensions.Tests
{
- public class MVD_Tests : MVD_TestBase
+ public class MultiValueDictionaryTests : MultiValueDictionaryTestBase
{
#region Helper Methods
/*======================================================================