Преглед изворни кода

Update revisioncombinationgenerator to be dynamic

Instead of generating all combinations before, the combinationgenerator
now has the possibility to generate on the fly. This however doesn't solve
the algorithm being slow but removes the crash when the combinations becomes
many.
ossv пре 4 година
родитељ
комит
a47504eb57

+ 12 - 4
code/szz/src/main/java/heuristics/SimpleBugIntroducerFinder.java

@@ -182,8 +182,13 @@ public class SimpleBugIntroducerFinder implements BugIntroducerFinder {
       List<String> issues = bucketIssues.get(entry.getKey());
 
       RevisionCombinationGenerator gen = new RevisionCombinationGenerator(introducers, issues, 2);
-      List<String[]> revisions = gen.generateRevIssuePairs();
-      for (String[] pair : revisions) {
+      gen = gen.iterator();
+
+      while(gen.hasNext()) {
+        String[] pair = gen.getNextIndic();
+        if (pair[0] == "" && pair[1] == "")
+          continue;
+        
         if (isWithinTimeframe(pair[1], pair[0])) {
           bugIntroducers.add(pair);
         } else {
@@ -209,9 +214,12 @@ public class SimpleBugIntroducerFinder implements BugIntroducerFinder {
       List<String> issues = partialIssues.get(suspects.getKey());
 
       RevisionCombinationGenerator gen = new RevisionCombinationGenerator(introducers, issues, 2);
-      List<String[]> revisions = gen.generateRevIssuePairs();
+      gen = gen.iterator();
 
-      for (String[] pair : revisions) {
+      while(gen.hasNext()) {
+        String[] pair = gen.getNextIndic();
+        if (pair[0] == "" && pair[1] == "")
+          continue;
         if (isPartialFix(pair[0])) {
           bugIntroducers.add(pair);
         }

+ 36 - 0
code/szz/src/main/java/util/RevisionCombinationGenerator.java

@@ -41,6 +41,13 @@ public class RevisionCombinationGenerator {
   private List<String> sa;
   private List<String> sb;
 
+  /*
+  * Temporary holder for the iterator.
+  */
+  private Set<String> revs;
+  private Set<String> issues;
+  private List<String> all_commits;
+
   /**
    * Constructor
    */
@@ -144,6 +151,35 @@ public class RevisionCombinationGenerator {
     return a;
   }
 
+  public RevisionCombinationGenerator iterator() {
+    this.revs = new HashSet<>(this.sa);
+    this.issues = new HashSet<>(this.sb);
+    this.all_commits = Stream.concat(this.sa.stream(), this.sb.stream()).collect(Collectors.toList());
+
+    return this;
+  }
+
+  public boolean hasNext() {
+    if (r != 2) return false;
+    return hasMore();
+  }
+
+  public String[] getNextIndic() {
+    int[] indices;
+    indices = getNext();
+
+    String c1 = this.all_commits.get(indices[0]);
+    String c2 = this.all_commits.get(indices[1]);
+
+    if (revs.contains(c1) && issues.contains(c2)) {
+      return new String[]{c1, c2};
+    } else if (revs.contains(c2) && issues.contains(c1)) {
+      return new String[]{c2, c1};
+    }
+
+    return new String[]{"", ""};
+  }
+
   public List<String[]> generateRevIssuePairs() {
     if (r != 2) return Collections.emptyList();
     List<String[]> combinations = new LinkedList<>();