Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
fix codeclimate
Browse files Browse the repository at this point in the history
  • Loading branch information
y0f0 committed Dec 21, 2023
1 parent 2b75a4d commit 35bc19f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ru/vk/itmo/pologovnikita/DaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Entry<MemorySegment> get(MemorySegment key) {
@Override
public void compact() throws IOException {
Iterable<Entry<MemorySegment>> allEntities = this::all;
DiskStorage.compact(path, allEntities, compactionalPath, path);
DiskStorage.compact(allEntities, compactionalPath, path);
}

@Override
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/ru/vk/itmo/pologovnikita/DiskStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected boolean skip(Entry<MemorySegment> memorySegmentEntry) {

public static void save(Path storagePath, Iterable<Entry<MemorySegment>> iterable)
throws IOException {
final Path indexTmp = storagePath.resolve("index.tmp");
final Path indexTmp = getIndexFile(storagePath);
final Path indexFile = storagePath.resolve("index.idx");

try {
Expand Down Expand Up @@ -151,7 +151,7 @@ public static void save(Path storagePath, Iterable<Entry<MemorySegment>> iterabl
}

public static List<MemorySegment> loadOrRecover(Path storagePath, Arena arena) throws IOException {
Path indexTmp = storagePath.resolve("index.tmp");
Path indexTmp = getIndexFile(storagePath);
Path indexFile = storagePath.resolve("index.idx");

if (Files.exists(indexTmp)) {
Expand Down Expand Up @@ -191,9 +191,9 @@ public static void deleteFiles(Path path) throws IOException {
}
}

public static void compact(Path storagePath, Iterable<Entry<MemorySegment>> entries, Path compactionalPath, Path path)
public static void compact(Iterable<Entry<MemorySegment>> entries, Path compactionalPath, Path path)
throws IOException {
Path indexFile = storagePath.resolve("index.tmp");
Path indexFile = getIndexFile(path);
List<String> existedFiles = Files.readAllLines(indexFile, StandardCharsets.UTF_8);

if (existedFiles.isEmpty() && !entries.iterator().hasNext()) {
Expand All @@ -210,6 +210,10 @@ public static void compact(Path storagePath, Iterable<Entry<MemorySegment>> entr
}
}

private static Path getIndexFile(Path path) {
return path.resolve("index.tmp");
}

private static long indexOf(MemorySegment segment, MemorySegment key) {
long recordsCount = recordsCount(segment);

Expand Down

0 comments on commit 35bc19f

Please sign in to comment.