在.NET GetHashCode
方法中,很多地方都使用.NET 方法.特别是在快速查找集合中的项目或确定相等性时.是否有关于如何GetHashCode
为我的自定义类实现覆盖的标准算法/最佳实践,因此我不会降低性能?
我使用C#HastSet和LINQ的Join方法遇到了一些奇怪的行为,我不明白.我已经简化了我正在做的事情,以帮助专注于我所看到的行为.
我有以下内容:
private HashSet<MyClass> _mySet; // module level
IEnumerable<ISearchKey> searchKeys; // parameter.
// Partial key searches are allowed.
private IEqualityComparer<ICoreKey> _coreKeyComparer; // Module level.
// Compares instances of MyClass and ISearchKey to determine
// if they match.
Run Code Online (Sandbox Code Playgroud)
{searchKey_a, myClass_a1},
{searchKey_a, myClass_a2},
{searchKey_a, myClass_a3},
{searchKey_b, myClass_b1},
{searchKey_b, myClass_b2},
{searchKey_c, myClass_c1},
{searchKey_c, myClass_c2},
{searchKey_c, myClass_c3},
{searchKey_c, myClass_c4},
etc....
Run Code Online (Sandbox Code Playgroud)
ie同一个ISearchKey实例会多次出现,一次为它所连接的每个匹配的MyClass实例.
var matchedPairs = searchKeys
.Join(
_mySet,
searchKey => searchKey,
myClass => …
Run Code Online (Sandbox Code Playgroud) .net ×1
algorithm ×1
c# ×1
gethashcode ×1
hashcode ×1
hashset ×1
inner-join ×1
join ×1
linq ×1