From faee9372bd6dc3e93141a23a4a34677d09d7a352 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 29 Jan 2024 18:40:35 -0300 Subject: [PATCH] new try --- .../java/dev/morling/onebrc/CalculateAverage_dpsoft.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/morling/onebrc/CalculateAverage_dpsoft.java b/src/main/java/dev/morling/onebrc/CalculateAverage_dpsoft.java index 27b9d57de..d241834fd 100644 --- a/src/main/java/dev/morling/onebrc/CalculateAverage_dpsoft.java +++ b/src/main/java/dev/morling/onebrc/CalculateAverage_dpsoft.java @@ -65,18 +65,18 @@ private static Map sortSequentially(MeasurementMap allMeasu return sorted; } - // Credits to @spullara + // Inspired by @spullara private static List getMemorySegments(int numberOfSegments) throws IOException { var file = new File(FILE); long fileSize = file.length(); long segmentSize = fileSize / numberOfSegments; List 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;