Skip to content

Commit 0b177b3

Browse files
authored
Merge pull request #119 from georges-hatem/main
use mORMot's crc32c alternative
2 parents 9e405e2 + 9d47171 commit 0b177b3

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

entries/ghatem-fpc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Georges Hatem
22

33
## Requirements
4-
- mORMot2 library
4+
- mORMot2 library (for the `MemMap` and `crc32c` functions)
55
- 64-bit compilation
66

77
## Usage

entries/ghatem-fpc/src/onebrc.pas

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface
66

77
uses
88
Classes, SysUtils, Generics.Collections,
9-
mormot.core.os;
9+
mormot.core.os, mormot.core.base;
1010

1111
function RoundExDouble(const ATemp: Double): Double; inline;
1212

@@ -97,6 +97,7 @@ implementation
9797
uses
9898
CRC;
9999

100+
100101
const
101102
c0ascii: ShortInt = 48;
102103
c9ascii: ShortInt = 57;
@@ -331,7 +332,8 @@ procedure TOneBRC.ProcessData (aThreadNb: UInt16; aStartIdx: Int64; aEndIdx: Int
331332
ExtractLineData (vLineStart, i - 1, vLenStationName, vTemp);
332333

333334
// compute the hash starting at the station's first char, and its length
334-
vHash := crc32(0, @FData[vLineStart], vLenStationName);
335+
// mORMot's crc32c is ~33% faster than the built-in one
336+
vHash := crc32c(0, @FData[vLineStart], vLenStationName);
335337

336338
if FstationsDicts[aThreadNb].TryGetValue(vHash, vData) then begin
337339
if vTemp < vData^.Min then
@@ -434,7 +436,7 @@ procedure TOneBRC.GenerateOutput;
434436
// the stations are now sorted, but we need to locate the data: recompute hash
435437
// would it be more efficient to store the hash as well?
436438
// debatable, and the whole output generation is < 0.3 seconds, so not exactly worth it
437-
vHash := crc32(0, @vStations[i][1], Length (vStations[i]));
439+
vHash := crc32c(0, @vStations[i][1], Length (vStations[i]));
438440
FStationsDicts[0].TryGetValue(vHash, vData);
439441
vMin := vData^.Min/10;
440442
vMax := vData^.Max/10;

0 commit comments

Comments
 (0)