1- unit OneBRC ;
1+ unit Baseline.Delphi ;
22
33interface
44
55uses
6- System.Classes, System.Generics.Collections;
6+ System.Classes
7+ , System.Generics.Collections
8+ ;
79
810type
9- // alias, to easily try various types (Int64, Currency, Double)
10- // due to rounding problems during the average calculation,
11- // and the mismatch between Delphi and Lazarus.
11+ // alias, to easily try various types (Int64, Currency, Double)
12+ // due to rounding problems during the average calculation,
13+ // and the mismatch between Delphi and Lazarus.
1214 TAmount = Int64;
1315
14- { TWeatherStation }
16+ { TWeatherStation }
1517 PWeatherStation = ^TWeatherStation;
1618 TWeatherStation = record
1719 FStation: string;
@@ -21,28 +23,31 @@ TWeatherStation = record
2123 FCnt: Integer;
2224 end ;
2325
24- { TBaseline }
26+ { TBaseline }
2527 TBaseline = class
2628 private
2729 FInputFile: String;
2830 FStationNames: TStringList;
2931 FHashStationList: TDictionary<string, PWeatherStation>;
3032 procedure AddToHashList (AStation: String; ATemp: TAmount);
3133 procedure BuildHashList ;
32- function RoundEx (x: Currency): Double;
3334 protected
3435 public
3536 constructor Create (AInputFile: String);
3637 destructor Destroy; override;
3738
3839 procedure Generate ;
39- end ;
40+ end ;
4041
4142
4243implementation
4344
4445uses
45- System.SysUtils, System.StrUtils, System.Math;
46+ System.SysUtils
47+ , System.StrUtils
48+ , System.Math
49+ , Baseline.Common
50+ ;
4651
4752
4853function Compare (AList: TStringList; AIndex1, AIndex2: Integer): Integer;
@@ -63,7 +68,6 @@ function Compare (AList: TStringList; AIndex1, AIndex2: Integer): Integer;
6368 end ;
6469end ;
6570
66- // ---------------------------------------------------
6771{ TBaseline }
6872
6973constructor TBaseline.Create (AInputFile: String);
@@ -81,7 +85,8 @@ destructor TBaseline.Destroy;
8185var
8286 iStation: PWeatherStation;
8387begin
84- for iStation in FHashStationList.Values do begin
88+ for iStation in FHashStationList.Values do
89+ begin
8590 Dispose(iStation);
8691 end ;
8792 FStationNames.Free;
@@ -93,8 +98,8 @@ procedure TBaseline.AddToHashList(AStation: String; ATemp: TAmount);
9398var
9499 vWeatherStation: PWeatherStation;
95100begin
96- // on Delphi, the below station returns a different average from the baseline.output provided
97- // this issue was resolved after
101+ // on Delphi, the below station returns a different average from the baseline.output provided
102+ // this issue was resolved after
98103// if aStation = 'Danau Kändimarg' then begin
99104// FProblematicSum := FProblematicSum + aTemp;
100105// Inc (FProblematicCount);
@@ -156,11 +161,6 @@ procedure TBaseline.BuildHashList;
156161 end ;
157162end ;
158163
159- function TBaseline.RoundEx (x: Currency): Double;
160- begin
161- Result := Ceil(x * 10 ) / 10 ;
162- end ;
163-
164164procedure TBaseline.Generate ;
165165var
166166 index: Integer;
@@ -170,23 +170,27 @@ procedure TBaseline.Generate;
170170 mean: Double;
171171 weatherStation: PWeatherStation;
172172 iStation: string;
173+ { $IFDEF DEBUG}
173174 vStream: TStringStream;
175+ { $ENDIF}
174176begin
175177 BuildHashList;
176178 FStationNames.BeginUpdate;
177- for iStation in FHashStationList.Keys do begin
179+ for iStation in FHashStationList.Keys do
180+ begin
178181 FHashStationList.TryGetValue(iStation, weatherStation);
179182 Min := weatherStation^.FMin/10 ;
180183 Max := weatherStation^.FMax/10 ;
181- Mean := RoundEx (weatherStation^.FTot/weatherStation^.FCnt/10 );
184+ Mean := RoundExDouble (weatherStation^.FTot/weatherStation^.FCnt/10 );
182185 strTemp := weatherStation^.FStation + ' =' + FormatFloat(' 0.0' , Min) + ' /' + FormatFloat(' 0.0' , Mean) + ' /' + FormatFloat(' 0.0' , Max) + ' ,' ;
183186 FStationNames.Add(strTemp);
184187 end ;
185188 FStationNames.EndUpdate;
186189 FStationNames.CustomSort(Compare);
187190
188191 strTemp:= ' ' ;
189- for index:= 0 to FStationNames.Count - 1 do begin
192+ for index:= 0 to FStationNames.Count - 1 do
193+ begin
190194 strTemp:= strTemp + FStationNames[index] + ' ' ;
191195 end ;
192196 SetLength(strTemp, Length(strTemp) - 2 );
0 commit comments