Boost logo

Boost :

Subject: Re: [boost] Attn metaprogrammers! [Better Enums] More complete release - feedback requested
From: Anton Bachin (antonbachin_at_[hidden])
Date: 2015-06-08 11:01:22


Whoops! Missed this because of the change in topic.

> 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.

That’s right, for now I am simply doing a linear scan through an array of
strings. Changing the complexity to sub-linear is on my list of things to do,
and I’ve considered those approaches (compile-time binary search, hashing, and
trie). So far, I’ve been focusing on the interface and generation procedure
instead, so I didn’t want to get into too much optimization before I knew
exactly what the constraints would be. It’s getting pretty stable now, so I
would be grateful for any comments/assistance with compile-time data structures.

Regards,
Anton


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk