Skip to content

Commit

Permalink
Remove requirement of connections from shuffle format
Browse files Browse the repository at this point in the history
Shuffle format v3
  • Loading branch information
Gaming32 committed Aug 11, 2021
1 parent ba01eb1 commit 00d58a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
6 changes: 2 additions & 4 deletions Noisily sorted.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
2 2.0
N true RANDOM true 0 1
3 2.0
N true RANDOM true 0 2
N false SORTED 1 -1
C 0 1
C 1 2
50 changes: 35 additions & 15 deletions src/utils/shuffle_utils/GraphReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public PartialElement(int left, int right) {
}
}

public final static int[] COMPATIBLE_VERSIONS = {0, 1, 2};
public final static int[] COMPATIBLE_VERSIONS = {0, 1, 2, 3};
static Set<Integer> compatibleVersionsSet;

Scanner scanner;
Expand All @@ -49,8 +49,8 @@ public GraphReader() {
if (compatibleVersionsSet == null) {
compatibleVersionsSet = new HashSet<>(
Arrays.stream(COMPATIBLE_VERSIONS)
.boxed()
.collect(Collectors.toList())
.boxed()
.collect(Collectors.toList())
);
}
}
Expand Down Expand Up @@ -94,8 +94,8 @@ private void read() throws IOException, MalformedGraphFileException {
if (!compatibleVersionsSet.contains(version)) {
throw new MalformedGraphFileException("Unsupported version for reading: " + version + " (Supported versions: "
+ Arrays.stream(COMPATIBLE_VERSIONS)
.mapToObj(String::valueOf)
.collect(Collectors.joining(", ", "{", "}")) + ")");
.mapToObj(String::valueOf)
.collect(Collectors.joining(", ", "{", "}")) + ")");
}
result = new ShuffleGraph();
partialNodes = new ArrayList<>();
Expand All @@ -122,8 +122,25 @@ private void read() throws IOException, MalformedGraphFileException {
ShuffleNode node = result.nodes.get(i);
PartialElement partial = partialNodes.get(i - 1);
try {
node.preConnection = partial.left == -1 ? null : result.connections.get(partial.left);
node.postConnection = partial.right == -1 ? null : result.connections.get(partial.right);
if (version < 3) {
node.preConnection = partial.left == -1 ? null : result.connections.get(partial.left);
node.postConnection = partial.right == -1 ? null : result.connections.get(partial.right);
} else {
if (partial.left != -1 && node.preConnection == null) {
ShuffleNode from = result.nodes.get(partial.left);
ShuffleConnection newConnection = new ShuffleConnection(from, node);
result.connections.add(newConnection);
from.postConnection = newConnection;
node.preConnection = newConnection;
}
if (partial.right != -1 && node.postConnection == null) {
ShuffleNode to = result.nodes.get(partial.right);
ShuffleConnection newConnection = new ShuffleConnection(node, to);
result.connections.add(newConnection);
node.postConnection = newConnection;
to.preConnection = newConnection;
}
}
} catch (IndexOutOfBoundsException e) {
String message = e.getMessage();
int id = Integer.parseInt(message.split(" ", 3)[1]);
Expand Down Expand Up @@ -195,15 +212,15 @@ private void readNode() throws MalformedGraphFileException {
}
throw e;
}
int x, y, preConnectionID, postConnectionID;
if (!scanner.hasNextInt()) { // x
throw new MalformedGraphFileException("Expected X coordinate in node declaration");
}
int x = scanner.nextInt();
x = scanner.nextInt();
if (!scanner.hasNextInt()) { // y
throw new MalformedGraphFileException("Expected Y coordinate in node declaration");
}
int y = scanner.nextInt();
int preConnectionID, postConnectionID;
y = scanner.nextInt();
if (version < 2) {
if (!scanner.hasNextInt()) { // preConnectionID
throw new MalformedGraphFileException("Expected preConnection ID in node declaration");
Expand All @@ -214,16 +231,16 @@ private void readNode() throws MalformedGraphFileException {
}
postConnectionID = scanner.nextInt();
} else {
if (!scanner.hasNextInt()) {
preConnectionID = x;
postConnectionID = y;
x = Integer.MIN_VALUE;
} else {
if (scanner.hasNextInt()) {
preConnectionID = scanner.nextInt();
if (!scanner.hasNextInt()) { // postConnectionID
throw new MalformedGraphFileException("Expected postConnection ID in node declaration");
}
postConnectionID = scanner.nextInt();
} else {
preConnectionID = x;
postConnectionID = y;
x = Integer.MIN_VALUE;
}
}

Expand All @@ -232,6 +249,9 @@ private void readNode() throws MalformedGraphFileException {
}

private void readConnection() throws MalformedGraphFileException {
if (version >= 3) {
throw new MalformedGraphFileException("Invalid identifier type \"C\": Connections were removed in format v3");
}
if (!scanner.hasNextInt()) {
throw new MalformedGraphFileException("Expected fromNode ID in connection declaration");
}
Expand Down

0 comments on commit 00d58a2

Please sign in to comment.