4 ms·
> I mean at least cut the iterations in half by not iterating over the entire range in the inner loop! The reason I wrote it that way is because the actual co
by cogman10 2y ago
> I mean at least cut the iterations in half by not iterating over the entire range in the inner loop!
The reason I wrote it that way is because the actual common way I find this is in Java where the team wants to use the `stream` api.
IE
items.stream()
.filter((item)->items.stream()
.filter((item2)->item2 != item)
.findAny((item2)->Object.equals(item.foo, item2.foo)).isPresent())
.toList();
That's not really super readable or universalizable to other languages.
Even more commonly, instead of doing the `findAny` I often see the trip up being someone doing a `contains` or other O(n) operations on `List` objects inside iterations of that list.
It's this sort of fluent/functional style of programming that often seems to get tripped up on doing n^2 (or more) algorithms.