Consider the following record:
TMyRecord = record
b: Boolean;
// 3 bytes of padding in here with default record alignment settings
i: Integer;
end;
I wish to implement IEqualityComparer<TMyRecord>
. In order to do so I want to call TEqualityComparer<TMyRecord>.Construct
. This needs to be supplied with a TEqualityComparison<TMyRecord>
which presents no problems to me.
However, Construct
also requires a THasher<TMyRecord>
and I would like to know the canonical method for implementing that. The function needs to have the following form:
function MyRecordHasher(const Value: TMyRecord): Integer;
begin
Result := ???
end;
I expect that I need to call BobJenkinsHash
on both fields of the record value and then combine them some how. Is this the right approach, and how should I combine them?
The reason I don't use TEqualityComparison<TMyRecord>.Default
is that it uses CompareMem
and so will be incorrect due to the record's padding.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…