Created
August 12, 2014 14:37
-
-
Save ducky427/9125b39d797738865c21 to your computer and use it in GitHub Desktop.
Length of linked list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try(Transaction tx = db.beginTx()) { | |
Node startNode = db.getNodeById( nodeId ); | |
int maxLength = 0; | |
boolean to_continue = true; | |
while (to_continue) { | |
maxLength++; | |
Iterator<Relationship> rels = startNode.getRelationships(Direction.OUTGOING, NEXT).iterator(); | |
if (rels.hasNext()) { | |
startNode = rels.next().getEndNode(); | |
to_continue = true; | |
} else { | |
to_continue = false; | |
} | |
} | |
System.out.printf( "%15s Node: %4d, Length: %3d, Time (ms): %3d%n", "(Traversal API)", nodeId, maxLength, System.currentTimeMillis() - start ); | |
tx.failure(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment