/*----------------------------------------------------------------------------*- Function: bernstein Params: string[] - the string to hash. Return: the bernstein hash of the input string Notes: This is a 32bit hash system so is not very secure, however we're only using this as a string enumerator to uniquely identify strings easilly and allow for a binary search of strings based on the hash of their name. crc32, then jenkins were originally used however this is far faster, if a little collision prone, but we're checking the strings manually anyway. This doesn't matter as it would be done regardless of hash method, so this doesn't need to be accounted for. Speed is all that matters with at least a bit of non collision (the number of strings we're dealing with, this should have none-few collisions). I modified it slightly from the original code pasted by aru, to code closer to the code http://www.burtleburtle.net/bob/hash/doobs.html and to work with PAWN (and shaved 0.2µs off the time for one call :D). Uber reduced version (just for fun): b(s[]){new h=-1,i,j;while((j=s[i++]))h=h*33+j;return h;} Update: Contrary to what I said above this is also used to identify colour strings for the updated text system involving file based styling and this is not checked for collisions as it's unimportant. But this doesn't affect the function at all, I just mentioned it here for "interest". -*----------------------------------------------------------------------------*/ stock bernstein(string[]) { new hash = -1, i, j; while ((j = string[i++])) { hash = hash * 33 + j; } return hash; }