aliceif on Nostr: npub1nqp93…mw9sy So funny thing, if you use Linq in C#, OrderBy() followed by ...
npub1nqp93y3l9r4cse4mpqlhuq3mjtctlujgyh8ksx8x57wvzt030epq3mw9sy (npub1nqp…w9sy) So funny thing, if you use Linq in C#, OrderBy() followed by First() actually seems to only do one pass through the list.
So sorting followed by taking the first isn't necessarily even going to do a whole sort
Now i wonder if something like list comprehension in python or libraries like numpy or pandas also do that
Linqpad code sample for C#:
void Main()
{
var random = new Random();
List unsorted = Enumerable.Range(0, 100).Select(x => (x, r: random.Next())).OrderBy(t => t.r).Select(t => new PrinteyNumber { Value = t.x }).ToList();
unsorted.OrderBy(x => x.NoisyValue).First().Dump();
}
// Define other methods and classes here
public class PrinteyNumber
{
private int internalValue;
public int Value { get => internalValue; set => internalValue = value; }
public int NoisyValue
{
get
{
Console.WriteLine(internalValue); return internalValue;
}
}
}
So sorting followed by taking the first isn't necessarily even going to do a whole sort
Now i wonder if something like list comprehension in python or libraries like numpy or pandas also do that
Linqpad code sample for C#:
void Main()
{
var random = new Random();
List unsorted = Enumerable.Range(0, 100).Select(x => (x, r: random.Next())).OrderBy(t => t.r).Select(t => new PrinteyNumber { Value = t.x }).ToList();
unsorted.OrderBy(x => x.NoisyValue).First().Dump();
}
// Define other methods and classes here
public class PrinteyNumber
{
private int internalValue;
public int Value { get => internalValue; set => internalValue = value; }
public int NoisyValue
{
get
{
Console.WriteLine(internalValue); return internalValue;
}
}
}