[fpc-pascal] rtl-generics: TIStringComparer.Ordinal -> Access violation

Maciej Izak hnb.code at gmail.com
Wed Aug 17 19:42:12 CEST 2016


2016-08-17 18:45 GMT+02:00 silvioprog <silvioprog at gmail.com>:

> I changed it to a function:
>
>   function ExtendedHasher(constref AValue: string): UInt32;
>   begin
>     TDefaultHashFactory.GetHashList(Pointer(AValue),
>       Length(AValue) * SizeOf(Char), @Result);
>   end;
>

Still bad implementation (see my previous message). Is highly probable to
obtain different hashes for 'foo' and 'Foo'. Usage of GetHashList in that
context is also improper, GetHashList is generally dedicated for more
complicated structures (for example for cuckoo hashing). The proper code is:

  function MyHasher(constref AValue: string): UInt32;
  var
    temp: string;
  begin
    temp := LowerCase(AValue);
    Result := TDefaultHashFactory.GetHashCode(Pointer(temp), Length(temp) *
SizeOf(Char), 0);
  end;


> because the "Error: Incompatible type for arg no. 2: Got
> "ExtendedHasher(constref AnsiString;PDWord);", expected "<procedure
> variable type of function(constref AnsiString):DWord;Register>"".
>
>
Point for you, that was code from my memory, sorry ;) ExtendedHasher in
presented form is dedicated for TExtendedEqualityComparer<T>.Construct(...)
which is used for THashMap<K,V> (THashMap is much faster than TDictionary
for big data)

-- 
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160817/c549ecb6/attachment.html>


More information about the fpc-pascal mailing list