| |
 | Posted by Philippe Sigaud | Permalink Reply |
|
Philippe Sigaud 
| On Thu, Nov 14, 2013 at 9:31 PM, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
> On 11/14/13, Philippe Sigaud <philippe.sigaud@gmail.com> wrote:
> - I'd greatly like for those sets or hash tables to be
>> CTFE-compatible.
>
> Well if it's only used in CTFE, I'd imagine a simple struct wrapping an array and doing "!canFind" when adding elements would do the job, no?
The trick is, I don't use them only during CT evaluation. In that
case, yes, linear search would do the trick.
But my code is used at runtime and also, from time to time, during
compilation (a new Pegged parser engine).
Hence my need.
But no worries, I spent the day writing and testing code for a small set/hash implementation. It supports user-defined types (it automatically creates a reasonable hashing function), support sets of sets (unlike AA which do not accept other AA as keys) and is both runtime and compile-time compatible. It's a bit slower than the builtin, but I'm using the code only to generate other code, not in performance-critical code.
I also wrote a small string mixin that generates a big switch statement and it's 40% faster than a standard AA. That's fun. Not useful, mind, but fun.
|