mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-04 13:50:36 +02:00
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:
parent
2357ca1fe6
commit
dcf172dee4
@ -47,12 +47,7 @@ type
|
|||||||
{ TQuadraticProbing }
|
{ TQuadraticProbing }
|
||||||
|
|
||||||
TQuadraticProbing = class(TProbeSequence)
|
TQuadraticProbing = class(TProbeSequence)
|
||||||
private
|
|
||||||
class constructor Create;
|
|
||||||
public
|
public
|
||||||
class var C1: UInt32;
|
|
||||||
class var C2: UInt32;
|
|
||||||
|
|
||||||
class function Probe(I, Hash: UInt32): UInt32; static; inline;
|
class function Probe(I, Hash: UInt32): UInt32; static; inline;
|
||||||
|
|
||||||
const MAX_LOAD_FACTOR = 0.5;
|
const MAX_LOAD_FACTOR = 0.5;
|
||||||
@ -214,15 +209,9 @@ end;
|
|||||||
|
|
||||||
{ TQuadraticProbing }
|
{ TQuadraticProbing }
|
||||||
|
|
||||||
class constructor TQuadraticProbing.Create;
|
|
||||||
begin
|
|
||||||
C1 := 1;
|
|
||||||
C2 := 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TQuadraticProbing.Probe(I, Hash: UInt32): UInt32;
|
class function TQuadraticProbing.Probe(I, Hash: UInt32): UInt32;
|
||||||
begin
|
begin
|
||||||
Result := (Hash + C1 * I {%H-}+ C2 * Sqr(I));
|
Result := (Hash + Sqr(I));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TDoubleHashingNoMod }
|
{ TDoubleHashingNoMod }
|
||||||
|
Loading…
Reference in New Issue
Block a user