Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions entries/ghatem-fpc/src/onebrc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface
function RoundExDouble(const ATemp: Double): Double; inline;

const
cDictSize: Integer = 45000;
cDictSize: Integer = 45003;

type

Expand Down Expand Up @@ -128,11 +128,18 @@ function Compare(AList: TStringList; AIndex1, AIndex2: Integer): Integer;

{ TMyDictionary }

const
cHashConst: Double = (Sqrt(5) - 1) / 2;

procedure TMyDictionary.InternalFind(const aKey: Cardinal; out aFound: Boolean; out aIndex: Integer);
var vIdx: Integer;
vDbl: Double;
vOffset: Integer;
begin
vIdx := aKey mod cDictSize;
vDbl := aKey * cHashConst;
vDbl := vDbl - Trunc (vDbl);
vIdx := Trunc (vDbl * cDictSize);

aFound := False;

if FHashes[vIdx] = aKey then begin
Expand Down