英文:
Limit cursor-based node traversal to outgoing edges
问题
我正在尝试将Max de Marzi的Parallel K-Hop Counts示例适应到一个有向图的问题上,使用关系和节点游标。
RelationshipTraversalCursor relsCursor = cursors.allocateRelationshipTraversalCursor();
NodeCursor nodeCursor = cursors.allocateNodeCursor();
read.singleNode(startingNode.getId(), nodeCursor);
nodeCursor.next();
nodeCursor.allRelationships(relsCursor);
如何将对关系的迭代限制为出边?到目前为止,我是使用org.neo4j.graphdb.Node
的Iterable<Relationship> getRelationships(Direction var1)
函数来实现的,但由于我对Neo4j Java API的内部了解有限,我想比较相对性能。
英文:
I'm trying to adapt Max de Marzi's Parallel K-Hop Counts example to a problem on a directed graph. Using relationship and node cursors
RelationshipTraversalCursor relsCursor = cursors.allocateRelationshipTraversalCursor();
NodeCursor nodeCursor = cursors.allocateNodeCursor();
read.singleNode(startingNode.getId(), nodeCursor);
nodeCursor.next();
nodeCursor.allRelationships(relsCursor);
how would I limit the iteration over the relationships while (relsCursor.next()) {...}
to the outgoing edges?
So far I achieved this using the Iterable<Relationship> getRelationships(Direction var1)
function of the org.neo4j.graphdb.Node
, but since my intuition of the internal Neo4j Java API is limited, I would like to compare relative performance.
答案1
得分: 1
这是一个有用的代码片段,来自相关的neo4j测试方法,展示了如何确定游标当前关系的方向:
private static String computeKey( ..., RelationshipTraversalCursor r )
{
Direction d;
if ( r.sourceNodeReference() == r.targetNodeReference() )
{
d = Direction.BOTH;
}
else if ( r.sourceNodeReference() == r.originNodeReference() )
{
d = Direction.OUTGOING;
}
else
{
d = Direction.INCOMING;
}
.
.
.
}
所以,对你来说,类似这样的代码应该可以工作:
while (relsCursor.next()) {
if (relsCursor.sourceNodeReference() == relsCursor.originNodeReference()) {
// 进行OUTGOING关系处理
}
}
英文:
Here is a helpful snippet from a relevant neo4j test method that shows how to determine the direction of the cursor's current relationship:
private static String computeKey( ..., RelationshipTraversalCursor r )
{
Direction d;
if ( r.sourceNodeReference() == r.targetNodeReference() )
{
d = Direction.BOTH;
}
else if ( r.sourceNodeReference() == r.originNodeReference() )
{
d = Direction.OUTGOING;
}
else
{
d = Direction.INCOMING;
}
.
.
.
}
So, something like this should work for you:
while (relsCursor.next()) {
if (relsCursor.sourceNodeReference() == relsCursor.originNodeReference()) {
// Do OUTGOING relationship processing
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论