Bob Jenkins 哈希函数是否有不区分大小写的变体?
Generics.Defaults.BobJenkinsHash
提供快速哈希函数。不幸的是,它不能与这样的不区分大小写的比较函数结合使用
TCustomStringComparer = class (TEqualityComparer <String>)
function Equals(const Left, Right: String): Boolean; override;
function GetHashCode(const Value: String): Integer; override;
end;
function TCustomStringComparer.Equals (const Left, Right : String) : Boolean;
begin
Result := CompareText (Left, Right) = 0;
end;
function TCustomStringComparer.GetHashCode (const Value : String) : Integer;
begin
Result := Generics.Defaults.BobJenkinsHash (Value [1], Length (Value) * SizeOf (Char), 0);
end;
这是因为 TDictionary 首先比较哈希码,然后在检查相等性时使用提供的比较器。
当然我可以在我的GetHashCode
函数中使用大写,但我想知道如果我能以某种方式修改散列函数本身是否会更快。