bearophile wrote:
Andrei Alexandrescu:
I think a best-effort search is not widely useful.<
I meant using a hash search in a hash and a linear search in an
array, etc. And having the same syntax to search in different type of
collections is widely useful.
What evidence do you have that it's widely useful?
Searching an array literal vs. an array variable is not a special
case.<
I can't agree. They are both arrays.
Well I understand you don't agree from the frame you're now in, but you
haven't heard my argument yet. Under such conditions you shouldn't say
"can't"! Here goes my argument.
1. An array literal has no name and cannot be aliased, hence it's
private to the implementation. The implementation is therefore free to
induce structure on the searched elements, e.g. by sorting the array or
using a hash.
2. The size of an array variable must be conservatively assumed to scale
with the size of the input. The size of an array literal scales with the
size of the program, or in the worst case (code generation) with
statically-known inputs to the program.
Andrei