PendingEntry.WithPrimality changed to modify the instance instead of creating a new one.
This commit is contained in:
1 parent
928e847f1f
commit
cf5bd6bc1a
1 file changed
+12
-11
@@ -12,12 +12,12 @@ namespace PerfectNumbers.Core;
|
|||||||
|
|
||||||
internal static partial class PrimeOrderCalculator
|
internal static partial class PrimeOrderCalculator
|
||||||
{
|
{
|
||||||
internal readonly struct PendingEntry
|
internal struct PendingEntry
|
||||||
{
|
{
|
||||||
public readonly ulong Value;
|
public ulong Value;
|
||||||
public readonly bool KnownComposite;
|
public bool KnownComposite;
|
||||||
public readonly bool HasKnownPrimality;
|
public bool HasKnownPrimality;
|
||||||
public readonly bool IsPrime;
|
public bool IsPrime;
|
||||||
|
|
||||||
public PendingEntry(ulong value, bool knownComposite)
|
public PendingEntry(ulong value, bool knownComposite)
|
||||||
{
|
{
|
||||||
@@ -36,10 +36,11 @@ internal static partial class PrimeOrderCalculator
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public PendingEntry WithPrimality(bool isPrime)
|
public void WithPrimality(bool isPrime)
|
||||||
{
|
{
|
||||||
bool knownComposite = KnownComposite || !isPrime;
|
KnownComposite = KnownComposite || !isPrime;
|
||||||
return new PendingEntry(Value, knownComposite, true, isPrime);
|
HasKnownPrimality = true;
|
||||||
|
IsPrime = isPrime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1932,7 +1933,7 @@ internal static partial class PrimeOrderCalculator
|
|||||||
// Atomic.Add(ref _partialFactorPendingHits, 1UL);
|
// Atomic.Add(ref _partialFactorPendingHits, 1UL);
|
||||||
// Console.WriteLine($"Partial factor pending hits {Volatile.Read(ref _partialFactorPendingHits)}");
|
// Console.WriteLine($"Partial factor pending hits {Volatile.Read(ref _partialFactorPendingHits)}");
|
||||||
|
|
||||||
entry = entry.WithPrimality(isPrime);
|
entry.WithPrimality(isPrime);
|
||||||
pending[index] = entry;
|
pending[index] = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2112,7 +2113,7 @@ internal static partial class PrimeOrderCalculator
|
|||||||
// Atomic.Add(ref _partialFactorPendingHits, 1UL);
|
// Atomic.Add(ref _partialFactorPendingHits, 1UL);
|
||||||
// Console.WriteLine($"Partial factor pending hits {Volatile.Read(ref _partialFactorPendingHits)}");
|
// Console.WriteLine($"Partial factor pending hits {Volatile.Read(ref _partialFactorPendingHits)}");
|
||||||
|
|
||||||
entry = entry.WithPrimality(isPrime);
|
entry.WithPrimality(isPrime);
|
||||||
pending[index] = entry;
|
pending[index] = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2294,7 +2295,7 @@ internal static partial class PrimeOrderCalculator
|
|||||||
// Atomic.Add(ref _partialFactorPendingHits, 1UL);
|
// Atomic.Add(ref _partialFactorPendingHits, 1UL);
|
||||||
// Console.WriteLine($"Partial factor pending hits {Volatile.Read(ref _partialFactorPendingHits)}");
|
// Console.WriteLine($"Partial factor pending hits {Volatile.Read(ref _partialFactorPendingHits)}");
|
||||||
|
|
||||||
entry = entry.WithPrimality(isPrime);
|
entry.WithPrimality(isPrime);
|
||||||
pending[index] = entry;
|
pending[index] = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user