| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // === 补:未被任何 DFS 覆盖的端点(degree <= 1),作为单点 lane === |
| | | for (String codeData : codeDataList) { |
| | | if (visited.contains(codeData)) { |
| | | continue; |
| | | } |
| | | List<String> neighbors = adjacencyCodeMap.get(codeData); |
| | | int degree = neighbors == null ? 0 : neighbors.size(); |
| | | if (degree <= 1) { |
| | | LaneDto laneDto = new LaneDto(); |
| | | laneDto.getCodes().add(codeData); |
| | | laneDtoList.add(laneDto); |
| | | visited.add(codeData); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void dfsCalcIncludingEnd(String start, String current, LaneDto laneDto, Set<String> visited) { |
| | |
| | | int degree = this.adjacencyCodeMap.get(neighbor).size(); |
| | | if (degree == 2) { |
| | | if (this.isSameDirection(current, neighbor, parent)) { |
| | | this.dfsCalcForLoop(current, neighbor, laneDto, visited); |
| | | this.dfsCalcForLoop(neighbor, current, laneDto, visited); |
| | | } |
| | | } else { |
| | | laneDto.getCodes().add(neighbor); |