private static void PostProcess(ref UInt64 h, UInt64[] initValues, ulong dataCount, byte[] remainder) { if (dataCount >= 32) { h = initValues[0].RotateLeft(1) + initValues[1].RotateLeft(7) + initValues[2].RotateLeft(12) + initValues[3].RotateLeft(18); for (var x = 0; x < initValues.Length; ++x) { initValues[x] *= _primes64[1]; initValues[x] = initValues[x].RotateLeft(31); initValues[x] *= _primes64[0]; h ^= initValues[x]; h = (h * _primes64[0]) + _primes64[3]; } } h += (UInt64)dataCount; if (remainder != null) { // In 8-byte chunks, process all full chunks for (int x = 0; x < remainder.Length / 8; ++x) { h ^= (BitConverter.ToUInt64(remainder, x * 8) * _primes64[1]).RotateLeft(31) * _primes64[0]; h = (h.RotateLeft(27) * _primes64[0]) + _primes64[3]; } // Process a 4-byte chunk if it exists if ((remainder.Length % 8) >= 4) { h ^= ((UInt64)BitConverter.ToUInt32(remainder, remainder.Length - (remainder.Length % 8))) * _primes64[0]; h = (h.RotateLeft(23) * _primes64[1]) + _primes64[2]; } // Process last 4 bytes in 1-byte chunks (only runs if data.Length % 4 != 0) for (int x = remainder.Length - (remainder.Length % 4); x < remainder.Length; ++x) { h ^= (UInt64)remainder[x] * _primes64[4]; h = h.RotateLeft(11) * _primes64[0]; } } h ^= h >> 33; h *= _primes64[1]; h ^= h >> 29; h *= _primes64[2]; h ^= h >> 32; }
public void RotateLeftTest() { UInt64 actual = 3421843292831082394UL; UInt64 expected = 17856004537878215074UL; Assert.AreEqual(expected, actual.RotateLeft(4)); }