Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2017-06-30 08:55:49 +0300
committerAndrew Arnott <andrewarnott@gmail.com>2017-06-30 08:55:49 +0300
commit812957920219f3ca274d3cfb80cac06893dd33cd (patch)
tree8f4742170a338e09b1a40c827f78dbf00881f8a1 /src/System.Collections.Immutable
parentf2c0ae2d1b273a02fba4d012f9e0bda693339609 (diff)
Move code around to fit standards
Diffstat (limited to 'src/System.Collections.Immutable')
-rw-r--r--src/System.Collections.Immutable/src/System.Collections.Immutable.csproj2
-rw-r--r--src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs8
-rw-r--r--src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucketByRefEqualityComparer.cs44
-rw-r--r--src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucketByValueEqualityComparer.cs53
-rw-r--r--src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.cs73
5 files changed, 122 insertions, 58 deletions
diff --git a/src/System.Collections.Immutable/src/System.Collections.Immutable.csproj b/src/System.Collections.Immutable/src/System.Collections.Immutable.csproj
index 7d03aff450..2d19079d52 100644
--- a/src/System.Collections.Immutable/src/System.Collections.Immutable.csproj
+++ b/src/System.Collections.Immutable/src/System.Collections.Immutable.csproj
@@ -37,6 +37,8 @@
<Compile Include="System\Collections\Immutable\IImmutableQueue.cs" />
<Compile Include="System\Collections\Immutable\IImmutableSet.cs" />
<Compile Include="System\Collections\Immutable\IImmutableStack.cs" />
+ <Compile Include="System\Collections\Immutable\ImmutableHashSet_1.HashBucketByValueEqualityComparer.cs" />
+ <Compile Include="System\Collections\Immutable\ImmutableHashSet_1.HashBucketByRefEqualityComparer.cs" />
<Compile Include="System\Collections\Immutable\IStrongEnumerable_2.cs" />
<Compile Include="System\Collections\Immutable\IStrongEnumerator_1.cs" />
<Compile Include="System\Collections\Immutable\IOrderedCollection.cs" />
diff --git a/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs b/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs
index 904d23ab8c..5b0e066a01 100644
--- a/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs
+++ b/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs
@@ -31,7 +31,7 @@ namespace System.Collections.Immutable
/// <summary>
/// Contains all the keys in the collection that hash to the same value.
/// </summary>
- internal struct HashBucket : IEquatable<HashBucket>
+ internal struct HashBucket
{
/// <summary>
/// One of the values in this bucket.
@@ -78,12 +78,6 @@ namespace System.Collections.Immutable
}
/// <inheritdoc />
- public bool Equals(HashBucket other)
- {
- throw new NotSupportedException();
- }
-
- /// <inheritdoc />
public override bool Equals(object obj)
{
throw new NotSupportedException();
diff --git a/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucketByRefEqualityComparer.cs b/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucketByRefEqualityComparer.cs
new file mode 100644
index 0000000000..7b4205598c
--- /dev/null
+++ b/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucketByRefEqualityComparer.cs
@@ -0,0 +1,44 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Collections.Generic;
+
+namespace System.Collections.Immutable
+{
+ /// <content>
+ /// Contains the inner <see cref="ImmutableHashSet{T}.HashBucketByRefEqualityComparer"/> class.
+ /// </content>
+ public sealed partial class ImmutableHashSet<T> : IImmutableSet<T>, IHashKeyCollection<T>, IReadOnlyCollection<T>, ICollection<T>, ISet<T>, ICollection, IStrongEnumerable<T, ImmutableHashSet<T>.Enumerator>
+ {
+ /// <summary>
+ /// Compares equality between two <see cref="HashBucket"/> instances
+ /// by reference.
+ /// </summary>
+ private class HashBucketByRefEqualityComparer : IEqualityComparer<HashBucket>
+ {
+ /// <summary>
+ /// The singleton instance.
+ /// </summary>
+ private static readonly IEqualityComparer<HashBucket> s_defaultInstance = new HashBucketByRefEqualityComparer();
+
+ /// <summary>
+ /// Gets the singleton instance to use.
+ /// </summary>
+ internal static IEqualityComparer<HashBucket> DefaultInstance => s_defaultInstance;
+
+ /// <summary>
+ /// Prevents a default instance of the <see cref="HashBucketByRefEqualityComparer"/> class from being created.
+ /// </summary>
+ private HashBucketByRefEqualityComparer()
+ {
+ }
+
+ /// <inheritdoc />
+ public bool Equals(HashBucket x, HashBucket y) => x.EqualsByRef(y);
+
+ /// <inheritdoc />
+ public int GetHashCode(HashBucket obj) => throw new NotSupportedException();
+ }
+ }
+}
diff --git a/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucketByValueEqualityComparer.cs b/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucketByValueEqualityComparer.cs
new file mode 100644
index 0000000000..720114a9d6
--- /dev/null
+++ b/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucketByValueEqualityComparer.cs
@@ -0,0 +1,53 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Collections.Generic;
+
+namespace System.Collections.Immutable
+{
+ /// <content>
+ /// Contains the inner <see cref="ImmutableHashSet{T}.HashBucketByValueEqualityComparer"/> class.
+ /// </content>
+ public sealed partial class ImmutableHashSet<T> : IImmutableSet<T>, IHashKeyCollection<T>, IReadOnlyCollection<T>, ICollection<T>, ISet<T>, ICollection, IStrongEnumerable<T, ImmutableHashSet<T>.Enumerator>
+ {
+ /// <summary>
+ /// Compares equality between two <see cref="HashBucket"/> instances
+ /// by value.
+ /// </summary>
+ private class HashBucketByValueEqualityComparer : IEqualityComparer<HashBucket>
+ {
+ /// <summary>
+ /// The instance to use when the value comparer is <see cref="EqualityComparer{T}.Default"/>.
+ /// </summary>
+ private static readonly IEqualityComparer<HashBucket> s_defaultInstance = new HashBucketByValueEqualityComparer(EqualityComparer<T>.Default);
+
+ /// <summary>
+ /// Gets the instance to use when the value comparer is
+ /// <see cref="EqualityComparer{T}.Default"/>.
+ /// </summary>
+ internal static IEqualityComparer<HashBucket> DefaultInstance => s_defaultInstance;
+
+ /// <summary>
+ /// The value comparer to use when comparing two T instances.
+ /// </summary>
+ private readonly IEqualityComparer<T> _valueComparer;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="HashBucketByValueEqualityComparer"/> class.
+ /// </summary>
+ /// <param name="valueComparer">The value comparer for T.</param>
+ internal HashBucketByValueEqualityComparer(IEqualityComparer<T> valueComparer)
+ {
+ Requires.NotNull(valueComparer, nameof(valueComparer));
+ _valueComparer = valueComparer;
+ }
+
+ /// <inheritdoc />
+ public bool Equals(HashBucket x, HashBucket y) => x.EqualsByValue(y, _valueComparer);
+
+ /// <inheritdoc />
+ public int GetHashCode(HashBucket obj) => throw new NotSupportedException();
+ }
+ }
+}
diff --git a/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.cs b/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.cs
index 342d4292d6..878e64b7d0 100644
--- a/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.cs
+++ b/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.cs
@@ -73,57 +73,7 @@ namespace System.Collections.Immutable
_root = root;
_count = count;
_equalityComparer = equalityComparer;
- _hashBucketEqualityComparer = Get(equalityComparer);
- }
-
- internal static IEqualityComparer<HashBucket> Get(IEqualityComparer<T> valueComparer)
- {
- if (!typeof(ValueType).IsAssignableFrom(typeof(T)))
- {
- return HashBucketByRefEqualityComparer.DefaultInstance;
- }
- else if (valueComparer == EqualityComparer<T>.Default)
- {
- return HashBucketByValueEqualityComparer.DefaultInstance;
- }
- else
- {
- return new HashBucketByValueEqualityComparer(valueComparer);
- }
- }
-
- private class HashBucketByRefEqualityComparer : IEqualityComparer<HashBucket>
- {
- private static readonly IEqualityComparer<HashBucket> s_defaultInstance = new HashBucketByRefEqualityComparer();
-
- internal static IEqualityComparer<HashBucket> DefaultInstance => s_defaultInstance;
-
- private HashBucketByRefEqualityComparer()
- {
- }
-
- public bool Equals(HashBucket x, HashBucket y) => x.EqualsByRef(y);
-
- public int GetHashCode(HashBucket obj) => throw new NotSupportedException();
- }
-
- private class HashBucketByValueEqualityComparer : IEqualityComparer<HashBucket>
- {
- private static readonly IEqualityComparer<HashBucket> s_defaultInstance = new HashBucketByValueEqualityComparer(EqualityComparer<T>.Default);
-
- internal static IEqualityComparer<HashBucket> DefaultInstance => s_defaultInstance;
-
- private readonly IEqualityComparer<T> _valueComparer;
-
- internal HashBucketByValueEqualityComparer(IEqualityComparer<T> valueComparer)
- {
- Requires.NotNull(valueComparer, nameof(valueComparer));
- _valueComparer = valueComparer;
- }
-
- public bool Equals(HashBucket x, HashBucket y) => x.EqualsByValue(y, _valueComparer);
-
- public int GetHashCode(HashBucket obj) => throw new NotSupportedException();
+ _hashBucketEqualityComparer = GetHashBucketEqualityComparer(equalityComparer);
}
/// <summary>
@@ -1058,6 +1008,27 @@ namespace System.Collections.Immutable
}
/// <summary>
+ /// Gets the <see cref="IEqualityComparer{HashBucket}"/> to use.
+ /// </summary>
+ /// <param name="valueComparer">The value comparer for T.</param>
+ /// <returns>The equality comparer to use.</returns>
+ private static IEqualityComparer<HashBucket> GetHashBucketEqualityComparer(IEqualityComparer<T> valueComparer)
+ {
+ if (!typeof(ValueType).IsAssignableFrom(typeof(T)))
+ {
+ return HashBucketByRefEqualityComparer.DefaultInstance;
+ }
+ else if (valueComparer == EqualityComparer<T>.Default)
+ {
+ return HashBucketByValueEqualityComparer.DefaultInstance;
+ }
+ else
+ {
+ return new HashBucketByValueEqualityComparer(valueComparer);
+ }
+ }
+
+ /// <summary>
/// Wraps the specified data structure with an immutable collection wrapper.
/// </summary>
/// <param name="root">The root of the data structure.</param>