Skip to content

Commit

Permalink
Support traversing groups through buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Nov 9, 2017
1 parent e84fcb1 commit ce9c593
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
Expand Up @@ -21,6 +21,7 @@


import org.neo4j.collection.primitive.Primitive; import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveIntObjectMap;
import org.neo4j.kernel.impl.newapi.RelationshipTraversalCursor.Record;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord; import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord; import org.neo4j.kernel.impl.store.record.RelationshipRecord;


Expand Down Expand Up @@ -256,9 +257,9 @@ static class Group
{ {
final int label; final int label;
final Group next; final Group next;
RelationshipTraversalCursor.Record outgoing; Record outgoing;
RelationshipTraversalCursor.Record incoming; Record incoming;
RelationshipTraversalCursor.Record loops; Record loops;
private long firstOut = NO_ID; private long firstOut = NO_ID;
private long firstIn = NO_ID; private long firstIn = NO_ID;
private long firstLoop = NO_ID; private long firstLoop = NO_ID;
Expand Down
Expand Up @@ -27,24 +27,36 @@ class RelationshipTraversalCursor extends RelationshipCursor
{ {
private long originNodeReference; private long originNodeReference;
private long next; private long next;
private Record buffer;


RelationshipTraversalCursor( Read read ) RelationshipTraversalCursor( Read read )
{ {
super( read ); super( read );
} }


/*
* Cursor being called as a group, use the buffered records in Record
* instead.
*/
void buffered( long nodeReference, Record record ) void buffered( long nodeReference, Record record )
{ {
throw new UnsupportedOperationException( "not implemented" ); this.originNodeReference = nodeReference;
this.buffer = Record.initialize( record );
} }


/*
* Normal traversal.
*/
void chain( long nodeReference, long reference ) void chain( long nodeReference, long reference )
{ {
setId( NO_ID ); setId( NO_ID );
originNodeReference = nodeReference; originNodeReference = nodeReference;
next = reference; next = reference;
} }


/*
* Reference to a group record
*/
void groups( long nodeReference, long reference ) void groups( long nodeReference, long reference )
{ {
throw new UnsupportedOperationException( "not implemented" ); throw new UnsupportedOperationException( "not implemented" );
Expand Down Expand Up @@ -95,6 +107,27 @@ public long originNodeReference()
@Override @Override
public boolean next() public boolean next()
{ {
if ( hasBufferedData() )
{ //We have buffered data, iterate the chain of buffered records
buffer = buffer.next;
if ( !hasBufferedData() )
{
close();
return false;
}
else
{
// Copy buffer data to self
this.setId( buffer.id );
this.setType( buffer.type );
this.setNextProp( buffer.nextProp );
this.setFirstNode( buffer.firstNode );
this.setSecondNode( buffer.secondNode );
return true;
}
}


if ( next == NO_ID ) if ( next == NO_ID )
{ {
close(); close();
Expand Down Expand Up @@ -127,14 +160,57 @@ public boolean shouldRetry()
public void close() public void close()
{ {
setId( next = NO_ID ); setId( next = NO_ID );
buffer = null;
}

private boolean hasBufferedData()
{
return buffer != null;
} }


/*
* Record is both a data holder for buffering data from a RelationshipRecord
* as well as a linked list over the records in the group.
*/
static class Record static class Record
{ {
private static final RelationshipRecord DUMMY = null;
final long id;
final int type;
final long nextProp;
final long firstNode;
final long secondNode;
final Record next; final Record next;


/*
* Initialize the chain of records
*/
static Record initialize(Record first)
{
return new Record( DUMMY, first );
}

/*
* Initialize the record chain or push a new record as the new head of the record chain
*/
Record( RelationshipRecord record, Record next ) Record( RelationshipRecord record, Record next )
{ {
if ( record != null )
{
id = record.getId();
type = record.getType();
nextProp = record.getNextProp();
firstNode = record.getFirstNode();
secondNode = record.getSecondNode();
}
else
{
id = NO_ID;
type = NO_ID;
nextProp = NO_ID;
firstNode = NO_ID;
secondNode = NO_ID;
}
this.next = next; this.next = next;
} }
} }
Expand Down

0 comments on commit ce9c593

Please sign in to comment.