Renaming isPerfect to passedAllTests variables and parameters

This commit is contained in:
Marek Lemańczyk committed 2025-09-19 20:11:48 +02:00
1 parent e3f2cf1f2c
commit 3a3da488b0
2 files changed
+36 -29

No files matched your search

+20 -13
View File
@@ -19,7 +19,7 @@ internal static class Program
"/help" "/help"
}; };
private const string DefaultHeader = "p,searchedMersenne,detailedCheck,isPerfect"; private const string DefaultHeader = "p,searchedMersenne,detailedCheck,passedAllTests";
private static int Main(string[] args) private static int Main(string[] args)
{ {
@@ -89,10 +89,14 @@ internal static class Program
return false; return false;
} }
int index;
string option, optionAndValue, value;
for (int i = 0; i < arguments.Length; i += 2) for (int i = 0; i < arguments.Length; i += 2)
{ {
string option = arguments[i]; optionAndValue = arguments[i];
string value = arguments[i + 1]; index = optionAndValue.IndexOf('=');
option = optionAndValue[..index];
value = optionAndValue[(index + 1)..];
try try
{ {
@@ -149,8 +153,8 @@ internal static class Program
Console.WriteLine("Outputs prime results into four files placed next to the source file:"); Console.WriteLine("Outputs prime results into four files placed next to the source file:");
Console.WriteLine(" raw-primes-<name> - prime entries in the original order"); Console.WriteLine(" raw-primes-<name> - prime entries in the original order");
Console.WriteLine(" sorted-primes-<name> - prime entries sorted by p"); Console.WriteLine(" sorted-primes-<name> - prime entries sorted by p");
Console.WriteLine(" sorted-primes-passed-<name> - sorted prime entries with isPerfect = true"); Console.WriteLine(" sorted-primes-passed-<name> - sorted prime entries with passedAllTests = true");
Console.WriteLine(" sorted-primes-rejected-<name> - sorted prime entries with isPerfect = false"); Console.WriteLine(" sorted-primes-rejected-<name> - sorted prime entries with passedAllTests = false");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Example:"); Console.WriteLine("Example:");
Console.WriteLine(" EvenPerfectBitScanner.ResultsParser results.csv --p-min 89 --p-max 107"); Console.WriteLine(" EvenPerfectBitScanner.ResultsParser results.csv --p-min 89 --p-max 107");
@@ -219,15 +223,17 @@ internal static class Program
} }
List<CandidateResult> sortedResults = [.. primeResults]; List<CandidateResult> sortedResults = [.. primeResults];
Console.WriteLine("Sorting candidates...");
BubbleSort(sortedResults); BubbleSort(sortedResults);
List<CandidateResult> passedResults = []; Console.WriteLine("Splitting results...");
List<CandidateResult> rejectedResults = []; List<CandidateResult> passedResults = new(sortedResults.Count);
List<CandidateResult> rejectedResults = new(sortedResults.Count);
for (int i = 0; i < sortedResults.Count; i++) for (int i = 0; i < sortedResults.Count; i++)
{ {
CandidateResult candidate = sortedResults[i]; CandidateResult candidate = sortedResults[i];
if (candidate.IsPerfect) if (candidate.PassedAllTests)
{ {
passedResults.Add(candidate); passedResults.Add(candidate);
} }
@@ -237,6 +243,7 @@ internal static class Program
} }
} }
Console.WriteLine("Saving files...");
string sortedOutputPath = BuildOutputPath(inputPath, "sorted-primes-"); string sortedOutputPath = BuildOutputPath(inputPath, "sorted-primes-");
string passedOutputPath = BuildOutputPath(inputPath, "sorted-primes-passed-"); string passedOutputPath = BuildOutputPath(inputPath, "sorted-primes-passed-");
string rejectedOutputPath = BuildOutputPath(inputPath, "sorted-primes-rejected-"); string rejectedOutputPath = BuildOutputPath(inputPath, "sorted-primes-rejected-");
@@ -276,10 +283,10 @@ internal static class Program
} }
ReadOnlySpan<char> pSpan = span[..firstCommaIndex]; ReadOnlySpan<char> pSpan = span[..firstCommaIndex];
ReadOnlySpan<char> isPerfectSpan = span[(lastCommaIndex + 1)..]; ReadOnlySpan<char> passedAllTestsSpan = span[(lastCommaIndex + 1)..];
ulong p = ulong.Parse(pSpan, NumberStyles.Integer, CultureInfo.InvariantCulture); ulong p = ulong.Parse(pSpan, NumberStyles.Integer, CultureInfo.InvariantCulture);
bool isPerfect = bool.Parse(isPerfectSpan); bool passedAllTests = bool.Parse(passedAllTestsSpan);
return new CandidateResult(p, isPerfect, trimmedLine); return new CandidateResult(p, passedAllTests, trimmedLine);
} }
private static string BuildOutputPath(string inputPath, string prefix) private static string BuildOutputPath(string inputPath, string prefix)
@@ -475,13 +482,13 @@ internal static class Program
return low; return low;
} }
private readonly record struct CandidateResult(ulong P, bool IsPerfect, string Csv) private readonly record struct CandidateResult(ulong P, bool PassedAllTests, string Csv)
{ {
public string ToCsv() => Csv; public string ToCsv() => Csv;
public readonly string Csv = Csv; public readonly string Csv = Csv;
public readonly ulong P = P; public readonly ulong P = P;
public readonly bool IsPerfect = IsPerfect; public readonly bool PassedAllTests = PassedAllTests;
} }
} }
+16 -16
View File
@@ -476,7 +476,7 @@ internal static class Program
ulong remainder = currentP % 6UL; ulong remainder = currentP % 6UL;
if (currentP == InitialP && string.IsNullOrEmpty(filterFile)) if (currentP == InitialP && string.IsNullOrEmpty(filterFile))
{ {
// bool isPerfect = IsEvenPerfectCandidate(InitialP, out bool searchedMersenne, out bool detailedCheck); // bool passedAllTests = IsEvenPerfectCandidate(InitialP, out bool searchedMersenne, out bool detailedCheck);
// Skip the already processed range below 138 million // Skip the already processed range below 138 million
while (currentP < 138_000_000UL && !Volatile.Read(ref _limitReached)) while (currentP < 138_000_000UL && !Volatile.Read(ref _limitReached))
{ {
@@ -527,9 +527,9 @@ internal static class Program
if (File.Exists(ResultsFileName)) if (File.Exists(ResultsFileName))
{ {
Console.WriteLine("Processing previous results..."); Console.WriteLine("Processing previous results...");
LoadResultsFile(ResultsFileName, (p, detailedCheck, isPerfect) => LoadResultsFile(ResultsFileName, (p, detailedCheck, passedAllTests) =>
{ {
if (detailedCheck && isPerfect) if (detailedCheck && passedAllTests)
{ {
_primeCount++; _primeCount++;
} }
@@ -546,9 +546,9 @@ internal static class Program
if (useFilter) if (useFilter)
{ {
Console.WriteLine("Loading filter..."); Console.WriteLine("Loading filter...");
LoadResultsFile(filterFile, (p, detailedCheck, isPerfect) => LoadResultsFile(filterFile, (p, detailedCheck, passedAllTests) =>
{ {
if (isPerfect) if (passedAllTests)
{ {
Console.WriteLine($"Adding {p}"); Console.WriteLine($"Adding {p}");
filter.Add(p); filter.Add(p);
@@ -597,7 +597,7 @@ internal static class Program
{ {
int count, j; int count, j;
ulong p; ulong p;
bool isPerfect, searchedMersenne, detailedCheck; bool passedAllTests, searchedMersenne, detailedCheck;
ulong[] buffer = new ulong[blockSize]; ulong[] buffer = new ulong[blockSize];
while (!Volatile.Read(ref _limitReached)) while (!Volatile.Read(ref _limitReached))
{ {
@@ -612,8 +612,8 @@ internal static class Program
for (j = 0; j < count && !Volatile.Read(ref _limitReached); j++) for (j = 0; j < count && !Volatile.Read(ref _limitReached); j++)
{ {
p = buffer[j]; p = buffer[j];
isPerfect = IsEvenPerfectCandidate(p, divisorCyclesSearchLimit, out searchedMersenne, out detailedCheck); passedAllTests = IsEvenPerfectCandidate(p, divisorCyclesSearchLimit, out searchedMersenne, out detailedCheck);
PrintResult(p, searchedMersenne, detailedCheck, isPerfect); PrintResult(p, searchedMersenne, detailedCheck, passedAllTests);
} }
} }
else else
@@ -630,8 +630,8 @@ internal static class Program
Console.WriteLine($"Testing {p}"); Console.WriteLine($"Testing {p}");
} }
isPerfect = IsEvenPerfectCandidate(p, divisorCyclesSearchLimit, out searchedMersenne, out detailedCheck); passedAllTests = IsEvenPerfectCandidate(p, divisorCyclesSearchLimit, out searchedMersenne, out detailedCheck);
PrintResult(p, searchedMersenne, detailedCheck, isPerfect); PrintResult(p, searchedMersenne, detailedCheck, passedAllTests);
if (p == maxP) if (p == maxP)
{ {
Volatile.Write(ref _limitReached, true); Volatile.Write(ref _limitReached, true);
@@ -690,11 +690,11 @@ internal static class Program
} }
ReadOnlySpan<char> detailedSpan = span[..third]; ReadOnlySpan<char> detailedSpan = span[..third];
ReadOnlySpan<char> perfectSpan = span[(third + 1)..]; ReadOnlySpan<char> passedAllTestsSpan = span[(third + 1)..];
if (bool.TryParse(detailedSpan, out bool detailed) && bool.TryParse(perfectSpan, out bool isPerfect)) if (bool.TryParse(detailedSpan, out bool detailed) && bool.TryParse(passedAllTestsSpan, out bool passedAllTests))
{ {
lineProcessorAction(p, detailed, isPerfect); lineProcessorAction(p, detailed, passedAllTests);
} }
} }
} }
@@ -790,9 +790,9 @@ internal static class Program
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void PrintResult(ulong currentP, bool searchedMersenne, bool detailedCheck, bool isPerfect) private static void PrintResult(ulong currentP, bool searchedMersenne, bool detailedCheck, bool passedAllTests)
{ {
if (isPerfect) if (passedAllTests)
{ {
int newCount = Interlocked.Increment(ref _primeCount); int newCount = Interlocked.Increment(ref _primeCount);
if (newCount >= 2) if (newCount >= 2)
@@ -813,7 +813,7 @@ internal static class Program
.Append(currentP).Append(',') .Append(currentP).Append(',')
.Append(searchedMersenne).Append(',') .Append(searchedMersenne).Append(',')
.Append(detailedCheck).Append(',') .Append(detailedCheck).Append(',')
.Append(isPerfect).Append('\n'); .Append(passedAllTests).Append('\n');
lock (Sync) lock (Sync)
{ {