Is there a case-insensitive variant of the Bob Jenkins hash function?
Generics.Defaults.BobJenkinsHash
provides a fast hash function. Unfortunately it cannot be used in combination with a case-insensitive compare function like so
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;
This is because TDictionary first compares the hash codes and then uses the provided comparer when checking for equality.
Of course I could use UpperCase in my GetHashCode function, but I wondered if it would be faster if I could somehow modify the hash function itself.
No, there is no case invariant version of the hash function. Lower or upper case all strings before passing them to the hash function.