Hi,
In my first forays into my engine development I’ve found it necessary to come up with my own simple hashed string implementation. I plan on using this in place of strings wherever possible for identifiers of objects or for storage. My requirements are fairly simple, I want to have an implementation that resolves a string to an unsigned integer. In debug I want to be able to identify the string in the debugger so I have a debug only char array that is used to store the original string when passed in.
For my hash functions I used the code from General Purpose Hash Functions. I haven’t looked at the hashing algorithms in much detail, a lot of the math looks above my head. I chose the DJB hash function as it is described as being one of the most efficient hashing algorithms ever produced.
One of the things I haven’t considered as of yet is that collisions may be possible. I’ll have to look at the various hashing implementations and pick the one that looks to be the best choice and come up with a system to cope with clashes. This will probably involve doing some tests on a wide range of strings, for now however I don’t have many strings and so my implementation will suffice.
Below are the header and implementation of my HashString along with the HashFunctions found at the link above. You may need to fiddle with them slightly to get them working for your purposes but they’re largely for illustration purposes anyway. These are provided as is, I may find bugs and will endeavour to reupload the fixes.
GeneralHashFunctions.c
HashedString.h
GeneralHashFunctions.h
