Skip to content

Commit

Permalink
new try
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsoft committed Jan 29, 2024
1 parent 600ea10 commit faee937
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/dev/morling/onebrc/CalculateAverage_dpsoft.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ private static Map<String, Measurement> sortSequentially(MeasurementMap allMeasu
return sorted;
}

// Credits to @spullara
// Inspired by @spullara
private static List<FileSegment> getMemorySegments(int numberOfSegments) throws IOException {
var file = new File(FILE);
long fileSize = file.length();
long segmentSize = fileSize / numberOfSegments;
List<FileSegment> segments = new ArrayList<>(numberOfSegments);

// Pointless to split small files
if (segmentSize < 1_000_000) {
if (fileSize < 1_000_000) {
segments.add(new FileSegment(0, fileSize));
return segments;
}

try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r")) {
for (int i = 0; i < numberOfSegments; i++) {
long segStart = i * segmentSize;
Expand Down

0 comments on commit faee937

Please sign in to comment.