Quantcast
Viewing all articles
Browse latest Browse all 20

Source code checked in, #5763

MicroLinq.OrderBy: Yet another change to the sorting algorithm! As suggested by Corey Kosak, we no longer take a count twice of the IEnumerable to sort. His argument was that there was no way to ensure the enumerable didn't change between the first count to get size for the target, and then the actual iteration to perform the sort. The IEnumerable might be volatile and the iteration process itself could cause it to change. The new order of execution is: try to cast to ICollection and if this works, copy the array into the target using native code; otherwise use an ArrayList and iterate the source collection and store it into the target. Perform merge sort on target. Return target. This means the source is iterated exactly once and isn't modified by the sorting. I did as much as I could to ensure native methods were used. Performance should be on-par with the last build but instead of worst-case being O(n^2) we're down to O(n log n) - I think. (Wikipedia) Merge sort is apparently the default in many higher level languages. As above, so below.

Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>