Skip to content

Commit

Permalink
Removed TxState.LABEL_STATE
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Koval committed Feb 2, 2018
1 parent 5a3b9b6 commit 80449d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 118 deletions.

This file was deleted.

Expand Up @@ -95,11 +95,10 @@
*/
public class TxState implements TransactionState, RelationshipVisitor.Home
{
private static final LabelState.Defaults LABEL_STATE = new TransactionLabelState();
private static final NodeStateImpl.Defaults NODE_STATE = new TransactionNodeState();
private static final RelationshipStateImpl.Defaults RELATIONSHIP_STATE = new TransactionRelationshipState();

private PrimitiveLongObjectMap<LabelState.Mutable> labelStatesMap;
private PrimitiveIntObjectMap<DiffSets<Long>> labelStatesMap;
private PrimitiveLongObjectMap<NodeStateImpl> nodeStatesMap;
private PrimitiveLongObjectMap<RelationshipStateImpl> relationshipStatesMap;

Expand Down Expand Up @@ -358,7 +357,21 @@ public Iterable<NodeState> modifiedNodes()

private DiffSets<Long> getOrCreateLabelStateNodeDiffSets( int labelId )
{
return LABEL_STATE.getOrCreate( this, labelId ).getOrCreateNodeDiffSets();
if ( labelStatesMap == null )
{
labelStatesMap = Primitive.intObjectMap();
}
return labelStatesMap.computeIfAbsent( labelId, unused -> new DiffSets<>() );
}

private ReadableDiffSets<Long> getLabelStateNodeDiffSets( int labelId )
{
if ( labelStatesMap == null )
{
return ReadableDiffSets.Empty.instance();
}
final DiffSets<Long> nodeDiffSets = labelStatesMap.get( labelId );
return ReadableDiffSets.Empty.ifNull( nodeDiffSets );
}

@Override
Expand Down Expand Up @@ -706,7 +719,7 @@ public Cursor<RelationshipItem> augmentRelationshipsGetAllCursor( Cursor<Relatio
@Override
public ReadableDiffSets<Long> nodesWithLabelChanged( int label )
{
return LABEL_STATE.get( this, label ).nodeDiffSets();
return getLabelStateNodeDiffSets( label );
}

@Override
Expand All @@ -718,7 +731,7 @@ public ReadableDiffSets<Long> nodesWithAnyOfLabelsChanged( int... labels )
Set<Long> removed = new HashSet<>();
for ( int i = 0; i < labels.length; i++ )
{
ReadableDiffSets<Long> nodeDiffSets = LABEL_STATE.get( this, labels[i] ).nodeDiffSets();
ReadableDiffSets<Long> nodeDiffSets = getLabelStateNodeDiffSets( labels[i] );
if ( i == 0 )
{
removed.addAll( nodeDiffSets.getRemoved() );
Expand All @@ -739,9 +752,9 @@ public ReadableDiffSets<Long> nodesWithAllLabelsChanged( int... labels )
DiffSets<Long> changes = new DiffSets<>();
for ( int label : labels )
{
LabelState labelState = LABEL_STATE.get( this, label );
changes.addAll( labelState.nodeDiffSets().getAdded().iterator() );
changes.removeAll( labelState.nodeDiffSets().getRemoved().iterator() );
final ReadableDiffSets<Long> nodeDiffSets = getLabelStateNodeDiffSets( label );
changes.addAll( nodeDiffSets.getAdded().iterator() );
changes.removeAll( nodeDiffSets.getRemoved().iterator() );
}
return changes;
}
Expand Down Expand Up @@ -1333,21 +1346,6 @@ public void visitRemoved( ConstraintDescriptor constraint ) throws ConstraintVal
}
}

private static class TransactionLabelState extends LabelState.Defaults
{
@Override
PrimitiveLongObjectMap<LabelState.Mutable> getMap( TxState state )
{
return state.labelStatesMap;
}

@Override
void setMap( TxState state, PrimitiveLongObjectMap<LabelState.Mutable> map )
{
state.labelStatesMap = map;
}
}

private static class TransactionNodeState extends NodeStateImpl.Defaults
{
@Override
Expand Down

0 comments on commit 80449d6

Please sign in to comment.