rtl-generics: speed up quadratic probe function. If the hash table size is a prime number and load factor is < 0.5 then the probe function p(k,i)=(h(k)+sqr(i)) is sufficient.

git-svn-id: trunk@35627 -
This commit is contained in:
maciej-izak 2017-03-19 16:00:11 +00:00
parent 2357ca1fe6
commit dcf172dee4

View File

@ -47,12 +47,7 @@ type
{ TQuadraticProbing }
TQuadraticProbing = class(TProbeSequence)
private
class constructor Create;
public
class var C1: UInt32;
class var C2: UInt32;
class function Probe(I, Hash: UInt32): UInt32; static; inline;
const MAX_LOAD_FACTOR = 0.5;
@ -214,15 +209,9 @@ end;
{ TQuadraticProbing }
class constructor TQuadraticProbing.Create;
begin
C1 := 1;
C2 := 1;
end;
class function TQuadraticProbing.Probe(I, Hash: UInt32): UInt32;
begin
Result := (Hash + C1 * I {%H-}+ C2 * Sqr(I));
Result := (Hash + Sqr(I));
end;
{ TDoubleHashingNoMod }