Sieve of Pritchard: Difference between revisions

→‎C#: Small shortcut, explanation expanded
(→‎C#: Limit on wheel expansion was incorrect. Old version had proper output, but went about it in the wrong way.)
(→‎C#: Small shortcut, explanation expanded)
Line 29:
=={{header|C#|CSharp}}==
Loosely based on the Python version. I cut a couple of things out and it still worked. Not too crazy about having to create temporary lists to add or remove from the SortedSet, seems inefficient. But that is the work-around I employed, since SortedSets can't be accessed by indexing, and are non-mutable in a foreach loop. I haven't yet directly tested this against a Sieve of Eratosthenes to compare performance. The Wikipedia article suggests using a doubly linked list, so this C# incarnation is a kludge at best.
 
Compared to the prototype algorithm, it appears there isn't any code to do the follow-up end-of-wheel additions when necessary. But the main loop limit has been changed to go to the next prime, and the existing code handles the additions.
<syntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
Line 46 ⟶ 48:
members.UnionWith(nu);
}
stp = Math.Min(primenl; *// stp,update wheel size to wheel limit);
nxtpr = 0; // for obtaining the next prime
var wb = new List<int>();