fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. static void Main()
  7. {
  8. int[] ints = { 10001, 10002, 10003, 10004, 10005 };
  9. int hash = GetHashCode(ints);
  10. int[] reorderedInts = { 10004, 10002, 10005, 10001, 10003 };
  11. int reorderedHash = GetHashCode(reorderedInts);
  12.  
  13. Console.WriteLine("hash == {0}", hash);
  14. Console.WriteLine("hashReordered == {0}", reorderedHash);
  15. }
  16.  
  17. static int GetHashCode(IEnumerable<int> integers)
  18. {
  19. int hash = 0;
  20.  
  21. foreach(int integer in integers)
  22. {
  23. int x = integer;
  24.  
  25. x ^= x >> 17;
  26. x *= 830770091; // 0xed5ad4bb
  27. x ^= x >> 11;
  28. x *= -1404298415; // 0xac4c1b51
  29. x ^= x >> 15;
  30. x *= 830770091; // 0x31848bab
  31. x ^= x >> 14;
  32.  
  33. hash += x;
  34. }
  35.  
  36. return hash;
  37. }
  38. }
Success #stdin #stdout 0.02s 131520KB
stdin
Standard input is empty
stdout
hash          == -2145263134
hashReordered == -2145263134