From: beware Date: Mon, 10 Aug 2015 21:45:41 +0000 (+0000) Subject: use better hash function (FNV-1a) X-Git-Url: http://www.lcore.org/git/lcore.git/commitdiff_plain/1a8d0bce39fe4edf7443bde884fefe78412fe521 use better hash function (FNV-1a) git-svn-id: file:///svnroot/lcore/trunk@143 b1de8a11-f9be-4011-bde0-cc7ace90066a --- diff --git a/bsearchtree.pas b/bsearchtree.pas index 9dc355e..9ec804c 100644 --- a/bsearchtree.pas +++ b/bsearchtree.pas @@ -37,18 +37,21 @@ procedure cleartree(t:phashtable); implementation +//FNV-1a hash function function makehash(s:ansistring):integer; const shifter=6; var a,b:integer; + h:longword; begin result := 0; b := length(s); + h := 216613626; for a := 1 to b do begin - result := (result shl shifter) xor byte(s[a]); + h := (h xor byte(s[a])) * 16777619; end; - result := (result xor result shr 16) and (hashtable_size-1); + result := h and (hashtable_size-1); end; procedure addtree(t:phashtable;s:ansistring;item:pointer);