-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54574 from sharwell/segmented-hashset
✨ Implement SegmentedHashSet<T>
- Loading branch information
Showing
12 changed files
with
3,564 additions
and
7 deletions.
There are no files selected for viewing
616 changes: 616 additions & 0 deletions
616
src/Compilers/Core/CodeAnalysisTest/Collections/HashSet/ISet_Generic_Tests`1.cs
Large diffs are not rendered by default.
Oops, something went wrong.
201 changes: 201 additions & 0 deletions
201
src/Compilers/Core/CodeAnalysisTest/Collections/HashSet/SegmentedHashSet_Generic_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
// 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. | ||
|
||
// NOTE: This code is derived from an implementation originally in dotnet/runtime: | ||
// https://github.com/dotnet/runtime/blob/v5.0.7/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.cs | ||
// | ||
// See the commentary in https://github.com/dotnet/roslyn/pull/50156 for notes on incorporating changes made to the | ||
// reference implementation. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.CodeAnalysis.Collections; | ||
|
||
namespace Microsoft.CodeAnalysis.UnitTests.Collections | ||
{ | ||
public class SegmentedHashSet_Generic_Tests_string : SegmentedHashSet_Generic_Tests<string> | ||
{ | ||
protected override string CreateT(int seed) | ||
{ | ||
int stringLength = seed % 10 + 5; | ||
Random rand = new Random(seed); | ||
byte[] bytes = new byte[stringLength]; | ||
rand.NextBytes(bytes); | ||
return Convert.ToBase64String(bytes); | ||
} | ||
} | ||
|
||
public class SegmentedHashSet_Generic_Tests_int : SegmentedHashSet_Generic_Tests<int> | ||
{ | ||
protected override int CreateT(int seed) | ||
{ | ||
Random rand = new Random(seed); | ||
return rand.Next(); | ||
} | ||
|
||
protected override bool DefaultValueAllowed => true; | ||
} | ||
|
||
public class SegmentedHashSet_Generic_Tests_int_With_Comparer_WrapStructural_Int : SegmentedHashSet_Generic_Tests<int> | ||
{ | ||
protected override IEqualityComparer<int> GetIEqualityComparer() | ||
{ | ||
return new WrapStructural_Int(); | ||
} | ||
|
||
protected override IComparer<int> GetIComparer() | ||
{ | ||
return new WrapStructural_Int(); | ||
} | ||
|
||
protected override int CreateT(int seed) | ||
{ | ||
Random rand = new Random(seed); | ||
return rand.Next(); | ||
} | ||
|
||
protected override ISet<int> GenericISetFactory() | ||
{ | ||
return new SegmentedHashSet<int>(new WrapStructural_Int()); | ||
} | ||
} | ||
|
||
public class SegmentedHashSet_Generic_Tests_int_With_Comparer_WrapStructural_SimpleInt : SegmentedHashSet_Generic_Tests<SimpleInt> | ||
{ | ||
protected override IEqualityComparer<SimpleInt> GetIEqualityComparer() | ||
{ | ||
return new WrapStructural_SimpleInt(); | ||
} | ||
|
||
protected override IComparer<SimpleInt> GetIComparer() | ||
{ | ||
return new WrapStructural_SimpleInt(); | ||
} | ||
|
||
protected override SimpleInt CreateT(int seed) | ||
{ | ||
Random rand = new Random(seed); | ||
return new SimpleInt(rand.Next()); | ||
} | ||
|
||
protected override ISet<SimpleInt> GenericISetFactory() | ||
{ | ||
return new SegmentedHashSet<SimpleInt>(new WrapStructural_SimpleInt()); | ||
} | ||
} | ||
|
||
public class SegmentedHashSet_Generic_Tests_EquatableBackwardsOrder : SegmentedHashSet_Generic_Tests<EquatableBackwardsOrder> | ||
{ | ||
protected override EquatableBackwardsOrder CreateT(int seed) | ||
{ | ||
Random rand = new Random(seed); | ||
return new EquatableBackwardsOrder(rand.Next()); | ||
} | ||
|
||
protected override ISet<EquatableBackwardsOrder> GenericISetFactory() | ||
{ | ||
return new SegmentedHashSet<EquatableBackwardsOrder>(); | ||
} | ||
} | ||
|
||
public class SegmentedHashSet_Generic_Tests_int_With_Comparer_SameAsDefaultComparer : SegmentedHashSet_Generic_Tests<int> | ||
{ | ||
protected override IEqualityComparer<int> GetIEqualityComparer() | ||
{ | ||
return new Comparer_SameAsDefaultComparer(); | ||
} | ||
|
||
protected override int CreateT(int seed) | ||
{ | ||
Random rand = new Random(seed); | ||
return rand.Next(); | ||
} | ||
|
||
protected override ISet<int> GenericISetFactory() | ||
{ | ||
return new SegmentedHashSet<int>(new Comparer_SameAsDefaultComparer()); | ||
} | ||
} | ||
|
||
public class SegmentedHashSet_Generic_Tests_int_With_Comparer_HashCodeAlwaysReturnsZero : SegmentedHashSet_Generic_Tests<int> | ||
{ | ||
protected override IEqualityComparer<int> GetIEqualityComparer() | ||
{ | ||
return new Comparer_HashCodeAlwaysReturnsZero(); | ||
} | ||
|
||
protected override int CreateT(int seed) | ||
{ | ||
Random rand = new Random(seed); | ||
return rand.Next(); | ||
} | ||
|
||
protected override ISet<int> GenericISetFactory() | ||
{ | ||
return new SegmentedHashSet<int>(new Comparer_HashCodeAlwaysReturnsZero()); | ||
} | ||
} | ||
|
||
public class SegmentedHashSet_Generic_Tests_int_With_Comparer_ModOfInt : SegmentedHashSet_Generic_Tests<int> | ||
{ | ||
protected override IEqualityComparer<int> GetIEqualityComparer() | ||
{ | ||
return new Comparer_ModOfInt(15000); | ||
} | ||
|
||
protected override IComparer<int> GetIComparer() | ||
{ | ||
return new Comparer_ModOfInt(15000); | ||
} | ||
|
||
protected override int CreateT(int seed) | ||
{ | ||
Random rand = new Random(seed); | ||
return rand.Next(); | ||
} | ||
|
||
protected override ISet<int> GenericISetFactory() | ||
{ | ||
return new SegmentedHashSet<int>(new Comparer_ModOfInt(15000)); | ||
} | ||
} | ||
|
||
public class SegmentedHashSet_Generic_Tests_int_With_Comparer_AbsOfInt : SegmentedHashSet_Generic_Tests<int> | ||
{ | ||
protected override IEqualityComparer<int> GetIEqualityComparer() | ||
{ | ||
return new Comparer_AbsOfInt(); | ||
} | ||
|
||
protected override int CreateT(int seed) | ||
{ | ||
Random rand = new Random(seed); | ||
return rand.Next(); | ||
} | ||
|
||
protected override ISet<int> GenericISetFactory() | ||
{ | ||
return new SegmentedHashSet<int>(new Comparer_AbsOfInt()); | ||
} | ||
} | ||
|
||
public class SegmentedHashSet_Generic_Tests_int_With_Comparer_BadIntEqualityComparer : SegmentedHashSet_Generic_Tests<int> | ||
{ | ||
protected override IEqualityComparer<int> GetIEqualityComparer() | ||
{ | ||
return new BadIntEqualityComparer(); | ||
} | ||
|
||
protected override int CreateT(int seed) | ||
{ | ||
Random rand = new Random(seed); | ||
return rand.Next(); | ||
} | ||
|
||
protected override ISet<int> GenericISetFactory() | ||
{ | ||
return new SegmentedHashSet<int>(new BadIntEqualityComparer()); | ||
} | ||
} | ||
} |
Oops, something went wrong.