Extend D's switch statement?
Dmitry Olshansky via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jul 8 15:26:11 PDT 2015
On 09-Jul-2015 00:26, Martin Nowak wrote:
> On 07/08/2015 08:06 PM, Yuxuan Shui wrote:
>>> switch(x.toHash()){
>>> case a.toHash():
>>> if(x!=a) goto default;
>>> ...;
>>> break;
>>> case b.toHash():
>>> if(x!=b) goto default;
>>> ...;
>>> break;
>>> default: break;
>>> }
>>>
>>> (a and b are known at compile time here, and so are their hash values.
>>> Hash collisions between e.g. a and b would need to be dealt with of
>>> course.)
>>
>> Yes, this is what I meant.
>
> Very interesting. How would you deal with collisions?
> You can already do some nice things during compile time, e.g. creating
> perfect hash functions and lookup table, but it doesn't seem to be
> possible to achieve what you suggest.
>
In the worst case just if-else chain collided items per hash value?
Given that in this case it may use the full range of size_t I won't
expect high collision rates.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list