Fowler–Noll–Vo is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Phong Vo.
It is very simple to implement, and very fast. The FNV hash can come in several different sizes, 32-, 64-, 128-bit etc. See http://www.isthe.com/chongo/tech/comp/fnv/index.html for more information.
There are two versions of the hash, FNV-1 and FNV-1a. For all purposes the FNV-1a hash is recommended.
The basic algorithm of the FNV-1a hash is:
- hash = FNV_offset_basis
- for each octet_of_data to be hashed
- hash = hash XOR octet_of_data
- hash = hash FNV_prime
- return hash
String.charCodeAt returns a 16-bit value and so has to be treated as two octets/bytes of data.
This implementation is the 32-bit FNV-1a hash.