11unit uWeatherStations;
22
33{ $mode ObjFPC}{ $H+}
4+ { $R-} { $Q-}
45
56interface
67
@@ -14,7 +15,6 @@ TWSManager = class;
1415 HashBuckets = 1 shl 17 ;
1516
1617type
17- PData = ^TData;
1818 TData = record
1919 FMin: Single;
2020 FMax: Single;
@@ -25,7 +25,7 @@ TData = record
2525
2626 TWS = record
2727 FStation: TBytes;
28- FData: PData ;
28+ FData: TData ;
2929 end ;
3030
3131 TWSList = array [0 ..HashBuckets - 1 ] of TWS;
@@ -248,22 +248,17 @@ constructor TWSThread.Create(ABytes: TBytes; AWSManager: TWSManager);
248248 FMS := TMemoryStream.Create;
249249 for I := Low(FWSList) to High(FWSList) do
250250 begin
251- FWSList[I].FData := nil ;
252- New(FWSList[I].FData);
253- FWSList[I].FData^.FMin := 0 ;
254- FWSList[I].FData^.FMax := 0 ;
255- FWSList[I].FData^.FTot := 0 ;
256- FWSList[I].FData^.FCnt := 0 ;
251+ FWSList[I].FStation := nil ;
252+ FWSList[I].FData.FMin := 0 ;
253+ FWSList[I].FData.FMax := 0 ;
254+ FWSList[I].FData.FTot := 0 ;
255+ FWSList[I].FData.FCnt := 0 ;
257256 end ;
258257end ;
259258
260259destructor TWSThread.Destroy;
261- var
262- I: Integer;
263260begin
264261 FMS.Free;
265- for I := Low(FWSList) to High(FWSList) do
266- Dispose(FWSList[I].FData);
267262 inherited Destroy;
268263end ;
269264
@@ -415,19 +410,19 @@ procedure TWSThread.AddToHashList(AStation: TBytes; ATemp: Single; AHash: QWord)
415410 begin
416411 SetLength(FWSList[Index].FStation, Length(Astation));
417412 Move(Astation[0 ], FWSList[Index].FStation[0 ], Length(Astation));
418- FWSList[Index].FData^ .FMin := Atemp;
419- FWSList[Index].FData^ .FMax := Atemp;
420- FWSList[Index].FData^ .FTot := Atemp;
421- FWSList[Index].FData^ .FCnt := 1 ;
422- FWSList[Index].FData^ .FHash := AHash;
413+ FWSList[Index].FData.FMin := Atemp;
414+ FWSList[Index].FData.FMax := Atemp;
415+ FWSList[Index].FData.FTot := Atemp;
416+ FWSList[Index].FData.FCnt := 1 ;
417+ FWSList[Index].FData.FHash := AHash;
423418 Break;
424419 end ;
425420 if CompareMem(@FWSList[Index].FStation[0 ], @Astation[0 ], Length(Astation)) then
426421 begin
427- FWSList[Index].FData^ .FMin := min(FWSList[Index].FData^ .FMin, Atemp);
428- FWSList[Index].FData^ .FMax := max(FWSList[Index].FData^ .FMax, Atemp);
429- FWSList[Index].FData^ .FTot := FWSList[Index].FData^ .FTot + Atemp;
430- Inc(FWSList[Index].FData^ .FCnt);
422+ FWSList[Index].FData.FMin := min(FWSList[Index].FData.FMin, Atemp);
423+ FWSList[Index].FData.FMax := max(FWSList[Index].FData.FMax, Atemp);
424+ FWSList[Index].FData.FTot := FWSList[Index].FData.FTot + Atemp;
425+ Inc(FWSList[Index].FData.FCnt);
431426 Break;
432427 end ;
433428 Inc(Index);
@@ -444,25 +439,25 @@ procedure TWSThread.UpdateMainHashList;
444439 begin
445440 if FWSList[I].FStation = nil then
446441 Continue;
447- Index := FWSList[I].FData^ .FHash and QWord(HashBuckets - 1 );
442+ Index := FWSList[I].FData.FHash and QWord(HashBuckets - 1 );
448443 while True do
449444 begin
450445 if FWSManager.FWSListAll[Index].FStation = nil then
451446 begin
452447 SetLength(FWSManager.FWSListAll[Index].FStation, Length(FWSList[I].FStation));
453448 Move(FWSList[I].FStation[0 ], FWSManager.FWSListAll[Index].FStation[0 ], Length(FWSList[I].FStation));
454- FWSManager.FWSListAll[Index].FData^ .FMin := FWSList[I].FData^ .FMin;
455- FWSManager.FWSListAll[Index].FData^ .FMax := FWSList[I].FData^ .FMax;
456- FWSManager.FWSListAll[Index].FData^ .FTot := FWSList[I].FData^ .FTot;
457- FWSManager.FWSListAll[Index].FData^ .FCnt := FWSList[I].FData^ .FCnt;
449+ FWSManager.FWSListAll[Index].FData.FMin := FWSList[I].FData.FMin;
450+ FWSManager.FWSListAll[Index].FData.FMax := FWSList[I].FData.FMax;
451+ FWSManager.FWSListAll[Index].FData.FTot := FWSList[I].FData.FTot;
452+ FWSManager.FWSListAll[Index].FData.FCnt := FWSList[I].FData.FCnt;
458453 Break;
459454 end ;
460455 if CompareMem(@FWSManager.FWSListAll[Index].FStation[0 ], @FWSList[I].FStation[0 ], Length(FWSList[I].FStation)) then
461456 begin
462- FWSManager.FWSListAll[Index].FData^ .FMin := min(FWSManager.FWSListAll[Index].FData^ .FMin, FWSList[I].FData^ .FMin);
463- FWSManager.FWSListAll[Index].FData^ .FMax := max(FWSManager.FWSListAll[Index].FData^ .FMax, FWSList[I].FData^ .FMax);
464- FWSManager.FWSListAll[Index].FData^ .FTot := FWSManager.FWSListAll[Index].FData^ .FTot + FWSList[I].FData^ .FTot;
465- FWSManager.FWSListAll[Index].FData^ .FCnt := FWSManager.FWSListAll[Index].FData^ .FCnt + FWSList[I].FData^ .FCnt;
457+ FWSManager.FWSListAll[Index].FData.FMin := min(FWSManager.FWSListAll[Index].FData.FMin, FWSList[I].FData.FMin);
458+ FWSManager.FWSListAll[Index].FData.FMax := max(FWSManager.FWSListAll[Index].FData.FMax, FWSList[I].FData.FMax);
459+ FWSManager.FWSListAll[Index].FData.FTot := FWSManager.FWSListAll[Index].FData.FTot + FWSList[I].FData.FTot;
460+ FWSManager.FWSListAll[Index].FData.FCnt := FWSManager.FWSListAll[Index].FData.FCnt + FWSList[I].FData.FCnt;
466461 Break;
467462 end ;
468463 Inc(Index);
@@ -518,9 +513,9 @@ procedure TWSThreadsWatcher.CreateFinalList;
518513 Continue;
519514 SetString(Name , Pointer(@WS.FStation[0 ]), Length(WS.FStation));
520515 SetCodePage(Name , CP_UTF8, True);
521- WS.FData^ .FTot := Round(WS.FData^ .FTot*10 )/10 ;
522- Mean := WS.FData^ .FTot/WS.FData^ .FCnt;
523- Str := Name + ' =' + FormatFloat(' 0.0' , WS.FData^ .FMin) + ' /' + FormatFloat(' 0.0' , Mean) + ' /' + FormatFloat(' 0.0' , WS.FData^ .FMax) + ' ,' ;
516+ WS.FData.FTot := Round(WS.FData.FTot*10 )/10 ;
517+ Mean := WS.FData.FTot/WS.FData.FCnt;
518+ Str := Name + ' =' + FormatFloat(' 0.0' , WS.FData.FMin) + ' /' + FormatFloat(' 0.0' , Mean) + ' /' + FormatFloat(' 0.0' , WS.FData.FMax) + ' ,' ;
524519 SL.Add(Str);
525520 end ;
526521 SL.EndUpdate;
@@ -601,22 +596,17 @@ constructor TWSManager.Create(ASrcFile:String; AThreadCnt: Integer);
601596 for I := Low(FWSListAll) to High(FWSListAll) do
602597 begin
603598 FWSListAll[I].FStation := nil ;
604- New(FWSListAll[I].FData);
605- FWSListAll[I].FData^.FMin := 0 ;
606- FWSListAll[I].FData^.FMax := 0 ;
607- FWSListAll[I].FData^.FTot := 0 ;
608- FWSListAll[I].FData^.FCnt := 0 ;
599+ FWSListAll[I].FData.FMin := 0 ;
600+ FWSListAll[I].FData.FMax := 0 ;
601+ FWSListAll[I].FData.FTot := 0 ;
602+ FWSListAll[I].FData.FCnt := 0 ;
609603 end ;
610604 FThreadList := TLockList.Create;
611605 FWSThreadsWatcher := TWSThreadsWatcher.Create(Self);
612606end ;
613607
614608destructor TWSManager.Destroy;
615- var
616- I: Integer;
617609begin
618- for I := Low(FWSListAll) to High(FWSListAll) do
619- Dispose(FWSListAll[I].FData);
620610 FThreadList.Free;
621611 inherited Destroy;
622612end ;
0 commit comments