PJW Hash

PJW is a hash function algorithm.



									public static uint PJWHash(string str)
{
	const uint BitsInUnsignedInt = (uint)(sizeof(uint) * 8);
	const uint ThreeQuarters = (uint)((BitsInUnsignedInt * 3) / 4);
	const uint OneEighth = (uint)(BitsInUnsignedInt / 8);
	const uint HighBits = (uint)(0xFFFFFFFF) << (int)(BitsInUnsignedInt - OneEighth);
	uint hash = 0;
	uint test = 0;
	uint i = 0;

	for (i = 0; i < str.Length; i++)
	{
		hash = (hash << (int)OneEighth) + ((byte)str[(int)i]);

		if ((test = hash & HighBits) != 0)
		{
			hash = ((hash ^ (test >> (int)ThreeQuarters)) & (~HighBits));
		}
	}

	return hash;
}
								


Example

									string data = "jdfgsdhfsdfsd 6445dsfsd7fg/*/+bfjsdgf%$^";
uint value = PJWHash(data);
								


Output

									248446350