From: Ketmar Dark Date: Wed, 30 Aug 2017 02:47:39 +0000 (+0300) Subject: hashtable: StrInt hash X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=35579eb567465d3cd5b8c498d5c6fd30de4b0ad2;p=d2df-sdl.git hashtable: StrInt hash --- diff --git a/src/shared/hashtable.pas b/src/shared/hashtable.pas index f3331d8..531b3a3 100644 --- a/src/shared/hashtable.pas +++ b/src/shared/hashtable.pas @@ -158,8 +158,10 @@ type type THashIntInt = specialize THashBase; + THashStrInt = specialize THashBase; function hashNewIntInt (): THashIntInt; +function hashNewStrInt (): THashStrInt; function u32Hash (a: LongWord): LongWord; inline; @@ -194,6 +196,7 @@ end; // ////////////////////////////////////////////////////////////////////////// // function hiiequ (constref a, b: Integer): Boolean; begin result := (a = b); end; +function hsiequ (constref a, b: AnsiString): Boolean; begin result := (a = b); end; {$PUSH} {$RANGECHECKS OFF} @@ -208,6 +211,11 @@ begin result := result xor (result shl 10); result := result xor (result shr 15); end; + +function hsihash (constref k: AnsiString): LongWord; +begin + if (Length(k) > 0) then result := fnvHash(PAnsiChar(k)^, Length(k)) else result := 0; +end; {$POP} @@ -217,6 +225,12 @@ begin end; +function hashNewStrInt (): THashStrInt; +begin + result := THashStrInt.Create(hsihash, hsiequ); +end; + + // ////////////////////////////////////////////////////////////////////////// // {$PUSH} {$RANGECHECKS OFF}