c++ - Compile Time Hashing C++0x -


Using GCC 4.4 (usually available for Android and iOS) is a way to schedule strings.

We have a resource manager that maps to the string key for resources. However the look is fast slow and string construction is slow. Something like this:

  Resource Manager: Get & lt; Texture & gt; ("Some");   

The string spends a lot of time to allocate "something" and then it is sensing it.

I am thinking that there is a trick that I can use to haveh to compile time.

You must apply the correct hashing algorithm, but it does work on C ++ 11: #include & lt; Iostream & gt; // Dummy hashing algorithm adds value of every four in Cstring Constexpr unsigned compile_time_hash (const char * str) {// Modify you as a desire to return (* str == 0)? 0: (* str + compile_time_hash (str + 1)); } Int main () {unsigned some_hash = compile_time_hash ("hallou"); Std :: cout & lt; & Lt; Some_hash & lt; & Lt; Std :: endl; }

Then you can get the source of the resource manager which takes the result of compile_time_hash (an unsigned, in this case) .

It clearly depends on which hushing algorithm you are implementing: Some applications like SAA will be very painful by applying * constexpr

Note that you can use constenpr GCC & gt; = 4.6 or clag & gt; = 3.1 is required.

Comments