Merge branch 'codex/analyze-gc-instances-in-checkdivisors-method' of https://github.com/mlemanczyk/even-perfect-numbers-scanner into codex/analyze-gc-instances-in-checkdivisors-method
This commit is contained in:
commit
301e715179
1 file changed
+29
-3
@@ -729,14 +729,40 @@ internal static partial class PrimeOrderCalculator
|
|||||||
// We don't need to worry about leftovers, because we always use indexes within the calculated counts
|
// We don't need to worry about leftovers, because we always use indexes within the calculated counts
|
||||||
// primeSlots.Clear();
|
// primeSlots.Clear();
|
||||||
// exponentSlots.Clear();
|
// exponentSlots.Clear();
|
||||||
if (!TryPopulateSmallPrimeFactorsCpu(value, limit, primeSlots, exponentSlots, out factorCount, out remaining))
|
|
||||||
|
counts = ThreadStaticPools.RentUlongIntDictionary(Math.Max(FactorSlotCount, 8));
|
||||||
|
counts.Clear();
|
||||||
|
|
||||||
|
bool gpuPopulated = TryPopulateSmallPrimeFactorsGpu(value, limit, counts, out remaining);
|
||||||
|
if (!gpuPopulated)
|
||||||
{
|
{
|
||||||
useDictionary = true;
|
counts.Clear();
|
||||||
counts = ThreadStaticPools.RentUlongIntDictionary(Math.Max(factorCount, 8));
|
|
||||||
remaining = PopulateSmallPrimeFactorsCpu(value, limit, counts);
|
remaining = PopulateSmallPrimeFactorsCpu(value, limit, counts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dictionaryCount = counts.Count;
|
||||||
|
if (dictionaryCount <= FactorSlotCount)
|
||||||
|
{
|
||||||
|
int copyIndex = 0;
|
||||||
|
foreach (KeyValuePair<ulong, int> entry in counts)
|
||||||
|
{
|
||||||
|
primeSlots[copyIndex] = entry.Key;
|
||||||
|
exponentSlots[copyIndex] = entry.Value;
|
||||||
|
copyIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
factorCount = copyIndex;
|
||||||
|
ThreadStaticPools.ReturnUlongIntDictionary(counts);
|
||||||
|
counts = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
useDictionary = true;
|
||||||
|
factorCount = dictionaryCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (remaining > 1UL)
|
if (remaining > 1UL)
|
||||||
{
|
{
|
||||||
pending.Add(remaining);
|
pending.Add(remaining);
|
||||||
|
|||||||
Reference in new issue
Block a user