I sort the list of objects by their integer identifiers in parallel using OrderBy . I have several objects with the same identifier and need sorting to be stable.
According to Microsoft documentation , parallelized OrderBy unstable, but there is an implementation approach to make it stable. However, I cannot find an example of this.
var list = new List<pair>() { new pair("a", 1), new pair("b", 1), new pair("c", 2), new pair("d", 3), new pair("e", 4) }; var newList = list.AsParallel().WithDegreeOfParallelism(4).OrderBy<pair, int>(p => p.order); private class pair { private String name; public int order; public pair (String name, int order) { this.name = name; this.order = order; } }
Joe w source share