Skip to content

Commit

Permalink
Return sets instead of collections in Kernel APIs where uniqueness
Browse files Browse the repository at this point in the history
semantic is implied by design
  • Loading branch information
Andrei Koval committed Feb 16, 2018
1 parent d999c2a commit 0157562
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 26 deletions.
Expand Up @@ -21,7 +21,6 @@


import java.util.Set; import java.util.Set;


import org.neo4j.collection.primitive.PrimitiveIntCollection;
import org.neo4j.collection.primitive.PrimitiveIntSet; import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.collection.primitive.PrimitiveIntVisitor; import org.neo4j.collection.primitive.PrimitiveIntVisitor;
import org.neo4j.cursor.Cursor; import org.neo4j.cursor.Cursor;
Expand Down Expand Up @@ -134,7 +133,7 @@ public void visitNodeLabelChanges( long id, final Set<Integer> added, final Set<
super.visitNodeLabelChanges( id, added, removed ); super.visitNodeLabelChanges( id, added, removed );
} }


private void updateRelationshipsCountsFromDegrees( PrimitiveIntCollection labels, int type, long outgoing, private void updateRelationshipsCountsFromDegrees( PrimitiveIntSet labels, int type, long outgoing,
long incoming ) long incoming )
{ {
labels.visitKeys( label -> updateRelationshipsCountsFromDegrees( type, label, outgoing, incoming ) ); labels.visitKeys( label -> updateRelationshipsCountsFromDegrees( type, label, outgoing, incoming ) );
Expand Down
Expand Up @@ -23,7 +23,6 @@


import java.util.Iterator; import java.util.Iterator;


import org.neo4j.collection.primitive.PrimitiveIntCollection;
import org.neo4j.collection.primitive.PrimitiveIntCollections; import org.neo4j.collection.primitive.PrimitiveIntCollections;
import org.neo4j.collection.primitive.PrimitiveIntIterator; import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.collection.primitive.PrimitiveIntSet; import org.neo4j.collection.primitive.PrimitiveIntSet;
Expand Down Expand Up @@ -510,7 +509,7 @@ public boolean nodeHasProperty( KernelStatement statement, NodeItem node, int pr
} }


@Override @Override
public PrimitiveIntCollection nodeGetPropertyKeys( KernelStatement statement, NodeItem node ) public PrimitiveIntSet nodeGetPropertyKeys( KernelStatement statement, NodeItem node )
{ {
return entityReadOperations.nodeGetPropertyKeys( statement, node ); return entityReadOperations.nodeGetPropertyKeys( statement, node );
} }
Expand All @@ -535,7 +534,7 @@ public boolean relationshipHasProperty( KernelStatement statement, RelationshipI
} }


