From 35579eb567465d3cd5b8c498d5c6fd30de4b0ad2 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Wed, 30 Aug 2017 05:47:39 +0300 Subject: [PATCH] hashtable: StrInt hash --- src/shared/hashtable.pas | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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} -- 2.29.2