PrimeOrderCalculator converted to a template.
This commit is contained in:
1 parent
48df3df290
commit
2bf9ff233c
19 files changed
+3407
-4332
No files matched your search
@@ -0,0 +1,34 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace PerfectNumbers.Core;
|
||||
|
||||
public readonly struct PrimeOrderCalculatorConfig(uint smallFactorLimit, int pollardRhoMilliseconds, int maxPowChecks, bool strictMode, int maxSeconds = 0)
|
||||
{
|
||||
private static PrimeOrderCalculatorConfig _heuristicDefault = CreateHeuristicDefault(UnboundedTaskScheduler.ConfiguredThreadCount);
|
||||
|
||||
public static PrimeOrderCalculatorConfig HeuristicDefault
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _heuristicDefault;
|
||||
}
|
||||
|
||||
public static readonly PrimeOrderCalculatorConfig StrictDefault = new(smallFactorLimit: 1_000_000, pollardRhoMilliseconds: 0, maxPowChecks: 0, true);
|
||||
|
||||
public static void ConfigureHeuristicDefault(int threadCount)
|
||||
{
|
||||
_heuristicDefault = CreateHeuristicDefault(threadCount);
|
||||
}
|
||||
|
||||
public static PrimeOrderCalculatorConfig CreateHeuristicDefault(int threadCount)
|
||||
{
|
||||
int normalizedThreadCount = threadCount < 1 ? 1 : threadCount;
|
||||
return new(smallFactorLimit: 100_000, pollardRhoMilliseconds: normalizedThreadCount * 24, maxPowChecks: 24, false);
|
||||
}
|
||||
|
||||
public readonly uint SmallFactorLimit = smallFactorLimit;
|
||||
public readonly int PollardRhoMilliseconds = pollardRhoMilliseconds;
|
||||
public readonly int MaxPowChecks = maxPowChecks;
|
||||
public readonly int MaxPowChecksCapacity = maxPowChecks << 2;
|
||||
public readonly bool StrictMode = strictMode;
|
||||
public readonly int MaxSeconds = maxSeconds;
|
||||
}
|
||||
Reference in new issue
Block a user