Suggestion: Operator `in` for slices

Quirin Schroll qs.il.paperinik at gmail.com
Sat Dec 18 20:17:51 UTC 2021


On Saturday, 18 December 2021 at 18:47:33 UTC, Adam Ruppe wrote:
> On Saturday, 18 December 2021 at 18:29:56 UTC, Quirin Schroll 
> wrote:
>> I guess it has never been implemented because this information 
>> (true/false) is so much less than it could be.
>
> Nah, the general rule against it is due to speed/computational 
> complexity. The `in` operator on AAs has a speed of O(log n) or 
> O(1). `in` on slices would exceed that being O(n).

How is that even a criterion? `foreach` on arrays has O(n) 
complexity as well. You cannot say it's okay for `foreach` 
because it obviously has to be that way. The same can be said for 
linear search. It doesn't take a genius that searching an 
unordered structure cannot be better than O(n) in the worst case.


More information about the Digitalmars-d mailing list