Skip to content

Commit

Permalink
Introduce RelationshipTypeItem instead of using a generic IntSupplier
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Jan 9, 2017
1 parent 621625a commit 525007d
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 133 deletions.
Expand Up @@ -106,6 +106,7 @@
import org.neo4j.storageengine.api.LabelItem;
import org.neo4j.storageengine.api.NodeItem;
import org.neo4j.storageengine.api.RelationshipItem;
import org.neo4j.storageengine.api.RelationshipTypeItem;
import org.neo4j.storageengine.api.Token;
import org.neo4j.storageengine.api.lock.ResourceType;
import org.neo4j.storageengine.api.schema.PopulationProgress;
Expand Down Expand Up @@ -456,7 +457,7 @@ public PrimitiveIntIterator nodeGetRelationshipTypes( long nodeId ) throws Entit
statement.assertOpen();
try ( Cursor<NodeItem> node = dataRead().nodeCursorById( statement, nodeId ) )
{
return Cursors.intIterator( node.get().relationshipTypes(), IntSupplier::getAsInt );
return Cursors.intIterator( node.get().relationshipTypes(), RelationshipTypeItem::getAsInt );
}
}

Expand Down
Expand Up @@ -26,8 +26,6 @@
import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.cursor.Cursor;
import org.neo4j.cursor.GenericCursor;
import org.neo4j.cursor.IntValue;
import org.neo4j.kernel.api.StatementConstants;
import org.neo4j.kernel.api.cursor.EntityItemHelper;
import org.neo4j.kernel.api.txstate.TransactionState;
Expand All @@ -37,6 +35,7 @@
import org.neo4j.storageengine.api.NodeItem;
import org.neo4j.storageengine.api.PropertyItem;
import org.neo4j.storageengine.api.RelationshipItem;
import org.neo4j.storageengine.api.RelationshipTypeItem;
import org.neo4j.storageengine.api.txstate.NodeState;

import static org.neo4j.kernel.impl.util.Cursors.empty;
Expand Down Expand Up @@ -171,7 +170,7 @@ public Cursor<RelationshipItem> relationships( Direction direction )
}

@Override
public Cursor<IntSupplier> relationshipTypes()
public Cursor<RelationshipTypeItem> relationshipTypes()
{
if ( nodeIsAddedInThisTx )
{
Expand All @@ -189,7 +188,7 @@ public Cursor<IntSupplier> relationshipTypes()

// Augment with types stored on disk, minus any types where all rels of that type are deleted
// in current tx.
try ( Cursor<IntSupplier> storeTypes = cursor.get().relationshipTypes() )
try ( Cursor<RelationshipTypeItem> storeTypes = cursor.get().relationshipTypes() )
{
while ( storeTypes.next() )
{
Expand Down Expand Up @@ -228,40 +227,55 @@ public boolean isDense()
return cursor.get().isDense();
}

private class RelationshipTypeCursor extends GenericCursor<IntSupplier>
private class RelationshipTypeCursor implements Cursor<RelationshipTypeItem>, RelationshipTypeItem
{
private final PrimitiveIntIterator primitiveIntIterator;
private int current = StatementConstants.NO_SUCH_RELATIONSHIP_TYPE;

RelationshipTypeCursor( PrimitiveIntIterator primitiveIntIterator )
{
this.primitiveIntIterator = primitiveIntIterator;
current = new IntValue();
}

@Override
public boolean next()
{
if ( primitiveIntIterator.hasNext() )
{
((IntValue) current).setValue( primitiveIntIterator.next() );
current = primitiveIntIterator.next();
return true;
}
else
{
current = null;
return false;
}

current = StatementConstants.NO_SUCH_RELATIONSHIP_TYPE;
return false;
}

@Override
public void close()
{
}

@Override
public int getAsInt()
{
return current;
}

@Override
public RelationshipTypeItem get()
{
return this;
}
}

private class DegreeCursor implements Cursor<DegreeItem>, DegreeItem
{
private final Cursor<IntSupplier> relTypeCursor;
private final Cursor<RelationshipTypeItem> relTypeCursor;
private int type;
private long outgoing;
private long incoming;

DegreeCursor( Cursor<IntSupplier> relTypeCursor )
DegreeCursor( Cursor<RelationshipTypeItem> relTypeCursor )
{
this.relTypeCursor = relTypeCursor;
}
Expand Down
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.api.store;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.cursor.Cursor;
import org.neo4j.storageengine.api.RelationshipItem;
import org.neo4j.storageengine.api.RelationshipTypeItem;

import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_RELATIONSHIP_TYPE;

class RelationshipTypeCursor implements Cursor<RelationshipTypeItem>, RelationshipTypeItem
{
private final PrimitiveIntSet foundTypes;
private final Cursor<RelationshipItem> relationships;

private int value = NO_SUCH_RELATIONSHIP_TYPE;

RelationshipTypeCursor( Cursor<RelationshipItem> relationships )
{
this.relationships = relationships;
foundTypes = Primitive.intSet( 5 );
}

@Override
public boolean next()
{
while ( relationships.next() )
{
if ( !foundTypes.contains( relationships.get().type() ) )
{
foundTypes.add( relationships.get().type() );
value = relationships.get().type();
return true;
}
}

value = NO_SUCH_RELATIONSHIP_TYPE;
return false;
}

@Override
public void close()
{
relationships.close();
}

@Override
public RelationshipTypeItem get()
{
return this;
}

@Override
public int getAsInt()
{
return value;
}
}
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.api.store;

import org.neo4j.cursor.Cursor;
import org.neo4j.kernel.impl.store.RecordCursors;
import org.neo4j.kernel.impl.store.record.Record;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.storageengine.api.RelationshipTypeItem;

import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_RELATIONSHIP_TYPE;
import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;

class RelationshipTypeDenseCursor implements Cursor<RelationshipTypeItem>, RelationshipTypeItem
{
private final RelationshipGroupRecord groupRecord;
private RecordCursors recordCursors;

private long groupId;
private int value = NO_SUCH_RELATIONSHIP_TYPE;

RelationshipTypeDenseCursor( long groupId, RelationshipGroupRecord groupRecord, RecordCursors recordCursors )
{
this.groupId = groupId;
this.groupRecord = groupRecord;
this.recordCursors = recordCursors;
}

@Override
public boolean next()
{
while ( groupId != Record.NO_NEXT_RELATIONSHIP.intValue() )
{
boolean groupRecordInUse = recordCursors.relationshipGroup().next( groupId, groupRecord, FORCE );
groupId = groupRecord.getNext();
if ( groupRecordInUse )
{
value = groupRecord.getType();
return true;
}
}

value = NO_SUCH_RELATIONSHIP_TYPE;
return false;
}

@Override
public void close()
{
}

@Override
public RelationshipTypeItem get()
{
return this;
}

@Override
public int getAsInt()
{
return value;
}
}

0 comments on commit 525007d

Please sign in to comment.