Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,11 @@ private static int CalcNumBuckets(ReadOnlySpan<int> hashCodes, bool hashCodesAre
return HashHelpers.GetPrime(uniqueCodesCount);
}

// In our precomputed primes table, find the index of the smallest prime that's at least as large as our number of
// hash codes. If there are more codes than in our precomputed primes table, which accommodates millions of values,
// give up and just use the next prime.
ReadOnlySpan<int> primes = HashHelpers.Primes;
int minPrimeIndexInclusive = 0;
while ((uint)minPrimeIndexInclusive < (uint)primes.Length && minNumBuckets > primes[minPrimeIndexInclusive])
// Beyond the precomputed prime table, GetPrime falls back to trial division,
// so skip the collision-tuning loop and just pick the first prime >= minNumBuckets.
if (minNumBuckets > HashHelpers.MaxPrecomputedPrime)
{
minPrimeIndexInclusive++;
}

if (minPrimeIndexInclusive >= primes.Length)
{
return HashHelpers.GetPrime(uniqueCodesCount);
return HashHelpers.GetPrime((int)minNumBuckets);
}

// Determine the largest number of buckets we're willing to use, based on a multiple of the number of inputs.
Expand All @@ -220,32 +212,18 @@ private static int CalcNumBuckets(ReadOnlySpan<int> hashCodes, bool hashCodesAre
uniqueCodesCount *
(uniqueCodesCount >= LargeInputSizeThreshold ? MaxLargeBucketTableMultiplier : MaxSmallBucketTableMultiplier);

// Find the index of the smallest prime that accommodates our max buckets.
int maxPrimeIndexExclusive = minPrimeIndexInclusive;
while ((uint)maxPrimeIndexExclusive < (uint)primes.Length && maxNumBuckets > primes[maxPrimeIndexExclusive])
{
maxPrimeIndexExclusive++;
}

if (maxPrimeIndexExclusive < primes.Length)
{
Debug.Assert(maxPrimeIndexExclusive != 0);
maxNumBuckets = primes[maxPrimeIndexExclusive - 1];
}

const int BitsPerInt32 = 32;
int[] seenBuckets = ArrayPool<int>.Shared.Rent((maxNumBuckets / BitsPerInt32) + 1);

int bestNumBuckets = maxNumBuckets;
int bestNumCollisions = uniqueCodesCount;
int numBuckets = 0, numCollisions = 0;

// Iterate through each available prime between the min and max discovered. For each, compute
// the collision ratio.
for (int primeIndex = minPrimeIndexInclusive; primeIndex < maxPrimeIndexExclusive; primeIndex++)
// Iterate through each prime between minNumBuckets and maxNumBuckets, computing the collision ratio for each.
for (numBuckets = HashHelpers.GetPrime((int)minNumBuckets);
numBuckets <= maxNumBuckets;
numBuckets = HashHelpers.GetPrime(numBuckets + 1))
{
// Get the number of buckets to try, and clear our seen bucket bitmap.
numBuckets = primes[primeIndex];
Array.Clear(seenBuckets, 0, Math.Min(numBuckets, seenBuckets.Length));

// Determine the bucket for each hash code and mark it as seen. If it was already seen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// h1(key) + i*h2(key), 0 <= i < size. h2 and the size must be relatively prime.
// We prefer the low computation costs of higher prime numbers over the increased
// memory allocation of a fixed prime number i.e. when right sizing a HashSet.
internal static ReadOnlySpan<int> Primes =>
private static ReadOnlySpan<int> Primes =>
[
3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591,
Expand All @@ -37,6 +37,11 @@
1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369
];

/// <summary>The largest prime in the precomputed <see cref="Primes"/> table.</summary>
/// <remarks><see cref="GetPrime"/> uses trial division for values beyond this threshold.</remarks>
internal static int MaxPrecomputedPrime => Primes[^1];

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-arm checked CoreCLR_ReleaseLibraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-arm checked CoreCLR_ReleaseLibraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTestsCoreCLR)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTestsCoreCLR)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-arm64 checked CoreCLR_ReleaseLibraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-arm64 checked CoreCLR_ReleaseLibraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 checked CoreCLR_ReleaseLibraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 checked CoreCLR_ReleaseLibraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug CoreCLR_Libraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug CoreCLR_Libraries)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_WithPackages)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_WithPackages)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_WithPackages)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_WithPackages)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_WithPackages)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0518: (NETCORE_ENGINEERING_TELEMETRY=Build) Predefined type 'System.Index' is not defined or imported

Check failure on line 42 in src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs#L42

src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs(42,59): error CS0656: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing compiler required member 'System.Index..ctor'

/// <summary>Checks whether <paramref name="candidate"/> is prime, using trial division up to sqrt(candidate).</summary>
public static bool IsPrime(int candidate)
{
if ((candidate & 1) != 0)
Expand All @@ -52,6 +57,8 @@
return candidate == 2;
}

/// <summary>Returns the smallest prime greater than or equal to <paramref name="min"/>.</summary>
/// <remarks>Uses a precomputed table for small values; falls back to trial division for larger values. Very fast for all realistic hash table sizes.</remarks>
public static int GetPrime(int min)
{
if (min < 0)
Expand All @@ -72,7 +79,8 @@
return min;
}

// Returns size of hashtable to grow to.
/// <summary>Returns the next prime to grow a hash table to, currently using a 2x growth policy.</summary>
/// <remarks>Caps at <see cref="MaxPrimeArrayLength"/> to stay within array length limits.</remarks>
public static int ExpandPrime(int oldSize)
{
int newSize = 2 * oldSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static partial class HashHelpers
// h1(key) + i*h2(key), 0 <= i < size. h2 and the size must be relatively prime.
// We prefer the low computation costs of higher prime numbers over the increased
// memory allocation of a fixed prime number i.e. when right sizing a HashSet.
public static ReadOnlySpan<int> Primes =>
private static ReadOnlySpan<int> Primes =>
[
3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591,
Expand All @@ -29,6 +29,7 @@ internal static partial class HashHelpers
1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369
];

/// <summary>Checks whether <paramref name="candidate"/> is prime, using trial division up to sqrt(candidate).</summary>
public static bool IsPrime(int candidate)
{
if ((candidate & 1) != 0)
Expand All @@ -44,6 +45,8 @@ public static bool IsPrime(int candidate)
return (candidate == 2);
}

/// <summary>Returns the smallest prime greater than or equal to <paramref name="min"/>.</summary>
/// <remarks>Uses a precomputed table for small values; falls back to trial division for larger values. Very fast for all realistic hash table sizes.</remarks>
public static int GetPrime(int min)
{
if (min < 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ObjectIDGenerator
public ObjectIDGenerator()
{
_currentCount = 1;
_currentSize = 3; // HashHelpers.Primes[0]
_currentSize = 3; // Smallest prime > 1
_ids = new long[_currentSize * NumBins];
_objs = new object[_currentSize * NumBins];
}
Expand Down
Loading