Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into report-viewer/old-…
Browse files Browse the repository at this point in the history
…version-in-jar
  • Loading branch information
Kr0nox committed Jan 23, 2025
2 parents 6a492b5 + 56197a8 commit e4dfc9a
Show file tree
Hide file tree
Showing 12 changed files with 1,837 additions and 1,145 deletions.
26 changes: 24 additions & 2 deletions core/src/main/java/de/jplag/GreedyStringTiling.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

import de.jplag.options.JPlagOptions;

Expand All @@ -30,6 +31,15 @@ public class GreedyStringTiling {
private final Map<Submission, int[]> cachedTokenValueLists = new IdentityHashMap<>();
private final Map<Submission, SubsequenceHashLookupTable> cachedHashLookupTables = new IdentityHashMap<>();

private static final String ERROR_INDEX_OUT_OF_BOUNDS = """
GST index out of bounds. This is probably a random issue caused by multithreading issues.
Length of the list that caused the exception (the list of marks for the relevant submission): %s, Index in that list: %s
TokenCount: %s, TokenList: %s
CachedTokenCount: %s
Submission (cause of error): %s
Submission (other): %s
""".trim().stripIndent();

public GreedyStringTiling(JPlagOptions options) {
this.options = options;
// Ensures 1 <= neighborLength <= minimumTokenMatch
Expand Down Expand Up @@ -115,14 +125,16 @@ private JPlagComparison compareInternal(Submission leftSubmission, Submission ri
List<Match> iterationMatches = new ArrayList<>();
for (int leftStartIndex = 0; leftStartIndex < leftValues.length - maximumMatchLength; leftStartIndex++) {
int leftSubsequenceHash = leftLookupTable.subsequenceHashForStartIndex(leftStartIndex);
if (leftMarked[leftStartIndex] || leftSubsequenceHash == SubsequenceHashLookupTable.NO_HASH) {
if (checkMark(leftMarked, leftStartIndex, leftSubmission, rightSubmission)
|| leftSubsequenceHash == SubsequenceHashLookupTable.NO_HASH) {
continue;
}
List<Integer> possiblyMatchingRightStartIndexes = rightLookupTable
.startIndexesOfPossiblyMatchingSubsequencesForSubsequenceHash(leftSubsequenceHash);
for (Integer rightStartIndex : possiblyMatchingRightStartIndexes) {
// comparison uses >= because it is assumed that the last token is a pivot (FILE_END)
if (rightMarked[rightStartIndex] || maximumMatchLength >= rightValues.length - rightStartIndex) {
if (checkMark(rightMarked, rightStartIndex, rightSubmission, leftSubmission)
|| maximumMatchLength >= rightValues.length - rightStartIndex) {
continue;
}

Expand Down Expand Up @@ -228,4 +240,14 @@ private int[] tokenValueListFromSubmission(Submission submission) {
return tokenValueList;
}));
}

private boolean checkMark(boolean[] marks, int index, Submission submission, Submission otherSubmission) {
if (index >= marks.length) {
throw new IllegalStateException(String.format(ERROR_INDEX_OUT_OF_BOUNDS, marks.length, index, submission.getTokenList().size(),
submission.getTokenList().stream().map(it -> it.getType().getDescription()).collect(Collectors.joining(", ")),
cachedTokenValueLists.get(submission).length, submission.getName(), otherSubmission.getName()));
}

return marks[index];
}
}
4 changes: 2 additions & 2 deletions languages/scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<artifactId>scala</artifactId>

<properties>
<scala.version>2.13.15</scala.version>
<scala.version>2.13.16</scala.version>
<scala.compat.version>2.13</scala.compat.version>
</properties>

Expand All @@ -25,7 +25,7 @@
<dependency>
<groupId>org.scalameta</groupId>
<artifactId>scalameta_${scala.compat.version}</artifactId>
<version>4.12.3</version>
<version>4.12.6</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion languages/scxml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.27.2</version>
<version>3.27.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
5 changes: 5 additions & 0 deletions languages/swift/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>language-antlr-utils</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>

<build>
Expand Down
Loading

0 comments on commit e4dfc9a

Please sign in to comment.