New issue 23 by ilya.ind...@gmail.com: Nondeterministic keySelector in
OrderBy
http://code.google.com/p/linqbridge/issues/detail?id=23
Hi,
There is a difference in the implementation of OrderedEnumerable, which
affects the way how keySelector is threated.
Consider the following example:
[Test]
public void OrderByNonDeterministic()
{
var values = "abcd".ToCharArray();
int key = values.Count();
values = values.OrderBy(_ => key--).ToArray();
Assert.AreEqual("dcba", new String(values));
Assert.AreEqual(0, key, "Key for every element is computed only
once");
}
keySelector is evaluated only once for each element in System.Core, and
then resulting key array is sorted.
As an opposite in LinqBridge keySelector is computed for every two elements
being compared. So it produces different result. Even for deterministic
keySelector this can hurt performance.
According to the documentation of OrderBy there are no limitations to the
keySelector function, except that Comparer<TKey>.Default must exist for key
values being returned, if such comparer isn't provided for OrderBy.
Comment #1 on issue 23 by azizatif: Nondeterministic keySelector in OrderBy
http://code.google.com/p/linqbridge/issues/detail?id=23
(No comment was entered for this change.)
Comment #2 on issue 23 by azizatif: Nondeterministic keySelector in OrderBy
http://code.google.com/p/linqbridge/issues/detail?id=23
This issue was closed by revision b09ed8a618f6.