在.NET GetHashCode方法中,很多地方都使用.NET 方法.特别是在快速查找集合中的项目或确定相等性时.是否有关于如何GetHashCode为我的自定义类实现覆盖的标准算法/最佳实践,因此我不会降低性能?
散列过程如何在Dictionary中工作?我读到使用字典提供更快的查找.但是不明白怎么了?散列和映射到索引的方式如何?找不到任何好的参考.
编辑:如何从散列函数的结果中获取存储对象的实际内存位置?
我已经创建了一些类,因此我可以使用一对字典作为键
public class RouteKey
{
public Equip Equipment { get; set; }
public Destiny Destiny { get; set; }
public RouteKey() { }
public RouteKey(Equip Equipment, Destiny Destiny) {
this.Equipment = Equipment;
this.Destiny = Destiny;
}
}
public override bool Equals(object obj)
{
if (obj == null) return false;
if (this.GetType() != obj.GetType()) return false;
RouteKey rk = (RouteKey)obj;
// use this pattern to compare reference members
if (!Object.Equals(Equipment, rk.Equipment)) return false;
// use this pattern to compare value members …Run Code Online (Sandbox Code Playgroud)