using System; //----------------------------------------------------------------------------- // Hash // 重点计算字符串的 Hash // 算法及结果, 与 Hash.String.hpp 完全一致 //----------------------------------------------------------------------------- internal static class StringHash32 { private static readonly UInt32 _FNV_offset_basis_32 = 2166136261U; private static readonly UInt32 _FNV_prime_32 = 16777619U; internal static UInt32 From (string name) { var Hash = _FNV_offset_basis_32; foreach (var ch in name) { UInt32 w = ch; Hash ^= w; Hash *= _FNV_prime_32; } return Hash; } } internal static class StringHash64 { private static readonly UInt64 _FNV_offset_basis_64 = 14695981039346656037UL; // 0xcbf29ce484222325 private static readonly UInt64 _FNV_prime_64 = 1099511628211UL; // 0x00000100000001b3 internal static UInt64 From (string name) { var Hash = _FNV_offset_basis_64; foreach (var ch in name) { UInt64 w = ch; Hash ^= w; Hash *= _FNV_prime_64; } return Hash; } }