AstarChecksum.cs 579 B

123456789101112131415161718192021
  1. using System;
  2. namespace Pathfinding.Util {
  3. /// <summary>Calculates checksums of byte arrays</summary>
  4. public class Checksum {
  5. /// <summary>
  6. /// Calculate checksum for the byte array starting from a previous values.
  7. /// Useful if data is split up between several byte arrays
  8. /// </summary>
  9. public static uint GetChecksum (byte[] arr, uint hash) {
  10. // Sort of implements the Fowler–Noll–Vo hash function
  11. const int prime = 16777619;
  12. hash ^= 2166136261U;
  13. for (int i = 0; i < arr.Length; i++)
  14. hash = (hash ^ arr[i]) * prime;
  15. return hash;
  16. }
  17. }
  18. }