@Override @Override
public PrimitiveIntCollection relationshipGetPropertyKeys( KernelStatement statement, public PrimitiveIntSet relationshipGetPropertyKeys( KernelStatement statement,
RelationshipItem relationship ) RelationshipItem relationship )
{ {
return entityReadOperations.relationshipGetPropertyKeys( statement, relationship ); return entityReadOperations.relationshipGetPropertyKeys( statement, relationship );
Expand Down
Expand Up @@ -24,10 +24,8 @@
import java.util.Map; import java.util.Map;


import org.neo4j.collection.primitive.Primitive; import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntCollection;
import org.neo4j.collection.primitive.PrimitiveIntIterator; import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.collection.primitive.PrimitiveIntSet; import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.collection.primitive.PrimitiveIntStack;
import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.collection.primitive.PrimitiveLongResourceIterator; import org.neo4j.collection.primitive.PrimitiveLongResourceIterator;
import org.neo4j.cursor.Cursor; import org.neo4j.cursor.Cursor;
Expand Down Expand Up @@ -267,14 +265,14 @@ public Cursor<PropertyItem> nodeGetProperties( KernelStatement statement, NodeIt
} }


@Override @Override
public PrimitiveIntCollection nodeGetPropertyKeys( KernelStatement statement, NodeItem node ) public PrimitiveIntSet nodeGetPropertyKeys( KernelStatement statement, NodeItem node )
{ {
PrimitiveIntStack keys = new PrimitiveIntStack(); final PrimitiveIntSet keys = Primitive.intSet();
try ( Cursor<PropertyItem> properties = nodeGetProperties( statement, node ) ) try ( Cursor<PropertyItem> properties = nodeGetProperties( statement, node ) )
{ {
while ( properties.next() ) while ( properties.next() )
{ {
keys.push( properties.get().propertyKeyId() ); keys.add( properties.get().propertyKeyId() );
} }
} }


Expand Down Expand Up @@ -347,15 +345,15 @@ public Cursor<PropertyItem> relationshipGetProperties( KernelStatement statement
} }


@Override @Override
public PrimitiveIntCollection relationshipGetPropertyKeys( KernelStatement statement, public PrimitiveIntSet relationshipGetPropertyKeys( KernelStatement statement,
RelationshipItem relationship ) RelationshipItem relationship )
{ {
PrimitiveIntStack keys = new PrimitiveIntStack(); final PrimitiveIntSet keys = Primitive.intSet();
try ( Cursor<PropertyItem> properties = relationshipGetProperties( statement, relationship ) ) try ( Cursor<PropertyItem> properties = relationshipGetProperties( statement, relationship ) )
{ {
while ( properties.next() ) while ( properties.next() )
{ {
keys.push( properties.get().propertyKeyId() ); keys.add( properties.get().propertyKeyId() );
} }
} }


Expand Down
Expand Up @@ -28,9 +28,9 @@
import java.util.function.BiConsumer; import java.util.function.BiConsumer;


import org.neo4j.collection.primitive.Primitive; import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntCollection;
import org.neo4j.collection.primitive.PrimitiveIntIterator; import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveIntObjectMap;
import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.collection.primitive.PrimitiveLongObjectMap;
Expand Down Expand Up @@ -145,7 +145,7 @@ public Iterable<IndexProxy> getAllIndexProxies()
* @return set of LabelSchemaDescriptors describing the potentially affected indexes * @return set of LabelSchemaDescriptors describing the potentially affected indexes
*/ */
public Set<LabelSchemaDescriptor> getRelatedIndexes( public Set<LabelSchemaDescriptor> getRelatedIndexes(
long[] changedLabels, long[] unchangedLabels, PrimitiveIntCollection properties ) long[] changedLabels, long[] unchangedLabels, PrimitiveIntSet properties )
{ {
if ( changedLabels.length == 1 && properties.isEmpty() ) if ( changedLabels.length == 1 && properties.isEmpty() )
{ {
Expand Down Expand Up @@ -269,7 +269,7 @@ private static Map<LabelSchemaDescriptor, Long> indexIdsByDescriptor( PrimitiveL
*/ */
private Set<LabelSchemaDescriptor> getDescriptorsByProperties( private Set<LabelSchemaDescriptor> getDescriptorsByProperties(
long[] unchangedLabels, long[] unchangedLabels,
PrimitiveIntCollection properties ) PrimitiveIntSet properties )
{ {
int nIndexesForLabels = countIndexesByLabels( unchangedLabels ); int nIndexesForLabels = countIndexesByLabels( unchangedLabels );
int nIndexesForProperties = countIndexesByProperties( properties ); int nIndexesForProperties = countIndexesByProperties( properties );
Expand Down Expand Up @@ -316,7 +316,7 @@ private int countIndexesByLabels( long[] labels )
return count; return count;
} }


private Set<LabelSchemaDescriptor> extractIndexesByProperties( PrimitiveIntCollection properties ) private Set<LabelSchemaDescriptor> extractIndexesByProperties( PrimitiveIntSet properties )
{ {
Set<LabelSchemaDescriptor> set = new HashSet<>(); Set<LabelSchemaDescriptor> set = new HashSet<>();
for ( PrimitiveIntIterator iterator = properties.iterator(); iterator.hasNext(); ) for ( PrimitiveIntIterator iterator = properties.iterator(); iterator.hasNext(); )
Expand All @@ -330,7 +330,7 @@ private Set<LabelSchemaDescriptor> extractIndexesByProperties( PrimitiveIntColle
return set; return set;
} }


private int countIndexesByProperties( PrimitiveIntCollection properties ) private int countIndexesByProperties( PrimitiveIntSet properties )
{ {
int count = 0; int count = 0;
for ( PrimitiveIntIterator iterator = properties.iterator(); iterator.hasNext(); ) for ( PrimitiveIntIterator iterator = properties.iterator(); iterator.hasNext(); )
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/ */
package org.neo4j.kernel.impl.api.index; package org.neo4j.kernel.impl.api.index;


import org.neo4j.collection.primitive.PrimitiveIntCollection; import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.function.ThrowingFunction; import org.neo4j.function.ThrowingFunction;
import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException;
Expand Down Expand Up @@ -100,7 +100,7 @@ public Iterable<IndexProxy> getAllIndexProxies()
} }


public Iterable<LabelSchemaDescriptor> getRelatedIndexes( public Iterable<LabelSchemaDescriptor> getRelatedIndexes(
long[] changedLabels, long[] unchangedLabels, PrimitiveIntCollection properties ) long[] changedLabels, long[] unchangedLabels, PrimitiveIntSet properties )
{ {
return indexMap.getRelatedIndexes( changedLabels, unchangedLabels, properties ); return indexMap.getRelatedIndexes( changedLabels, unchangedLabels, properties );
} }
Expand Down
Expand Up @@ -25,7 +25,6 @@


import org.neo4j.collection.primitive.Primitive; import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveArrays; import org.neo4j.collection.primitive.PrimitiveArrays;
import org.neo4j.collection.primitive.PrimitiveIntCollection;
import org.neo4j.collection.primitive.PrimitiveIntIterator; import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveIntObjectMap;
import org.neo4j.collection.primitive.PrimitiveIntSet; import org.neo4j.collection.primitive.PrimitiveIntSet;
Expand All @@ -37,6 +36,7 @@


import static java.lang.String.format; import static java.lang.String.format;
import static java.util.Arrays.binarySearch; import static java.util.Arrays.binarySearch;
import static org.neo4j.collection.primitive.PrimitiveIntCollections.asSet;
import static org.neo4j.kernel.impl.api.index.NodeUpdates.PropertyValueType.Changed; import static org.neo4j.kernel.impl.api.index.NodeUpdates.PropertyValueType.Changed;
import static org.neo4j.kernel.impl.api.index.NodeUpdates.PropertyValueType.NoValue; import static org.neo4j.kernel.impl.api.index.NodeUpdates.PropertyValueType.NoValue;


Expand Down Expand Up @@ -138,11 +138,11 @@ long[] labelsUnchanged()
return PrimitiveArrays.intersect( labelsBefore, labelsAfter ); return PrimitiveArrays.intersect( labelsBefore, labelsAfter );
} }


PrimitiveIntCollection propertiesChanged() PrimitiveIntSet propertiesChanged()
{ {
assert !hasLoadedAdditionalProperties : "Calling propertiesChanged() is not valid after non-changed " + assert !hasLoadedAdditionalProperties : "Calling propertiesChanged() is not valid after non-changed " +
"properties have already been loaded."; "properties have already been loaded.";
return knownProperties; return asSet( knownProperties.iterator() );
} }


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


import org.neo4j.collection.primitive.PrimitiveIntCollection;
import org.neo4j.collection.primitive.PrimitiveIntIterator; import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.collection.primitive.PrimitiveIntSet; import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;
Expand Down Expand Up @@ -106,15 +105,15 @@ Cursor<RelationshipItem> nodeGetRelationships( KernelStatement statement, NodeIt


boolean nodeHasProperty( KernelStatement statement, NodeItem node, int propertyKeyId ); boolean nodeHasProperty( KernelStatement statement, NodeItem node, int propertyKeyId );


PrimitiveIntCollection nodeGetPropertyKeys( KernelStatement statement, NodeItem node ); PrimitiveIntSet nodeGetPropertyKeys( KernelStatement statement, NodeItem node );


Cursor<PropertyItem> relationshipGetProperties( KernelStatement statement, RelationshipItem relationship ); Cursor<PropertyItem> relationshipGetProperties( KernelStatement statement, RelationshipItem relationship );


Value relationshipGetProperty( KernelStatement statement, RelationshipItem relationship, int propertyKeyId ); Value relationshipGetProperty( KernelStatement statement, RelationshipItem relationship, int propertyKeyId );


boolean relationshipHasProperty( KernelStatement statement, RelationshipItem relationship, int propertyKeyId ); boolean relationshipHasProperty( KernelStatement statement, RelationshipItem relationship, int propertyKeyId );


PrimitiveIntCollection relationshipGetPropertyKeys( KernelStatement statement, RelationshipItem relationship ); PrimitiveIntSet relationshipGetPropertyKeys( KernelStatement statement, RelationshipItem relationship );


long nodesGetCount( KernelStatement statement ); long nodesGetCount( KernelStatement statement );


Expand Down

0 comments on commit 0157562

Please sign in to comment.