namespace HKW.HKWUtils;
///
/// 哈希值
///
public class HashCode
{
///
/// 默认种子
///
public const int DefaultSeed = 114514;
///
/// 默认系数
///
public const int DefaultFactor = 1919810;
///
/// 组合哈希值
///
/// 值
/// 组合的哈希值
public static int Combine(params object[] values)
{
return CustomHash(DefaultSeed, DefaultFactor, values.Select(v => v.GetHashCode()));
}
///
/// 组合哈希值
///
/// 种子
/// 系数
/// 值
/// 组合的哈希值
public static int Combine(int seed, int factor, params object[] values)
{
return CustomHash(seed, factor, values.Select(v => v.GetHashCode()));
}
///
/// 自定义组合哈希
///
/// 种子
/// 系数
/// 哈希集合
/// 组合的哈希
public static int CustomHash(int seed, int factor, IEnumerable collection)
{
int hash = seed;
foreach (int i in collection)
hash = unchecked((hash * factor) + i);
return hash;
}
///
/// 自定义组合哈希
///
/// 种子
/// 系数
/// 哈希集合
/// 组合的哈希
public static int CustomHash(int seed, int factor, params int[] values)
{
return CustomHash(seed, factor, collection: values);
}
}