Re:My Favorite Algorithm: Linear Time Median Finding
by davidmurdoch on Friday July 26, 2024 @11:15AM
(#41079299)
Does C# have the plumbing for this built in? It's been 7 years since using it so I might not be remembering correctly.
[ Parent
| on HN ]
Re:My Favorite Algorithm: Linear Time Median Finding
by neonsunset on Friday July 26, 2024 @12:17PM
(#41079854)
IEnumerable<T>.Max and .Min are the same as they were just significantly faster through the use of SIMD: https://github.com/dotnet/runtime/blob/ebbebaca1184940f06df6...
You could implement a similar (and simpler) fast path for types with contiguous memory by performing min and max per iteration instead.
Re:My Favorite Algorithm: Linear Time Median Finding
by davidmurdoch on Saturday July 27, 2024 @10:33AM
(#41086856)
I was thinking LINQ was optimized to do a single enumeration for cases such as this. Can LINQ be easily, naturally, and idiomatically used with `IEnumerable<T>.Max` and `.Min` to avoid looping twice, or is it more of a more rigorous and intentional optimization the engineer would have to seek out?