Hi Anton, Anton Bachin wrote:
I posted to the mailing list some weeks ago concerning a reflective enum library. I've since done a lot of work and made a new release. I'd like to get feedback from anyone that is interested.
The library can be found at: https://github.com/aantron/better-enums
On things that I noticed in your docs is that the complexity of your string-to-enum conversion is linear; presumably you're either creating a sequence of ifs or doing a linear scan through an unsorted array. Making this more efficient would be an interesting challenge for metaprogrammers. I can think of three approaches that you could take: 1. Do a compile-time sort of your strings, so that you can do a binary search on them: 1a - Create a tree of ifs 1b - Create a sorted array of literals 2. Do a compile-time hash of your strings, and switch on the run-time hash. 3. Create a parser containing nested switch statements that parse the string character by character. Since we're reviewing Hana this week, it would be great to see how it could help with this. I have had real applications where this sort of conversion, i.e. essentially wanting to use a string in a switch statement, was a significant performance constraint. Regards, Phil