Changeset View
Changeset View
Standalone View
Standalone View
java/src/main/java/org/softwareheritage/graph/Entry.java
package org.softwareheritage.graph; | package org.softwareheritage.graph; | ||||
import com.fasterxml.jackson.databind.ObjectMapper; | |||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |||||
import java.io.DataOutputStream; | import java.io.DataOutputStream; | ||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import com.fasterxml.jackson.databind.ObjectMapper; | |||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |||||
public class Entry { | public class Entry { | ||||
private final long PATH_SEPARATOR_ID = -1; | private final long PATH_SEPARATOR_ID = -1; | ||||
private Graph graph; | private Graph graph; | ||||
public void load_graph(String graphBasename) throws IOException { | public void load_graph(String graphBasename) throws IOException { | ||||
System.err.println("Loading graph " + graphBasename + " ..."); | System.err.println("Loading graph " + graphBasename + " ..."); | ||||
this.graph = new Graph(graphBasename); | this.graph = new Graph(graphBasename); | ||||
System.err.println("Graph loaded."); | System.err.println("Graph loaded."); | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | public class QueryHandler { | ||||
public void close() { | public void close() { | ||||
try { | try { | ||||
out.close(); | out.close(); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new RuntimeException("Cannot write response to client: " + e); | throw new RuntimeException("Cannot write response to client: " + e); | ||||
} | } | ||||
} | } | ||||
public void leaves(String direction, String edgesFmt, long srcNodeId, long maxEdges) { | public void leaves(String direction, String edgesFmt, long srcNodeId, long maxEdges, String returnTypes) { | ||||
open(); | open(); | ||||
Traversal t = new Traversal(this.graph, direction, edgesFmt, maxEdges); | Traversal t = new Traversal(this.graph, direction, edgesFmt, maxEdges, returnTypes); | ||||
t.leavesVisitor(srcNodeId, this::writeNode); | for (Long nodeId : t.leaves(srcNodeId)) { | ||||
writeNode(nodeId); | |||||
vlorentz: What is the difference between `t.leavesVisitor(srcNodeId, this::writeNode);` and this?
(same… | |||||
Done Inline ActionsIn Traversal.java, we can see that the functions "leaves" "neighbors" etc... are not used, because the code you show calls directly leavesVisitor with, as "consumer", a function that displays on the output the nodes found during the visit, on the fly. However, I need to filter the nodes found after the visit, not during, so I used the functions "leaves" "neighbors" etc... which store in an arraylist all the nodes found during the visit, to be able to do my filtering, and I still use the writeNode function to display them at the end. Hakimb: In Traversal.java, we can see that the functions "leaves" "neighbors" etc... are not used… | |||||
} | |||||
close(); | close(); | ||||
} | } | ||||
public void neighbors(String direction, String edgesFmt, long srcNodeId, long maxEdges) { | public void neighbors(String direction, String edgesFmt, long srcNodeId, long maxEdges, String returnTypes) { | ||||
open(); | open(); | ||||
Traversal t = new Traversal(this.graph, direction, edgesFmt, maxEdges); | Traversal t = new Traversal(this.graph, direction, edgesFmt, maxEdges, returnTypes); | ||||
t.neighborsVisitor(srcNodeId, this::writeNode); | for (Long nodeId : t.neighbors(srcNodeId)) { | ||||
writeNode(nodeId); | |||||
} | |||||
close(); | close(); | ||||
} | } | ||||
public void visit_nodes(String direction, String edgesFmt, long srcNodeId, long maxEdges) { | public void visit_nodes(String direction, String edgesFmt, long srcNodeId, long maxEdges, String returnTypes) { | ||||
open(); | open(); | ||||
Traversal t = new Traversal(this.graph, direction, edgesFmt, maxEdges); | Traversal t = new Traversal(this.graph, direction, edgesFmt, maxEdges, returnTypes); | ||||
t.visitNodesVisitor(srcNodeId, this::writeNode); | for (Long nodeId : t.visitNodes(srcNodeId)) { | ||||
writeNode(nodeId); | |||||
} | |||||
close(); | close(); | ||||
} | } | ||||
public void visit_edges(String direction, String edgesFmt, long srcNodeId, long maxEdges) { | public void visit_edges(String direction, String edgesFmt, long srcNodeId, long maxEdges) { | ||||
open(); | open(); | ||||
Traversal t = new Traversal(this.graph, direction, edgesFmt, maxEdges); | Traversal t = new Traversal(this.graph, direction, edgesFmt, maxEdges); | ||||
t.visitNodesVisitor(srcNodeId, null, this::writeEdge); | t.visitNodesVisitor(srcNodeId, null, this::writeEdge); | ||||
close(); | close(); | ||||
Show All 20 Lines | public class QueryHandler { | ||||
Node.Type dstType = Node.Type.fromStr(dst); | Node.Type dstType = Node.Type.fromStr(dst); | ||||
Traversal t = new Traversal(this.graph, direction, edgesFmt); | Traversal t = new Traversal(this.graph, direction, edgesFmt); | ||||
for (Long nodeId : t.walk(srcNodeId, dstType, algorithm)) { | for (Long nodeId : t.walk(srcNodeId, dstType, algorithm)) { | ||||
writeNode(nodeId); | writeNode(nodeId); | ||||
} | } | ||||
close(); | close(); | ||||
} | } | ||||
public void random_walk(String direction, String edgesFmt, int retries, long srcNodeId, long dstNodeId) { | public void random_walk(String direction, String edgesFmt, int retries, long srcNodeId, long dstNodeId, | ||||
String returnTypes) { | |||||
open(); | open(); | ||||
Traversal t = new Traversal(this.graph, direction, edgesFmt); | Traversal t = new Traversal(this.graph, direction, edgesFmt, 0, returnTypes); | ||||
for (Long nodeId : t.randomWalk(srcNodeId, dstNodeId, retries)) { | for (Long nodeId : t.randomWalk(srcNodeId, dstNodeId, retries)) { | ||||
writeNode(nodeId); | writeNode(nodeId); | ||||
} | } | ||||
close(); | close(); | ||||
} | } | ||||
public void random_walk_type(String direction, String edgesFmt, int retries, long srcNodeId, String dst) { | public void random_walk_type(String direction, String edgesFmt, int retries, long srcNodeId, String dst, | ||||
String returnTypes) { | |||||
open(); | open(); | ||||
Node.Type dstType = Node.Type.fromStr(dst); | Node.Type dstType = Node.Type.fromStr(dst); | ||||
Traversal t = new Traversal(this.graph, direction, edgesFmt); | Traversal t = new Traversal(this.graph, direction, edgesFmt, 0, returnTypes); | ||||
for (Long nodeId : t.randomWalk(srcNodeId, dstType, retries)) { | for (Long nodeId : t.randomWalk(srcNodeId, dstType, retries)) { | ||||
writeNode(nodeId); | writeNode(nodeId); | ||||
} | } | ||||
close(); | close(); | ||||
} | } | ||||
} | } | ||||
} | } |
What is the difference between t.leavesVisitor(srcNodeId, this::writeNode); and this?
(same question for the other two functions below)