Difference between revisions of "FNV"
From SimsWiki
(→Overview) |
|||
(2 intermediate revisions by one user not shown) | |||
Line 2: | Line 2: | ||
==Overview== | ==Overview== | ||
− | The | + | The [http://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function Fowler-Noll-Vo hash function] is used in various Sims 3 resources, be it the 32 or 64 bit form, it is used in the generation of property ids, instance ids, bone ids, etc. Occasionally a 24 bit hash will be used, which is just a 32 bit hash with the high byte folded down and XORd with the low byte. |
==Formula== | ==Formula== | ||
The hash is generated with an initial offset, which is multiplied by a prime number and XOR'ed by each byte of data. | The hash is generated with an initial offset, which is multiplied by a prime number and XOR'ed by each byte of data. | ||
+ | |||
+ | '''N.B. When hashing strings, the characters must first be converted to lower-case to comply with standards.''' | ||
<pre> | <pre> | ||
Line 19: | Line 21: | ||
} | } | ||
</pre> | </pre> | ||
+ | |||
==Constants== | ==Constants== | ||
{| border="1" | {| border="1" |
Latest revision as of 05:14, 24 August 2009
FNV hash function
[edit] Overview
The Fowler-Noll-Vo hash function is used in various Sims 3 resources, be it the 32 or 64 bit form, it is used in the generation of property ids, instance ids, bone ids, etc. Occasionally a 24 bit hash will be used, which is just a 32 bit hash with the high byte folded down and XORd with the low byte.
[edit] Formula
The hash is generated with an initial offset, which is multiplied by a prime number and XOR'ed by each byte of data.
N.B. When hashing strings, the characters must first be converted to lower-case to comply with standards.
FNV(byte[] data) { hash = offset; foreach(byte b in data) { hash *= prime; hash ^= b; } return hash; }
[edit] Constants
Bits | Prime | Offset |
---|---|---|
32 | 0x01000193 | 0x811C9DC5 |
64 | 0x00000100000001B3 | 0xCBF29CE484222325 |