Skip to content

Commit

Permalink
Optimise chunksOnBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Erashin committed Sep 22, 2023
1 parent 6bf68a1 commit e79792b
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PathfindingResultConverter {
Expand Down Expand Up @@ -190,7 +191,7 @@ static List<RJSRoutePath> makeRoutePath(
var blocks = ranges.stream()
.map(Pathfinding.EdgeRange::edge)
.toList();
var chunkPath = chunksOnBlocks(rawInfra, blockInfra, blocks);
var chunkPath = chunksOnBlocks(blockInfra, blocks);
var routes = chunksToRoutes(rawInfra, chunkPath);
var startOffset = findStartOffset(blockInfra, rawInfra, chunkPath.get(0), routes.get(0), ranges.get(0));
var endOffset = findEndOffset(blockInfra, rawInfra, Iterables.getLast(chunkPath),
Expand Down Expand Up @@ -336,12 +337,10 @@ private static long getRouteChunkOffset(RawSignalingInfra rawInfra, int routeSta
}

/** Returns the list of dir chunk id on the given block list */
public static List<Integer> chunksOnBlocks(RawSignalingInfra rawInfra,
BlockInfra blockInfra, List<Integer> blockIds) {
private static List<Integer> chunksOnBlocks(BlockInfra blockInfra, List<Integer> blockIds) {
return blockIds.stream()
.flatMap(blockId -> toIntList(blockInfra.getBlockPath(blockId)).stream())
.flatMap(zonePath -> toIntList(rawInfra.getZonePathChunks(zonePath)).stream())
.toList();
.flatMap(block -> toIntList(blockInfra.getTrackChunksFromBlock(block)).stream())
.collect(Collectors.toSet()).stream().toList();
}

/** Converts a list of dir chunks into a list of routes */
Expand Down

0 comments on commit e79792b

Please sign in to comment.