Просмотр исходного кода

Remove unnecessary array-based format of table entries.

Timur Sağlam 5 лет назад
Родитель
Сommit
bdb8d80998

+ 5 - 8
jplag.frontend-utils/src/main/java/jplag/Table.java

@@ -5,7 +5,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Stream;
 
 /**
  * A {@link HashMap} that maps Integer keys to multiple Integer values. Note that all keys with identical
@@ -29,16 +28,14 @@ public class Table {
      * Returns all stored numbers for a key. Note that all keys with identical <code>(key % prime)</code> are mapped to the
      * same values (see {@link Table}).
      * @param key is the specific key.
-     * @return the stored numbers or an empty array if it does not contain the modifiedKey.
+     * @return the stored numbers or null if nothing is stored.
      */
-    public final int[] get(int key) {
+    public final List<Integer> get(int key) {
         int actualKey = key % primeNumber;
-        if (!mappedEntries.containsKey(actualKey)) {
-            return null;
+        if (mappedEntries.containsKey(actualKey)) {
+            return new ArrayList<>(mappedEntries.get(actualKey));
         }
-        List<Integer> result = mappedEntries.get(actualKey);
-        Stream<Integer> stream = Stream.concat(Stream.of(result.size()), result.stream()); // Legacy format: First entry is the number of following entries.
-        return stream.mapToInt(Integer::intValue).toArray(); // TODO TS: Required, as the GST algorithm still relies on the array format.
+        return null;
     }
 
     /**

+ 8 - 8
jplag/src/main/java/jplag/GreedyStringTiling.java

@@ -1,5 +1,7 @@
 package jplag;
 
+import java.util.List;
+
 /**
  * This class implements the Greedy String Tiling algorithm as introduced by Michael Wise. However, it is very specific
  * to the classes {@link Structure}, {@link Token}, as well as {@link Matches} and {@link Match}.
@@ -147,17 +149,16 @@ public class GreedyStringTiling implements TokenConstants {
         }
 
         int maxmatch;
-        int[] elemsB;
+        List<Integer> elementsB;
 
         do {
             maxmatch = mml;
             matches.clear();
             for (int x = 0; x <= lengthA - maxmatch; x++) {
-                if (A[x].marked || A[x].hash == -1 || (elemsB = structB.table.get(A[x].hash)) == null) {
+                if (A[x].marked || A[x].hash == -1 || (elementsB = structB.table.get(A[x].hash)) == null) {
                     continue;
                 }
-                inner: for (int i = 1; i <= elemsB[0]; i++) { // elemsB[0] contains the length of the Array // TODO TS: we should change this
-                    int y = elemsB[i];
+                inner: for (Integer y : elementsB) {
                     if (B[y].marked || maxmatch > lengthB - y) {
                         continue;
                     }
@@ -251,17 +252,16 @@ public class GreedyStringTiling implements TokenConstants {
         }
 
         int maxmatch;
-        int[] elemsB;
+        List<Integer> elementsB;
 
         do {
             maxmatch = mml;
             matches.clear();
             for (int x = 0; x <= lengthA - maxmatch; x++) {
-                if (A[x].marked || A[x].hash == -1 || (elemsB = structB.table.get(A[x].hash)) == null) {
+                if (A[x].marked || A[x].hash == -1 || (elementsB = structB.table.get(A[x].hash)) == null) {
                     continue;
                 }
-                inner: for (int i = 1; i <= elemsB[0]; i++) {// elemsB[0] contains the length of the Array
-                    int y = elemsB[i];
+                inner: for (Integer y : elementsB) {
                     if (B[y].marked || maxmatch > lengthB - y) {
                         continue;
                     }