Sieve of Eratosthenes: Difference between revisions

Content added Content deleted
(Add Draco)
(→‎Tree-merging incremental sieve: no primed names please -- the highlighting is horrendous with those)
Line 8,661: Line 8,661:
_U ((x:xs):t) = x : (merge xs . _U . pairs) t -- tree-shaped folding big union
_U ((x:xs):t) = x : (merge xs . _U . pairs) t -- tree-shaped folding big union
pairs (xs:ys:t) = merge xs ys : pairs t
pairs (xs:ys:t) = merge xs ys : pairs t
merge xs@(x:xs') ys@(y:ys') | x < y = x : merge xs' ys
merge xs@(x:xt) ys@(y:yt) | x < y = x : merge xt ys
| y < x = y : merge xs ys'
| y < x = y : merge xs yt
| otherwise = x : merge xs' ys'</lang>
| otherwise = x : merge xt yt</lang>


Works with odds only, the simplest kind of wheel. Here's the [http://ideone.com/qpnqe test entry] on Ideone.com, and a [http://ideone.com/p0e81 comparison with more versions].
Works with odds only, the simplest kind of wheel. Here's the [http://ideone.com/qpnqe test entry] on Ideone.com, and a [http://ideone.com/p0e81 comparison with more versions].