You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/06/14 13:53:21 UTC

[3/3] jena git commit: JENA-1195: Use a hash set.

JENA-1195: Use a hash set.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e1bb3c96
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e1bb3c96
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e1bb3c96

Branch: refs/heads/master
Commit: e1bb3c967c6c868434ee412a5ad18e0fab547766
Parents: a05243d
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jun 14 14:24:49 2016 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jun 14 14:24:49 2016 +0100

----------------------------------------------------------------------
 .../jena/sparql/path/eval/PathEngineSPARQL.java | 25 +++++---------------
 1 file changed, 6 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/e1bb3c96/jena-arq/src/main/java/org/apache/jena/sparql/path/eval/PathEngineSPARQL.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/path/eval/PathEngineSPARQL.java b/jena-arq/src/main/java/org/apache/jena/sparql/path/eval/PathEngineSPARQL.java
index 187932f..54fbe82 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/path/eval/PathEngineSPARQL.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/path/eval/PathEngineSPARQL.java
@@ -76,29 +76,23 @@ public class PathEngineSPARQL extends PathEngine
 
     @Override
     protected void doZeroOrOne(Path pathStep, Node node, Collection<Node> output) {
-        // Force unique evaluation.
         Collection<Node> x = new HashSet<>() ;
         eval(pathStep, node, x) ;
         x.add(node) ;
         output.addAll(x) ;
     }
-
+    
     @Override
     protected void doZeroOrMore(Path pathStep, Node node, Collection<Node> output) {
-        // Reuse "output"
-        Collection<Node> visited = new LinkedList<>() ; // new
-                                                            // HashSet<Node>() ;
+        Set<Node> visited = new HashSet<Node>() ;
         ALP_1(forwardMode, 0, -1, node, pathStep, visited) ;
         output.addAll(visited) ;
     }
 
     @Override
     protected void doOneOrMore(Path pathStep, Node node, Collection<Node> output) {
-        // Reuse "output"
-        Collection<Node> visited = new LinkedList<>() ; // new
-                                                            // HashSet<Node>() ;
+        Set<Node> visited = new HashSet<Node>() ;
         // Do one step without including.
-        // TODO switch to PathEngine1 for the sub-step as we only need uniques.
         Iter<Node> iter1 = eval(pathStep, node) ;
         for (; iter1.hasNext();) {
             Node n1 = iter1.next() ;
@@ -113,16 +107,11 @@ public class PathEngineSPARQL extends PathEngine
         output.add(node) ;
     }
 
-    // TODO ?? switch to PathEngine1 for the sub-step as we only need uniques.
-    private void ALP_1(boolean forwardMode, int stepCount, int maxStepCount, Node node, Path path, Collection<Node> visited) {
+    private void ALP_1(boolean forwardMode, int stepCount, int maxStepCount, Node node, Path path, Set<Node> visited) {
         if ( maxStepCount >= 0 && stepCount > maxStepCount )
             return ;
-        if ( visited.contains(node) )
-            return ;
-
         if ( !visited.add(node) )
             return ;
-
         Iter<Node> iter1 = eval(path, node) ;
         // For each step, add to results and recurse.
         for (; iter1.hasNext();) {
@@ -131,6 +120,7 @@ public class PathEngineSPARQL extends PathEngine
         }
     }
 
+    // Not SPARQL - counting versions.
     @Override
     protected void doZeroOrMoreN(Path pathStep, Node node, Collection<Node> output) {
         Set<Node> visited = new HashSet<>() ;
@@ -148,11 +138,10 @@ public class PathEngineSPARQL extends PathEngine
         }
     }
 
-    // This is the worker function for path{*}
+    // This is the worker function for path{*} /counting (non_SPARQL) semantics.
     private void ALP_N(Node node, Path path, Collection<Node> visited, Collection<Node> output) {
         if ( visited.contains(node) )
             return ;
-
         // If output is a set, then no point going on if node has been added to
         // the results.
         // If output includes duplicates, more solutions are generated
@@ -198,7 +187,6 @@ public class PathEngineSPARQL extends PathEngine
         long min2 = dec(min1) ;
         long max2 = dec(max1) ;
 
-        // TODO Rewrite
         Path p1 = pathStep ;
         Path p2 = new P_Mod(pathStep, min2, max2) ;
 
@@ -213,7 +201,6 @@ public class PathEngineSPARQL extends PathEngine
             // cardinality of the
             // two operations is different.
         }
-        // ****
 
         // One step.
         Iterator<Node> iter = eval(p1, node) ;