On 13-07-02 09:15 AM, Patrick Walton wrote:
> On 7/2/13 8:45 AM, Michael Neumann wrote:
>> Am 02.07.2013 17:29, schrieb Alex Crichton:
>>>> I was looking for something like: static h:HashMap<K,C> =
>>>> {(K,V),(K,V).....}.
>>>> Is this possible at all?
>>
>> What would be much easier is to use a sorted array and binary search for
>> lookup.
>> But sorting at compile time seams to be tricky, for simple values ok,
>> but for more
>> complex keys I think it's impossible.
>
> A procedural macro (what we call a syntax extension) could do it. I've
> been thinking for a while that we should have such a syntax extension in
> the compiler. This is needed in Servo for "pre-interned identifiers":
> think well-known DOM attributes like "id" or HTML elements like "img".
Yeah. Though you might also want a static hash table combined with
gperf[1]-like functionality. For keyword sets and static lookup tables,
it's quite reasonable. I've assumed we'd grow a syntax extension for
this for a while.
I imagine the hashmap code could be abstracted some to handle lookups
over bucket-iterators, in which case it could be recycled between static
and dynamic hashmaps.
-Graydon
[1] https://www.gnu.org/software/gperf/manual/gperf.html
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev