PendingEntry renamed to PartialFactorPendingEntry and moved to its own file. PrimeOrderCalculator.PartialFactor partially optimized to use fixed buffers factors & exponents.
This commit is contained in:
1 parent
8fbe248a49
commit
ec080ade7f
6 files changed
+130
-291
No files matched your search
@@ -0,0 +1,50 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace PerfectNumbers.Core;
|
||||
|
||||
internal sealed class PartialFactorPendingEntry(ulong value, bool knownComposite)
|
||||
{
|
||||
[ThreadStatic]
|
||||
private static PartialFactorPendingEntry? _poolHead;
|
||||
private PartialFactorPendingEntry? _next;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static PartialFactorPendingEntry Rent(ulong value, bool knownComposite)
|
||||
{
|
||||
var poolHead = _poolHead;
|
||||
if (poolHead == null)
|
||||
{
|
||||
return new(value, knownComposite);
|
||||
}
|
||||
|
||||
_poolHead = poolHead._next;
|
||||
poolHead.Value = value;
|
||||
poolHead.KnownComposite = knownComposite;
|
||||
poolHead.HasKnownPrimality = knownComposite;
|
||||
poolHead.IsPrime = false;
|
||||
return poolHead;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static void Return(PartialFactorPendingEntry entry)
|
||||
{
|
||||
entry._next = _poolHead;
|
||||
_poolHead = entry;
|
||||
}
|
||||
|
||||
public ulong Value = value;
|
||||
public bool KnownComposite = knownComposite;
|
||||
public bool HasKnownPrimality = knownComposite;
|
||||
public bool IsPrime = false;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public void WithPrimality(bool isPrime)
|
||||
{
|
||||
KnownComposite = KnownComposite || !isPrime;
|
||||
HasKnownPrimality = true;
|
||||
IsPrime = isPrime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user