Skip to content

Commit

Permalink
Flatten node cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Jan 9, 2017
1 parent c826830 commit dd67bd8
Show file tree
Hide file tree
Showing 12 changed files with 987 additions and 1,120 deletions.

This file was deleted.

Expand Up @@ -19,6 +19,7 @@
*/ */
package org.neo4j.kernel.impl.api; package org.neo4j.kernel.impl.api;


import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
Expand Down Expand Up @@ -96,6 +97,7 @@
import org.neo4j.kernel.impl.api.operations.SchemaStateOperations; import org.neo4j.kernel.impl.api.operations.SchemaStateOperations;
import org.neo4j.kernel.impl.api.security.OverriddenAccessMode; import org.neo4j.kernel.impl.api.security.OverriddenAccessMode;
import org.neo4j.kernel.impl.api.security.RestrictedAccessMode; import org.neo4j.kernel.impl.api.security.RestrictedAccessMode;
import org.neo4j.kernel.impl.api.store.CursorRelationshipIterator;
import org.neo4j.kernel.impl.api.store.RelationshipIterator; import org.neo4j.kernel.impl.api.store.RelationshipIterator;
import org.neo4j.kernel.impl.proc.Procedures; import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.impl.query.QuerySource; import org.neo4j.kernel.impl.query.QuerySource;
Expand Down Expand Up @@ -365,7 +367,8 @@ public RelationshipIterator nodeGetRelationships( long nodeId, Direction directi
statement.assertOpen(); statement.assertOpen();
try ( Cursor<NodeItem> node = dataRead().nodeCursorById( statement, nodeId ) ) try ( Cursor<NodeItem> node = dataRead().nodeCursorById( statement, nodeId ) )
{ {
return node.get().getRelationships( direction( direction ), relTypes ); return new CursorRelationshipIterator(
node.get().relationships( direction( direction ), deduplicate( relTypes ) ) );
} }
} }


Expand All @@ -380,15 +383,40 @@ private org.neo4j.storageengine.api.Direction direction( Direction direction )
} }
} }


private static int[] deduplicate( int[] types )
{
int unique = 0;
for ( int i = 0; i < types.length; i++ )
{
int type = types[i];
for ( int j = 0; j < unique; j++ )
{
if ( type == types[j] )
{
type = -1; // signal that this relationship is not unique
break; // we will not find more than one conflict
}
}
if ( type != -1 )
{ // this has to be done outside the inner loop, otherwise we'd never accept a single one...
types[unique++] = types[i];
}
}
if ( unique < types.length )
{
types = Arrays.copyOf( types, unique );
}
return types;
}

@Override @Override
public RelationshipIterator nodeGetRelationships( long nodeId, Direction direction ) public RelationshipIterator nodeGetRelationships( long nodeId, Direction direction )
throws EntityNotFoundException throws EntityNotFoundException
{ {
statement.assertOpen(); statement.assertOpen();

try ( Cursor<NodeItem> node = dataRead().nodeCursorById( statement, nodeId ) ) try ( Cursor<NodeItem> node = dataRead().nodeCursorById( statement, nodeId ) )
{ {
return node.get().getRelationships( direction( direction ) ); return new CursorRelationshipIterator( node.get().relationships( direction( direction ) ) );
} }
} }


Expand Down

0 comments on commit dd67bd8

Please sign in to comment.