Sets again

Lionello Lunesu lio at remove.lunesu.com
Sun Feb 19 23:54:14 PST 2006


> How about in for arrays for consistency with AA's:
>
> void foo(char[] )
> {
> char[] arr = "abcdef";
> //...
> if('d' in arr) { ... }
> }
>

NO! Please don't do this. The operation is O(n). If will be useful perhaps 
for "if (day in Weekdays)", but the system is extremely unscalable, and 
using "in" on a larger array will harm performance. I don't think it's a 
good idea to hide such a potential performance hit behind a small word like 
"in".

(In fact, I generally think the costly operations should get long, 
complicated names, so they don't get used too often)

Now if the array were sorted, one could do a binary search, which is not all 
too bad. But this still needs special syntax, since the compiler should 
enforce the sorting.

L. 





More information about the Digitalmars-d mailing list