How about a Hash template?

Alexander aldem+dmars at nk7.net
Thu Apr 28 03:23:29 PDT 2011


On 28.04.2011 01:10, Andrej Mitrovic wrote:

> I really like the "in" keyword, and I also like hashes since they can
> potentially speed up look-ups compared to conventional arrays.

  The problem is, "potentially" means "for [relatively] large sets", as hashing overhead will kill the benefits for smaller sets.

  For 3, 5, 10 values chained if-then-else (or switch) will be *much* faster, especially for basic types (and strings), especially when values are compared according to frequency of usage.

  Just run a benchmark - you will be surprised :)

  For more than 10 values - I doubt that inline Hash! will be really readable, I would rather define an array somewhere else.

  OTOH, I like the idea of providing list of values "inline" for 'in' operator, this, obviously, improves readability.

/Alexander


More information about the Digitalmars-d mailing list