From 699ae0e3e7d1b9bf94505e1bbf4f1dea4c2738da Mon Sep 17 00:00:00 2001 From: Andrei Koval Date: Tue, 20 Mar 2018 21:42:17 +0100 Subject: [PATCH] Replaced PrimitiveIntObjectMap --- .../checking/full/MandatoryProperties.java | 11 +- .../full/PropertyAndNodeIndexedCheck.java | 16 +- .../graphalgo/impl/path/ShortestPath.java | 8 +- .../neo4j/graphdb/traversal/LevelUnique.java | 6 +- .../neo4j/kernel/impl/api/index/IndexMap.java | 15 +- .../kernel/impl/api/index/NodeUpdates.java | 39 +- .../PropertyPhysicalToLogicalConverter.java | 31 +- .../neo4j/kernel/impl/api/state/TxState.java | 95 +- .../kernel/impl/api/store/SchemaCache.java | 21 +- .../kernel/impl/index/IndexDefineCommand.java | 23 +- .../kernel/impl/locking/ResourceTypes.java | 7 +- .../community/CommunityLockClient.java | 49 +- .../DefaultRelationshipGroupCursor.java | 9 +- .../TransactionToRecordStateVisitor.java | 6 +- .../util/collection/CollectionsFactory.java | 4 +- .../collection/OffHeapCollectionsFactory.java | 7 +- .../collection/OnHeapCollectionsFactory.java | 7 +- .../api/txstate/TxStateVisitor.java | 24 +- .../internal/BatchTokenHolder.java | 7 +- .../input/InputEntityCacheReader.java | 17 +- .../impl/api/KernelTransactionTestBase.java | 4 +- .../kernel/impl/api/state/TxStateTest.java | 4 +- .../NativeAllEntriesLabelScanReaderTest.java | 6 +- .../OffHeapCollectionsFactoryTest.java | 4 +- .../neo4j/collection/primitive/Primitive.java | 12 - .../primitive/PrimitiveIntCollections.java | 11 - .../primitive/PrimitiveIntObjectMap.java | 52 -- .../primitive/PrimitiveIntObjectVisitor.java | 34 - .../hopscotch/PrimitiveIntObjectHashMap.java | 168 ---- .../PrimitiveIntCollectionsTest.java | 240 ----- .../PrimitiveCollectionEqualityTest.java | 34 - .../PrimitiveIntObjectHashMapTest.java | 48 - .../hopscotch/PrimitiveLongMapTest.java | 879 ------------------ .../token/ReplicatedTokenHolderTest.java | 2 +- .../enterprise/PropertyExistenceEnforcer.java | 12 +- 35 files changed, 178 insertions(+), 1734 deletions(-) delete mode 100644 community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntObjectMap.java delete mode 100644 community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntObjectVisitor.java delete mode 100644 community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/PrimitiveIntObjectHashMap.java delete mode 100644 community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveIntCollectionsTest.java delete mode 100644 community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveIntObjectHashMapTest.java delete mode 100644 community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveLongMapTest.java diff --git a/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/MandatoryProperties.java b/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/MandatoryProperties.java index 3125fac0895a1..c211e8c93e6dc 100644 --- a/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/MandatoryProperties.java +++ b/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/MandatoryProperties.java @@ -20,15 +20,14 @@ package org.neo4j.consistency.checking.full; import org.eclipse.collections.api.iterator.IntIterator; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.MutableIntSet; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; import java.util.Arrays; import java.util.function.Function; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; - import org.neo4j.consistency.RecordType; import org.neo4j.consistency.report.ConsistencyReport; import org.neo4j.consistency.report.ConsistencyReporter; @@ -46,8 +45,8 @@ public class MandatoryProperties { - private final PrimitiveIntObjectMap nodes = Primitive.intObjectMap(); - private final PrimitiveIntObjectMap relationships = Primitive.intObjectMap(); + private final MutableIntObjectMap nodes = new IntObjectHashMap<>(); + private final MutableIntObjectMap relationships = new IntObjectHashMap<>(); private final StoreAccess storeAccess; public MandatoryProperties( StoreAccess storeAccess ) @@ -138,7 +137,7 @@ private Iterable constraintsIgnoringMalformed( SchemaStorage sch return schemaStorage::constraintsGetAllIgnoreMalformed; } - private static void recordConstraint( int labelOrRelType, int propertyKey, PrimitiveIntObjectMap storage ) + private static void recordConstraint( int labelOrRelType, int propertyKey, MutableIntObjectMap storage ) { int[] propertyKeys = storage.get( labelOrRelType ); if ( propertyKeys == null ) diff --git a/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyAndNodeIndexedCheck.java b/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyAndNodeIndexedCheck.java index fdd40ad56809a..39dffb534b146 100644 --- a/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyAndNodeIndexedCheck.java +++ b/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyAndNodeIndexedCheck.java @@ -20,7 +20,10 @@ package org.neo4j.consistency.checking.full; import org.eclipse.collections.api.iterator.LongIterator; +import org.eclipse.collections.api.map.primitive.IntObjectMap; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.MutableIntSet; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; import java.util.Arrays; @@ -28,9 +31,6 @@ import java.util.List; import java.util.Set; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; - import org.neo4j.consistency.checking.ChainCheck; import org.neo4j.consistency.checking.CheckerEngine; import org.neo4j.consistency.checking.RecordCheck; @@ -94,7 +94,7 @@ private void matchIndexesToNode( Collection propertyRecs ) { Set labels = NodeLabelReader.getListOfLabels( record, records, engine ); - PrimitiveIntObjectMap nodePropertyMap = null; + IntObjectMap nodePropertyMap = null; for ( IndexRule indexRule : indexes.onlineRules() ) { long labelId = indexRule.schema().keyId(); @@ -200,7 +200,7 @@ private void checkProperty( NodeRecord record, } } - private Value[] getPropertyValues( PrimitiveIntObjectMap propertyMap, int[] indexPropertyIds ) + private Value[] getPropertyValues( IntObjectMap propertyMap, int[] indexPropertyIds ) { Value[] values = new Value[indexPropertyIds.length]; for ( int i = 0; i < indexPropertyIds.length; i++ ) @@ -211,9 +211,9 @@ private Value[] getPropertyValues( PrimitiveIntObjectMap property return values; } - private PrimitiveIntObjectMap properties( List propertyBlocks ) + private IntObjectMap properties( List propertyBlocks ) { - PrimitiveIntObjectMap propertyIds = Primitive.intObjectMap(); + final MutableIntObjectMap propertyIds = new IntObjectHashMap<>(); for ( PropertyBlock propertyBlock : propertyBlocks ) { propertyIds.put( propertyBlock.getKeyIndexId(), propertyBlock ); @@ -252,7 +252,7 @@ private LongIterator queryIndexOrEmpty( IndexReader reader, IndexQuery[] query ) } private static boolean nodeHasSchemaProperties( - PrimitiveIntObjectMap nodePropertyMap, int[] indexPropertyIds ) + IntObjectMap nodePropertyMap, int[] indexPropertyIds ) { for ( int indexPropertyId : indexPropertyIds ) { diff --git a/community/graph-algo/src/main/java/org/neo4j/graphalgo/impl/path/ShortestPath.java b/community/graph-algo/src/main/java/org/neo4j/graphalgo/impl/path/ShortestPath.java index ed661a7cf47c3..f3d8a2576dac2 100644 --- a/community/graph-algo/src/main/java/org/neo4j/graphalgo/impl/path/ShortestPath.java +++ b/community/graph-algo/src/main/java/org/neo4j/graphalgo/impl/path/ShortestPath.java @@ -21,6 +21,8 @@ import org.apache.commons.lang3.mutable.MutableBoolean; import org.apache.commons.lang3.mutable.MutableInt; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import java.util.ArrayList; import java.util.Arrays; @@ -33,8 +35,6 @@ import java.util.LinkedList; import java.util.Map; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.graphalgo.PathFinder; import org.neo4j.graphalgo.impl.util.PathImpl; import org.neo4j.graphalgo.impl.util.PathImpl.Builder; @@ -572,13 +572,13 @@ void addRel( Relationship rel ) // One long lived instance private static class Hits { - private final PrimitiveIntObjectMap> hits = Primitive.intObjectMap(); + private final MutableIntObjectMap> hits = new IntObjectHashMap<>(); private int lowestDepth; private int totalHitCount; int add( Hit hit, int atDepth ) { - Collection depthHits = hits.computeIfAbsent( atDepth, k -> new HashSet<>() ); + Collection depthHits = hits.getIfAbsentPut( atDepth, HashSet::new ); if ( depthHits.add( hit ) ) { totalHitCount++; diff --git a/community/graphdb-api/src/main/java/org/neo4j/graphdb/traversal/LevelUnique.java b/community/graphdb-api/src/main/java/org/neo4j/graphdb/traversal/LevelUnique.java index 0813dd8694174..42f6c9c016d26 100644 --- a/community/graphdb-api/src/main/java/org/neo4j/graphdb/traversal/LevelUnique.java +++ b/community/graphdb-api/src/main/java/org/neo4j/graphdb/traversal/LevelUnique.java @@ -19,16 +19,16 @@ */ package org.neo4j.graphdb.traversal; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.MutableLongSet; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.graphdb.Path; class LevelUnique extends AbstractUniquenessFilter { - private final PrimitiveIntObjectMap idsPerLevel = Primitive.intObjectMap(); + private final MutableIntObjectMap idsPerLevel = new IntObjectHashMap<>(); LevelUnique( PrimitiveTypeFetcher type ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexMap.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexMap.java index 4c376a112d15f..7dad7cb076ee2 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexMap.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexMap.java @@ -21,7 +21,9 @@ import org.eclipse.collections.api.iterator.IntIterator; import org.eclipse.collections.api.iterator.LongIterator; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.IntSet; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import java.util.Collections; import java.util.HashMap; @@ -32,7 +34,6 @@ import java.util.function.BiConsumer; import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.internal.kernel.api.schema.SchemaDescriptor; @@ -48,8 +49,8 @@ public final class IndexMap implements Cloneable private final PrimitiveLongObjectMap indexesById; private final Map indexesByDescriptor; private final Map indexIdsByDescriptor; - private final PrimitiveIntObjectMap> descriptorsByLabel; - private final PrimitiveIntObjectMap> descriptorsByProperty; + private final MutableIntObjectMap> descriptorsByLabel; + private final MutableIntObjectMap> descriptorsByProperty; public IndexMap() { @@ -69,8 +70,8 @@ private IndexMap( this.indexesById = indexesById; this.indexesByDescriptor = indexesByDescriptor; this.indexIdsByDescriptor = indexIdsByDescriptor; - this.descriptorsByLabel = Primitive.intObjectMap(); - this.descriptorsByProperty = Primitive.intObjectMap(); + this.descriptorsByLabel = new IntObjectHashMap<>(); + this.descriptorsByProperty = new IntObjectHashMap<>(); for ( SchemaDescriptor schema : indexesByDescriptor.keySet() ) { addDescriptorToLookups( schema ); @@ -214,7 +215,7 @@ private void addDescriptorToLookups( SchemaDescriptor schema ) private void addToLookup( int key, SchemaDescriptor schema, - PrimitiveIntObjectMap> lookup ) + MutableIntObjectMap> lookup ) { Set descriptors = lookup.get( key ); if ( descriptors == null ) @@ -228,7 +229,7 @@ private void addToLookup( private void removeFromLookup( int key, SchemaDescriptor schema, - PrimitiveIntObjectMap> lookup ) + MutableIntObjectMap> lookup ) { Set descriptors = lookup.get( key ); descriptors.remove( schema ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/NodeUpdates.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/NodeUpdates.java index 293c223623f12..f53ec5e1b3480 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/NodeUpdates.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/NodeUpdates.java @@ -20,17 +20,18 @@ package org.neo4j.kernel.impl.api.index; import org.eclipse.collections.api.iterator.IntIterator; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.set.primitive.MutableIntSet; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; -import org.neo4j.collection.primitive.Primitive; import org.neo4j.collection.primitive.PrimitiveArrays; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.helpers.collection.Iterables; import org.neo4j.internal.kernel.api.schema.SchemaDescriptor; import org.neo4j.internal.kernel.api.schema.SchemaDescriptorSupplier; @@ -39,7 +40,6 @@ import static java.lang.String.format; 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.NoValue; @@ -56,7 +56,7 @@ public class NodeUpdates implements PropertyLoader.PropertyLoadSink private final long[] labelsBefore; private final long[] labelsAfter; - private final PrimitiveIntObjectMap knownProperties; + private final MutableIntObjectMap knownProperties; private boolean hasLoadedAdditionalProperties; public static class Builder @@ -123,7 +123,7 @@ private NodeUpdates( long nodeId, long[] labelsBefore, long[] labelsAfter ) this.nodeId = nodeId; this.labelsBefore = labelsBefore; this.labelsAfter = labelsAfter; - this.knownProperties = Primitive.intObjectMap(); + this.knownProperties = new IntObjectHashMap<>(); } public final long getNodeId() @@ -145,7 +145,7 @@ IntSet propertiesChanged() { assert !hasLoadedAdditionalProperties : "Calling propertiesChanged() is not valid after non-changed " + "properties have already been loaded."; - return asSet( knownProperties.intIterator() ); + return knownProperties.keySet().toImmutable(); } @Override @@ -369,13 +369,12 @@ public String toString() StringBuilder result = new StringBuilder( getClass().getSimpleName() ).append( "[" ).append( nodeId ); result.append( ", labelsBefore:" ).append( Arrays.toString( labelsBefore ) ); result.append( ", labelsAfter:" ).append( Arrays.toString( labelsAfter ) ); - knownProperties.visitEntries( ( key, propertyValue ) -> + knownProperties.forEachKeyValue( ( key, propertyValue ) -> { result.append( ", " ); result.append( key ); result.append( " -> " ); result.append( propertyValue ); - return false; } ); return result.append( ']' ).toString(); } @@ -389,7 +388,7 @@ public int hashCode() result = prime * result + Arrays.hashCode( labelsAfter ); result = prime * result + (int) (nodeId ^ (nodeId >>> 32)); - final IntIterator propertyKeyIds = knownProperties.intIterator(); + final IntIterator propertyKeyIds = knownProperties.keySet().intIterator(); while ( propertyKeyIds.hasNext() ) { int propertyKeyId = propertyKeyIds.next(); @@ -418,27 +417,7 @@ public boolean equals( Object obj ) return Arrays.equals( labelsBefore, other.labelsBefore ) && Arrays.equals( labelsAfter, other.labelsAfter ) && nodeId == other.nodeId && - propertyMapEquals( knownProperties, other.knownProperties ); - } - - private boolean propertyMapEquals( - PrimitiveIntObjectMap a, - PrimitiveIntObjectMap b ) - { - if ( a.size() != b.size() ) - { - return false; - } - final IntIterator aIterator = a.intIterator(); - while ( aIterator.hasNext() ) - { - int key = aIterator.next(); - if ( !a.get( key ).equals( b.get( key ) ) ) - { - return false; - } - } - return true; + Objects.equals( knownProperties, other.knownProperties ); } enum PropertyValueType diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverter.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverter.java index 051218643b44d..8a4906510ee79 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverter.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverter.java @@ -20,21 +20,18 @@ package org.neo4j.kernel.impl.api.index; import org.eclipse.collections.api.iterator.IntIterator; +import org.eclipse.collections.api.map.primitive.IntObjectMap; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; +import org.eclipse.collections.api.set.primitive.MutableIntSet; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; +import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; -import java.util.Iterator; - -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.kernel.impl.store.PropertyStore; import org.neo4j.kernel.impl.store.record.PropertyBlock; import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.transaction.state.PropertyRecordChange; import org.neo4j.values.storable.Value; -import static org.neo4j.collection.primitive.PrimitiveIntCollections.concat; -import static org.neo4j.collection.primitive.PrimitiveIntCollections.deduplicate; -import static org.neo4j.helpers.collection.Iterators.asIterator; - public class PropertyPhysicalToLogicalConverter { private final PropertyStore propertyStore; @@ -50,8 +47,8 @@ public PropertyPhysicalToLogicalConverter( PropertyStore propertyStore ) public void convertPropertyRecord( long nodeId, Iterable changes, NodeUpdates.Builder properties ) { - PrimitiveIntObjectMap beforeMap = Primitive.intObjectMap(); - PrimitiveIntObjectMap afterMap = Primitive.intObjectMap(); + MutableIntObjectMap beforeMap = new IntObjectHashMap<>(); + MutableIntObjectMap afterMap = new IntObjectHashMap<>(); mapBlocks( nodeId, changes, beforeMap, afterMap ); final IntIterator uniqueIntIterator = uniqueIntIterator( beforeMap, afterMap ); @@ -90,16 +87,16 @@ else if ( beforeBlock != null ) } } - private IntIterator uniqueIntIterator( PrimitiveIntObjectMap beforeMap, - PrimitiveIntObjectMap afterMap ) + private IntIterator uniqueIntIterator( IntObjectMap beforeMap, IntObjectMap afterMap ) { - final Iterator intIterator = - asIterator( 2, beforeMap.intIterator(), afterMap.intIterator() ); - return deduplicate( concat( intIterator ) ); + final MutableIntSet keys = new IntHashSet(); + keys.addAll( beforeMap.keySet() ); + keys.addAll( afterMap.keySet() ); + return keys.intIterator(); } private void mapBlocks( long nodeId, Iterable changes, - PrimitiveIntObjectMap beforeMap, PrimitiveIntObjectMap afterMap ) + MutableIntObjectMap beforeMap, MutableIntObjectMap afterMap ) { for ( PropertyRecordChange change : changes ) { @@ -115,7 +112,7 @@ private void equalCheck( long nodeId, long expectedNodeId ) assert nodeId == expectedNodeId : "Node id differs expected " + expectedNodeId + ", but was " + nodeId; } - private void mapBlocks( PropertyRecord record, PrimitiveIntObjectMap blocks ) + private void mapBlocks( PropertyRecord record, MutableIntObjectMap blocks ) { for ( PropertyBlock block : record ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/TxState.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/TxState.java index 99adcd50796fd..0da37f66e2b97 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/TxState.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/TxState.java @@ -20,6 +20,7 @@ package org.neo4j.kernel.impl.api.state; import org.eclipse.collections.api.iterator.LongIterator; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.set.primitive.MutableIntSet; import org.eclipse.collections.api.set.primitive.MutableLongSet; @@ -33,8 +34,6 @@ import java.util.TreeMap; import java.util.function.Consumer; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; -import org.neo4j.collection.primitive.PrimitiveIntObjectVisitor; import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.cursor.Cursor; import org.neo4j.helpers.collection.Iterables; @@ -103,13 +102,13 @@ public class TxState implements TransactionState, RelationshipVisitor.Home */ private final CollectionsFactory collectionsFactory; - private PrimitiveIntObjectMap> labelStatesMap; + private MutableIntObjectMap> labelStatesMap; private PrimitiveLongObjectMap nodeStatesMap; private PrimitiveLongObjectMap relationshipStatesMap; - private PrimitiveIntObjectMap createdLabelTokens; - private PrimitiveIntObjectMap createdPropertyKeyTokens; - private PrimitiveIntObjectMap createdRelationshipTypeTokens; + private MutableIntObjectMap createdLabelTokens; + private MutableIntObjectMap createdPropertyKeyTokens; + private MutableIntObjectMap createdRelationshipTypeTokens; private GraphState graphState; private DiffSets indexChanges; @@ -234,17 +233,17 @@ public void accept( final TxStateVisitor visitor ) if ( createdLabelTokens != null ) { - createdLabelTokens.visitEntries( new LabelTokenStateVisitor( visitor ) ); + createdLabelTokens.forEachKeyValue( visitor::visitCreatedLabelToken ); } if ( createdPropertyKeyTokens != null ) { - createdPropertyKeyTokens.visitEntries( new PropertyKeyTokenStateVisitor( visitor ) ); + createdPropertyKeyTokens.forEachKeyValue( visitor::visitCreatedPropertyKeyToken ); } if ( createdRelationshipTypeTokens != null ) { - createdRelationshipTypeTokens.visitEntries( new RelationshipTypeTokenStateVisitor( visitor ) ); + createdRelationshipTypeTokens.forEachKeyValue( visitor::visitCreatedRelationshipTypeToken ); } } @@ -369,7 +368,7 @@ private DiffSets getOrCreateLabelStateNodeDiffSets( int labelId ) { labelStatesMap = collectionsFactory.newIntObjectMap(); } - return labelStatesMap.computeIfAbsent( labelId, unused -> new DiffSets<>() ); + return labelStatesMap.getIfAbsentPut( labelId, DiffSets::new ); } private ReadableDiffSets getLabelStateNodeDiffSets( int labelId ) @@ -1287,18 +1286,19 @@ public void release() { return; } - if ( labelStatesMap != null ) - { - labelStatesMap.close(); - } - if ( createdLabelTokens != null ) - { - createdLabelTokens.close(); - } - if ( createdRelationshipTypeTokens != null ) - { - createdRelationshipTypeTokens.close(); - } + // todo ak +// if ( labelStatesMap != null ) +// { +// labelStatesMap.close(); +// } +// if ( createdLabelTokens != null ) +// { +// createdLabelTokens.close(); +// } +// if ( createdRelationshipTypeTokens != null ) +// { +// createdRelationshipTypeTokens.close(); +// } if ( nodeStatesMap != null ) { nodeStatesMap.close(); @@ -1318,57 +1318,6 @@ public void release() // } } - private static class LabelTokenStateVisitor implements PrimitiveIntObjectVisitor - { - private final TxStateVisitor visitor; - - LabelTokenStateVisitor( TxStateVisitor visitor ) - { - this.visitor = visitor; - } - - @Override - public boolean visited( int key, String value ) - { - visitor.visitCreatedLabelToken( value, key ); - return false; - } - } - - private static class PropertyKeyTokenStateVisitor implements PrimitiveIntObjectVisitor - { - private final TxStateVisitor visitor; - - PropertyKeyTokenStateVisitor( TxStateVisitor visitor ) - { - this.visitor = visitor; - } - - @Override - public boolean visited( int key, String value ) - { - visitor.visitCreatedPropertyKeyToken( value, key ); - return false; - } - } - - private static class RelationshipTypeTokenStateVisitor implements PrimitiveIntObjectVisitor - { - private final TxStateVisitor visitor; - - RelationshipTypeTokenStateVisitor( TxStateVisitor visitor ) - { - this.visitor = visitor; - } - - @Override - public boolean visited( int key, String value ) - { - visitor.visitCreatedRelationshipTypeToken( value, key ); - return false; - } - } - private static class ConstraintDiffSetsVisitor implements DiffSetsVisitor { private final TxStateVisitor visitor; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/SchemaCache.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/SchemaCache.java index 339b6622a47e3..4805e8f9a63e1 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/SchemaCache.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/SchemaCache.java @@ -19,6 +19,9 @@ */ package org.neo4j.kernel.impl.api.store; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -31,8 +34,6 @@ import java.util.function.Function; import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntCollections; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.helpers.collection.Iterators; @@ -178,10 +179,10 @@ private static class SchemaCacheState private final PrimitiveLongObjectMap constraintRuleById; private final Map indexDescriptors; - private final PrimitiveIntObjectMap> indexDescriptorsByLabel; + private final MutableIntObjectMap> indexDescriptorsByLabel; private final Map,Object> dependantState; - private final PrimitiveIntObjectMap> indexByProperty; + private final MutableIntObjectMap> indexByProperty; SchemaCacheState( ConstraintSemantics constraintSemantics, Iterable rules ) { @@ -191,9 +192,9 @@ private static class SchemaCacheState this.constraintRuleById = Primitive.longObjectMap(); this.indexDescriptors = new HashMap<>(); - this.indexDescriptorsByLabel = Primitive.intObjectMap(); + this.indexDescriptorsByLabel = new IntObjectHashMap<>(); this.dependantState = new HashMap<>(); - this.indexByProperty = Primitive.intObjectMap(); + this.indexByProperty = new IntObjectHashMap<>(); load( rules ); } @@ -205,9 +206,9 @@ private static class SchemaCacheState this.constraints = new HashSet<>( schemaCacheState.constraints ); this.indexDescriptors = new HashMap<>( schemaCacheState.indexDescriptors ); - this.indexDescriptorsByLabel = PrimitiveIntCollections.copy( schemaCacheState.indexDescriptorsByLabel ); + this.indexDescriptorsByLabel = IntObjectHashMap.newMap( schemaCacheState.indexDescriptorsByLabel ); this.dependantState = new HashMap<>(); - this.indexByProperty = PrimitiveIntCollections.copy( schemaCacheState.indexByProperty ); + this.indexByProperty = IntObjectHashMap.newMap( schemaCacheState.indexByProperty ); } private void load( Iterable schemaRuleIterator ) @@ -287,13 +288,13 @@ else if ( rule instanceof IndexRule ) indexDescriptors.put( schemaDescriptor, schemaIndexDescriptor ); Set forLabel = - indexDescriptorsByLabel.computeIfAbsent( schemaDescriptor.keyId(), k -> new HashSet<>() ); + indexDescriptorsByLabel.getIfAbsentPut( schemaDescriptor.keyId(), HashSet::new ); forLabel.add( schemaIndexDescriptor ); for ( int propertyId : indexRule.schema().getPropertyIds() ) { List indexesForProperty = - indexByProperty.computeIfAbsent( propertyId, k -> new ArrayList<>() ); + indexByProperty.getIfAbsentPut( propertyId, ArrayList::new ); indexesForProperty.add( schemaIndexDescriptor ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/IndexDefineCommand.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/IndexDefineCommand.java index bde8d88d29845..56408d54d6192 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/IndexDefineCommand.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/IndexDefineCommand.java @@ -19,21 +19,22 @@ */ package org.neo4j.kernel.impl.index; +import org.eclipse.collections.api.map.primitive.IntObjectMap; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; + import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.kernel.impl.api.CommandVisitor; import org.neo4j.kernel.impl.transaction.command.Command; import org.neo4j.kernel.impl.transaction.command.NeoCommandType; import org.neo4j.storageengine.api.WritableChannel; import static java.lang.String.format; -import static org.neo4j.collection.primitive.Primitive.intObjectMap; import static org.neo4j.kernel.impl.util.IoPrimitiveUtils.write2bLengthAndString; /** @@ -53,15 +54,15 @@ public class IndexDefineCommand extends Command private final AtomicInteger nextKeyId = new AtomicInteger(); private Map indexNameIdRange; private Map keyIdRange; - private PrimitiveIntObjectMap idToIndexName; - private PrimitiveIntObjectMap idToKey; + private MutableIntObjectMap idToIndexName; + private MutableIntObjectMap idToKey; public IndexDefineCommand() { setIndexNameIdRange( new HashMap<>() ); setKeyIdRange( new HashMap<>() ); - idToIndexName = intObjectMap( 16 ); - idToKey = intObjectMap( 16 ); + idToIndexName = new IntObjectHashMap<>(); + idToKey = new IntObjectHashMap<>(); } public void init( Map indexNames, Map keys ) @@ -72,9 +73,9 @@ public void init( Map indexNames, Map keys ) idToKey = reverse( keys ); } - private static PrimitiveIntObjectMap reverse( Map map ) + private static MutableIntObjectMap reverse( Map map ) { - PrimitiveIntObjectMap result = Primitive.intObjectMap( map.size() ); + final MutableIntObjectMap result = new IntObjectHashMap<>( map.size() ); for ( Map.Entry entry : map.entrySet() ) { result.put( entry.getValue(), entry.getKey() ); @@ -82,7 +83,7 @@ private static PrimitiveIntObjectMap reverse( Map map ) return result; } - private static String getFromMap( PrimitiveIntObjectMap map, int id ) + private static String getFromMap( IntObjectMap map, int id ) { if ( id == -1 ) { @@ -116,7 +117,7 @@ public int getOrAssignKeyId( String key ) return getOrAssignId( keyIdRange, idToKey, nextKeyId, key ); } - private int getOrAssignId( Map stringToId, PrimitiveIntObjectMap idToString, + private int getOrAssignId( Map stringToId, MutableIntObjectMap idToString, AtomicInteger nextId, String string ) { if ( string == null ) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/ResourceTypes.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/ResourceTypes.java index 075036f7ee7e2..a6733d8e6e500 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/ResourceTypes.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/ResourceTypes.java @@ -19,10 +19,11 @@ */ package org.neo4j.kernel.impl.locking; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; + import java.lang.reflect.Array; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.hashing.HashFunction; import org.neo4j.helpers.Strings; import org.neo4j.internal.kernel.api.IndexQuery; @@ -47,7 +48,7 @@ public enum ResourceTypes implements ResourceType private static final boolean useStrongHashing = FeatureToggles.flag( ResourceTypes.class, "useStrongHashing", false ); - private static final PrimitiveIntObjectMap idToType = Primitive.intObjectMap(); + private static final MutableIntObjectMap idToType = new IntObjectHashMap<>(); private static final HashFunction indexEntryHash_2_2_0 = HashFunction.xorShift32(); private static final HashFunction indexEntryHash_4_x = HashFunction.incrementalXXH64(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/community/CommunityLockClient.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/community/CommunityLockClient.java index 7663861306730..493ea672e85e6 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/community/CommunityLockClient.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/community/CommunityLockClient.java @@ -19,6 +19,11 @@ */ package org.neo4j.kernel.impl.locking.community; +import org.eclipse.collections.api.block.procedure.Procedure; +import org.eclipse.collections.api.block.procedure.primitive.IntObjectProcedure; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; + import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -26,8 +31,6 @@ import java.util.stream.Stream; import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; -import org.neo4j.collection.primitive.PrimitiveIntObjectVisitor; import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.collection.primitive.PrimitiveLongObjectVisitor; import org.neo4j.kernel.impl.locking.ActiveLock; @@ -49,12 +52,12 @@ public class CommunityLockClient implements Locks.Client private final LockManagerImpl manager; private final LockTransaction lockTransaction = new LockTransaction(); - private final PrimitiveIntObjectMap> sharedLocks = Primitive.intObjectMap(); - private final PrimitiveIntObjectMap> exclusiveLocks = Primitive.intObjectMap(); + private final MutableIntObjectMap> sharedLocks = new IntObjectHashMap<>(); + private final MutableIntObjectMap> exclusiveLocks = new IntObjectHashMap<>(); private final PrimitiveLongObjectVisitor readReleaser; private final PrimitiveLongObjectVisitor writeReleaser; - private final PrimitiveIntObjectVisitor,RuntimeException> typeReadReleaser; - private final PrimitiveIntObjectVisitor,RuntimeException> typeWriteReleaser; + private final Procedure> typeReadReleaser; + private final Procedure> typeWriteReleaser; // To be able to close Locks.Client instance properly we should be able to do couple of things: // - have a possibility to prevent new clients to come @@ -80,17 +83,8 @@ public CommunityLockClient( LockManagerImpl manager ) return false; }; - typeReadReleaser = ( key, value ) -> - { - value.visitEntries( readReleaser ); - return false; - }; - - typeWriteReleaser = ( key, value ) -> - { - value.visitEntries( writeReleaser ); - return false; - }; + typeReadReleaser = value -> value.visitEntries( readReleaser ); + typeWriteReleaser = value -> value.visitEntries( writeReleaser ); } @Override @@ -354,8 +348,8 @@ public void close() private void releaseLocks() { - exclusiveLocks.visitEntries( typeWriteReleaser ); - sharedLocks.visitEntries( typeReadReleaser ); + exclusiveLocks.forEachValue( typeWriteReleaser ); + sharedLocks.forEachValue( typeReadReleaser ); exclusiveLocks.clear(); sharedLocks.clear(); } @@ -380,8 +374,8 @@ public int getLockSessionId() public Stream activeLocks() { List locks = new ArrayList<>(); - exclusiveLocks.visitEntries( collectActiveLocks( locks, ActiveLock.Factory.EXCLUSIVE_LOCK ) ); - sharedLocks.visitEntries( collectActiveLocks( locks, ActiveLock.Factory.SHARED_LOCK ) ); + exclusiveLocks.forEachKeyValue( collectActiveLocks( locks, ActiveLock.Factory.EXCLUSIVE_LOCK ) ); + sharedLocks.forEachKeyValue( collectActiveLocks( locks, ActiveLock.Factory.SHARED_LOCK ) ); return locks.stream(); } @@ -389,25 +383,23 @@ public Stream activeLocks() public long activeLockCount() { LockCounter counter = new LockCounter(); - exclusiveLocks.visitEntries( counter ); - sharedLocks.visitEntries( counter ); + exclusiveLocks.forEachKeyValue( counter ); + sharedLocks.forEachKeyValue( counter ); return counter.locks; } - private static class LockCounter - implements PrimitiveIntObjectVisitor,RuntimeException> + private static class LockCounter implements IntObjectProcedure> { long locks; @Override - public boolean visited( int key, PrimitiveLongObjectMap value ) + public void value( int key, PrimitiveLongObjectMap value ) { locks += value.size(); - return false; } } - private static PrimitiveIntObjectVisitor,RuntimeException> collectActiveLocks( + private static IntObjectProcedure> collectActiveLocks( List locks, ActiveLock.Factory activeLock ) { return ( typeId, exclusive ) -> @@ -418,7 +410,6 @@ private static PrimitiveIntObjectVisitor,Ru locks.add( activeLock.create( resourceType, resourceId ) ); return false; } ); - return false; }; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/DefaultRelationshipGroupCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/DefaultRelationshipGroupCursor.java index 804a7ecdfdba5..b8d844a15a7a3 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/DefaultRelationshipGroupCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/DefaultRelationshipGroupCursor.java @@ -21,12 +21,11 @@ import org.eclipse.collections.api.iterator.IntIterator; import org.eclipse.collections.api.iterator.LongIterator; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.MutableIntSet; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; - import org.neo4j.internal.kernel.api.RelationshipGroupCursor; import org.neo4j.internal.kernel.api.RelationshipTraversalCursor; import org.neo4j.io.pagecache.PageCursor; @@ -68,9 +67,9 @@ void buffer( long nodeReference, long relationshipReference, Read read ) setId( NO_ID ); setNext( NO_ID ); // TODO: read first record to get the required capacity (from the count value in the prev field) - try ( PrimitiveIntObjectMap buffer = Primitive.intObjectMap(); - PageCursor edgePage = read.relationshipPage( relationshipReference ) ) + try ( PageCursor edgePage = read.relationshipPage( relationshipReference ) ) { + final MutableIntObjectMap buffer = new IntObjectHashMap<>(); BufferedGroup current = null; while ( relationshipReference != NO_ID ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/TransactionToRecordStateVisitor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/TransactionToRecordStateVisitor.java index 394f525f2f003..ad83640048f2f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/TransactionToRecordStateVisitor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/TransactionToRecordStateVisitor.java @@ -264,19 +264,19 @@ public void visitRemovedConstraint( ConstraintDescriptor constraint ) } @Override - public void visitCreatedLabelToken( String name, int id ) + public void visitCreatedLabelToken( int id, String name ) { recordState.createLabelToken( name, id ); } @Override - public void visitCreatedPropertyKeyToken( String name, int id ) + public void visitCreatedPropertyKeyToken( int id, String name ) { recordState.createPropertyKeyToken( name, id ); } @Override - public void visitCreatedRelationshipTypeToken( String name, int id ) + public void visitCreatedRelationshipTypeToken( int id, String name ) { recordState.createRelationshipTypeToken( name, id ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/CollectionsFactory.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/CollectionsFactory.java index c9f131b9709a1..a923cd0e26a1e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/CollectionsFactory.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/CollectionsFactory.java @@ -19,9 +19,9 @@ */ package org.neo4j.kernel.impl.util.collection; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.MutableLongSet; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.kernel.impl.api.state.TxState; import org.neo4j.kernel.impl.util.diffsets.PrimitiveLongDiffSets; @@ -37,7 +37,7 @@ public interface CollectionsFactory PrimitiveLongObjectMap newLongObjectMap(); - PrimitiveIntObjectMap newIntObjectMap(); + MutableIntObjectMap newIntObjectMap(); PrimitiveLongDiffSets newLongDiffSets(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/OffHeapCollectionsFactory.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/OffHeapCollectionsFactory.java index 80603a365a300..eac694eb8bcf5 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/OffHeapCollectionsFactory.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/OffHeapCollectionsFactory.java @@ -19,10 +19,11 @@ */ package org.neo4j.kernel.impl.util.collection; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.MutableLongSet; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.kernel.impl.util.diffsets.PrimitiveLongDiffSets; import org.neo4j.memory.MemoryAllocationTracker; @@ -52,9 +53,9 @@ public PrimitiveLongObjectMap newLongObjectMap() } @Override - public PrimitiveIntObjectMap newIntObjectMap() + public MutableIntObjectMap newIntObjectMap() { - return Primitive.intObjectMap(); + return new IntObjectHashMap<>(); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/OnHeapCollectionsFactory.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/OnHeapCollectionsFactory.java index 1e7538d0a9606..0bb5cc167c07a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/OnHeapCollectionsFactory.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/collection/OnHeapCollectionsFactory.java @@ -20,11 +20,12 @@ package org.neo4j.kernel.impl.util.collection; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.MutableLongSet; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet; import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.kernel.impl.util.diffsets.PrimitiveLongDiffSets; import org.neo4j.memory.MemoryTracker; @@ -51,9 +52,9 @@ public PrimitiveLongObjectMap newLongObjectMap() } @Override - public PrimitiveIntObjectMap newIntObjectMap() + public MutableIntObjectMap newIntObjectMap() { - return Primitive.intObjectMap(); + return new IntObjectHashMap<>(); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/txstate/TxStateVisitor.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/txstate/TxStateVisitor.java index 5601265a168d6..43d868486a95b 100644 --- a/community/kernel/src/main/java/org/neo4j/storageengine/api/txstate/TxStateVisitor.java +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/txstate/TxStateVisitor.java @@ -62,11 +62,11 @@ void visitNodeLabelChanges( long id, Set added, Set removed ) void visitRemovedConstraint( ConstraintDescriptor element ); - void visitCreatedLabelToken( String name, int id ); + void visitCreatedLabelToken( int id, String name ); - void visitCreatedPropertyKeyToken( String name, int id ); + void visitCreatedPropertyKeyToken( int id, String name ); - void visitCreatedRelationshipTypeToken( String name, int id ); + void visitCreatedRelationshipTypeToken( int id, String name ); @Override void close(); @@ -137,17 +137,17 @@ public void visitRemovedConstraint( ConstraintDescriptor element ) } @Override - public void visitCreatedLabelToken( String name, int id ) + public void visitCreatedLabelToken( int id, String name ) { } @Override - public void visitCreatedPropertyKeyToken( String name, int id ) + public void visitCreatedPropertyKeyToken( int id, String name ) { } @Override - public void visitCreatedRelationshipTypeToken( String name, int id ) + public void visitCreatedRelationshipTypeToken( int id, String name ) { } @@ -248,21 +248,21 @@ public void visitRemovedConstraint( ConstraintDescriptor constraint ) } @Override - public void visitCreatedLabelToken( String name, int id ) + public void visitCreatedLabelToken( int id, String name ) { - actual.visitCreatedLabelToken( name, id ); + actual.visitCreatedLabelToken( id, name ); } @Override - public void visitCreatedPropertyKeyToken( String name, int id ) + public void visitCreatedPropertyKeyToken( int id, String name ) { - actual.visitCreatedPropertyKeyToken( name, id ); + actual.visitCreatedPropertyKeyToken( id, name ); } @Override - public void visitCreatedRelationshipTypeToken( String name, int id ) + public void visitCreatedRelationshipTypeToken( int id, String name ) { - actual.visitCreatedRelationshipTypeToken( name, id ); + actual.visitCreatedRelationshipTypeToken( id, name ); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchTokenHolder.java b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchTokenHolder.java index 48bee3651e150..2196bc6144227 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchTokenHolder.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchTokenHolder.java @@ -19,18 +19,19 @@ */ package org.neo4j.unsafe.batchinsert.internal; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; + import java.util.HashMap; import java.util.List; import java.util.Map; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.storageengine.api.Token; class BatchTokenHolder { private final Map nameToToken = new HashMap<>(); - private final PrimitiveIntObjectMap idToToken = Primitive.intObjectMap( 20 ); + private final MutableIntObjectMap idToToken = new IntObjectHashMap<>( 20 ); BatchTokenHolder( List tokens ) { diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/InputEntityCacheReader.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/InputEntityCacheReader.java index 35fb33fc07f04..c8a311abf7688 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/InputEntityCacheReader.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/InputEntityCacheReader.java @@ -19,12 +19,13 @@ */ package org.neo4j.unsafe.impl.batchimport.input; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; + import java.io.IOException; import java.nio.ByteBuffer; import java.util.Arrays; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.io.fs.StoreChannel; import org.neo4j.kernel.impl.transaction.log.ReadAheadChannel; import org.neo4j.kernel.impl.transaction.log.ReadableClosableChannel; @@ -51,7 +52,7 @@ abstract class InputEntityCacheReader implements InputIterator { // Used by workers, immutable - private final PrimitiveIntObjectMap[] tokens; + private final MutableIntObjectMap[] tokens; // Not used by workers private final StoreChannel channel; @@ -62,11 +63,11 @@ abstract class InputEntityCacheReader implements InputIterator InputEntityCacheReader( StoreChannel channel, StoreChannel header ) throws IOException { - tokens = new PrimitiveIntObjectMap[HIGH_TOKEN_TYPE]; - tokens[PROPERTY_KEY_TOKEN] = Primitive.intObjectMap(); - tokens[LABEL_TOKEN] = Primitive.intObjectMap(); - tokens[RELATIONSHIP_TYPE_TOKEN] = Primitive.intObjectMap(); - tokens[GROUP_TOKEN] = Primitive.intObjectMap(); + tokens = new MutableIntObjectMap[HIGH_TOKEN_TYPE]; + tokens[PROPERTY_KEY_TOKEN] = new IntObjectHashMap<>(); + tokens[LABEL_TOKEN] = new IntObjectHashMap<>(); + tokens[RELATIONSHIP_TYPE_TOKEN] = new IntObjectHashMap<>(); + tokens[GROUP_TOKEN] = new IntObjectHashMap<>(); this.channel = channel; readHeader( header ); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionTestBase.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionTestBase.java index d17f2a9c79989..01929f90069ec 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionTestBase.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionTestBase.java @@ -19,6 +19,7 @@ */ package org.neo4j.kernel.impl.api; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.MutableLongSet; import org.junit.Before; import org.mockito.Mockito; @@ -28,7 +29,6 @@ import java.util.function.Supplier; import org.neo4j.collection.pool.Pool; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.internal.kernel.api.Transaction.Type; @@ -204,7 +204,7 @@ public PrimitiveLongObjectMap newLongObjectMap() } @Override - public PrimitiveIntObjectMap newIntObjectMap() + public MutableIntObjectMap newIntObjectMap() { return OnHeapCollectionsFactory.INSTANCE.newIntObjectMap(); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateTest.java index 8fb19841d501c..b3e05a6ff1acc 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateTest.java @@ -19,6 +19,7 @@ */ package org.neo4j.kernel.impl.api.state; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -79,7 +80,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.neo4j.collection.primitive.Primitive.intObjectMap; import static org.neo4j.collection.primitive.PrimitiveIntCollections.toList; import static org.neo4j.collection.primitive.PrimitiveLongCollections.toSet; import static org.neo4j.helpers.collection.Iterators.asSet; @@ -1565,7 +1565,7 @@ public void shouldObserveCorrectAugmentedNodeRelationshipsState() public void useCollectionFactory() { final CollectionsFactory collectionsFactory = mock( CollectionsFactory.class ); - doAnswer( invocation -> intObjectMap() ).when( collectionsFactory ).newIntObjectMap(); + doAnswer( invocation -> new IntObjectHashMap<>() ).when( collectionsFactory ).newIntObjectMap(); state = new TxState( collectionsFactory ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/labelscan/NativeAllEntriesLabelScanReaderTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/labelscan/NativeAllEntriesLabelScanReaderTest.java index a5adbb39b5d06..9a1b1f302ec19 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/labelscan/NativeAllEntriesLabelScanReaderTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/labelscan/NativeAllEntriesLabelScanReaderTest.java @@ -19,6 +19,8 @@ */ package org.neo4j.kernel.impl.index.labelscan; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.junit.Rule; import org.junit.Test; @@ -31,8 +33,6 @@ import java.util.TreeMap; import java.util.function.IntFunction; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.cursor.RawCursor; import org.neo4j.helpers.collection.Pair; import org.neo4j.index.internal.gbptree.Hit; @@ -188,7 +188,7 @@ private static long highestRangeId( Labels[] data ) private static IntFunction,IOException>> store( Labels... labels ) { - PrimitiveIntObjectMap labelsMap = Primitive.intObjectMap( labels.length ); + final MutableIntObjectMap labelsMap = new IntObjectHashMap<>( labels.length ); for ( Labels item : labels ) { labelsMap.put( item.labelId, item ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/collection/OffHeapCollectionsFactoryTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/collection/OffHeapCollectionsFactoryTest.java index 27975df98f1a9..4731a2bc3d8ce 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/collection/OffHeapCollectionsFactoryTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/collection/OffHeapCollectionsFactoryTest.java @@ -19,12 +19,12 @@ */ package org.neo4j.kernel.impl.util.collection; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.MutableLongSet; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.kernel.impl.util.diffsets.PrimitiveLongDiffSets; import org.neo4j.memory.LocalMemoryTracker; @@ -109,7 +109,7 @@ public void intObjectMapAllocationAndRelease() { final long mem0 = memoryTracker.usedDirectMemory(); - final PrimitiveIntObjectMap map = factory.newIntObjectMap(); + final MutableIntObjectMap map = factory.newIntObjectMap(); map.put( 1, "foo" ); final long mem1 = memoryTracker.usedDirectMemory(); diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/Primitive.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/Primitive.java index aa85ce3c0a61b..02737868387ff 100644 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/Primitive.java +++ b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/Primitive.java @@ -26,9 +26,7 @@ import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet; -import org.neo4j.collection.primitive.hopscotch.IntKeyObjectValueTable; import org.neo4j.collection.primitive.hopscotch.LongKeyObjectValueTable; -import org.neo4j.collection.primitive.hopscotch.PrimitiveIntObjectHashMap; import org.neo4j.collection.primitive.hopscotch.PrimitiveLongObjectHashMap; import org.neo4j.memory.MemoryAllocationTracker; @@ -78,16 +76,6 @@ public static MutableIntSet offHeapIntSet( MemoryAllocationTracker allocationTra return new IntHashSet(); } - public static PrimitiveIntObjectMap intObjectMap() - { - return intObjectMap( DEFAULT_HEAP_CAPACITY ); - } - - public static PrimitiveIntObjectMap intObjectMap( int initialCapacity ) - { - return new PrimitiveIntObjectHashMap<>( new IntKeyObjectValueTable<>( initialCapacity ), NO_MONITOR ); - } - public static LongIterator iterator( final long... longs ) { return new LongIterator() diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntCollections.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntCollections.java index c095ada8a591e..57753150b0fbf 100644 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntCollections.java +++ b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntCollections.java @@ -318,17 +318,6 @@ public static MutableIntSet asSet( long[] values, LongToIntFunction converter ) return set; } - public static PrimitiveIntObjectMap copy( PrimitiveIntObjectMap original ) - { - PrimitiveIntObjectMap copy = Primitive.intObjectMap( original.size() ); - original.visitEntries( ( key, value ) -> - { - copy.put( key, value ); - return false; - } ); - return copy; - } - public static boolean contains( int[] values, int candidate ) { for ( int value : values ) diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntObjectMap.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntObjectMap.java deleted file mode 100644 index 630f2fb3c0ec4..0000000000000 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntObjectMap.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2002-2018 "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 . - */ -package org.neo4j.collection.primitive; - -import java.util.function.IntFunction; - -import static java.util.Objects.requireNonNull; - -public interface PrimitiveIntObjectMap extends PrimitiveIntCollection -{ - VALUE put( int key, VALUE value ); - - boolean containsKey( int key ); - - VALUE get( int key ); - - VALUE remove( int key ); - - /** - * Visit the entries of this map, until all have been visited or the visitor returns 'true'. - */ - void visitEntries( PrimitiveIntObjectVisitor visitor ) throws E; - - default VALUE computeIfAbsent( int key, IntFunction function ) - { - requireNonNull( function ); - VALUE value = get( key ); - if ( value == null ) - { - value = function.apply( key ); - put( key, value ); - } - return value; - } -} diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntObjectVisitor.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntObjectVisitor.java deleted file mode 100644 index c4a1c4fa7eaae..0000000000000 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntObjectVisitor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2002-2018 "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 . - */ -package org.neo4j.collection.primitive; - -public interface PrimitiveIntObjectVisitor -{ - /** - * Visit the given entry. - * - * @param key The key of the entry. - * @param value The value of the entry. - * @return 'true' to signal that the iteration should be stopped, 'false' to signal that the iteration should - * continue if there are more entries to look at. - * @throws E any thrown exception of type 'E' will bubble up through the 'visit' method. - */ - boolean visited( int key, VALUE value ) throws E; -} diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/PrimitiveIntObjectHashMap.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/PrimitiveIntObjectHashMap.java deleted file mode 100644 index 6718ff013b02a..0000000000000 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/PrimitiveIntObjectHashMap.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2002-2018 "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 . - */ -package org.neo4j.collection.primitive.hopscotch; - -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; -import org.neo4j.collection.primitive.PrimitiveIntObjectVisitor; -import org.neo4j.collection.primitive.hopscotch.HopScotchHashingAlgorithm.Monitor; - -import static org.neo4j.collection.primitive.hopscotch.HopScotchHashingAlgorithm.DEFAULT_HASHING; - -public class PrimitiveIntObjectHashMap extends AbstractIntHopScotchCollection - implements PrimitiveIntObjectMap -{ - private final Monitor monitor; - - public PrimitiveIntObjectHashMap( Table table, Monitor monitor ) - { - super( table ); - this.monitor = monitor; - } - - @Override - public VALUE put( int key, VALUE value ) - { - return HopScotchHashingAlgorithm.put( table, monitor, DEFAULT_HASHING, key, value, this ); - } - - @Override - public boolean containsKey( int key ) - { - return HopScotchHashingAlgorithm.get( table, monitor, DEFAULT_HASHING, key ) != null; - } - - @Override - public VALUE get( int key ) - { - return HopScotchHashingAlgorithm.get( table, monitor, DEFAULT_HASHING, key ); - } - - @Override - public VALUE remove( int key ) - { - return HopScotchHashingAlgorithm.remove( table, monitor, DEFAULT_HASHING, key ); - } - - @Override - public int size() - { - return table.size(); - } - - @Override - public String toString() - { - return table.toString(); - } - - @Override - public void visitEntries( PrimitiveIntObjectVisitor visitor ) throws E - { - long nullKey = table.nullKey(); - int capacity = table.capacity(); - for ( int i = 0; i < capacity; i++ ) - { - int key = (int) table.key( i ); - if ( key != nullKey && visitor.visited( key, table.value( i ) ) ) - { - return; - } - } - } - - @SuppressWarnings( "EqualsWhichDoesntCheckParameterClass" ) // yes it does - @Override - public boolean equals( Object other ) - { - if ( typeAndSizeEqual( other ) ) - { - PrimitiveIntObjectHashMap that = (PrimitiveIntObjectHashMap) other; - IntObjEquality equality = new IntObjEquality<>( that ); - visitEntries( equality ); - return equality.isEqual(); - } - return false; - } - - private static class IntObjEquality implements PrimitiveIntObjectVisitor - { - private PrimitiveIntObjectHashMap other; - private boolean equal = true; - - IntObjEquality( PrimitiveIntObjectHashMap that ) - { - this.other = that; - } - - @Override - public boolean visited( int key, T value ) - { - Object otherValue = other.get( key ); - equal = otherValue == value || (otherValue != null && otherValue.equals( value ) ); - return !equal; - } - - public boolean isEqual() - { - return equal; - } - } - - @Override - public int hashCode() - { - HashCodeComputer hash = new HashCodeComputer<>(); - visitEntries( hash ); - return hash.hashCode(); - } - - private static class HashCodeComputer implements PrimitiveIntObjectVisitor - { - private int hash = 1337; - - @Override - public boolean visited( int key, T value ) throws RuntimeException - { - hash += DEFAULT_HASHING.hashSingleValueToInt( key + value.hashCode() ); - return false; - } - - @Override - public int hashCode() - { - return hash; - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( o == null || getClass() != o.getClass() ) - { - return false; - } - HashCodeComputer that = (HashCodeComputer) o; - return hash == that.hash; - } - } -} diff --git a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveIntCollectionsTest.java b/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveIntCollectionsTest.java deleted file mode 100644 index e723487399ba9..0000000000000 --- a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveIntCollectionsTest.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (c) 2002-2018 "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 . - */ -package org.neo4j.collection.primitive; - -import org.eclipse.collections.api.iterator.IntIterator; -import org.eclipse.collections.api.set.primitive.IntSet; -import org.eclipse.collections.api.set.primitive.MutableIntSet; -import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; -import org.junit.Test; - -import java.util.NoSuchElementException; -import java.util.concurrent.atomic.AtomicInteger; - -import org.neo4j.memory.GlobalMemoryTracker; - -import static java.util.Arrays.asList; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class PrimitiveIntCollectionsTest -{ - @Test - public void arrayOfItemsAsIterator() - { - // GIVEN - int[] items = new int[] { 2, 5, 234 }; - - // WHEN - IntIterator iterator = PrimitiveIntCollections.iterator( items ); - - // THEN - assertItems( iterator, items ); - } - - @Test - public void convertCollectionToLongArray() - { - IntSet heapSet = new IntHashSet( 1, 2, 3 ); - MutableIntSet offHeapIntSet = Primitive.offHeapIntSet( GlobalMemoryTracker.INSTANCE ); - offHeapIntSet.add( 7 ); - offHeapIntSet.add( 8 ); - assertArrayEquals( new long[]{1, 2, 3}, PrimitiveIntCollections.asLongArray( heapSet ) ); - assertArrayEquals( new long[]{7, 8}, PrimitiveIntCollections.asLongArray( offHeapIntSet ) ); - } - - @Test - public void concatenateTwoIterators() - { - // GIVEN - IntIterator firstItems = PrimitiveIntCollections.iterator( 10, 3, 203, 32 ); - IntIterator otherItems = PrimitiveIntCollections.iterator( 1, 2, 5 ); - - // WHEN - IntIterator iterator = PrimitiveIntCollections.concat( asList( firstItems, otherItems ).iterator() ); - - // THEN - assertItems( iterator, 10, 3, 203, 32, 1, 2, 5 ); - } - - @Test - public void deduplicate() - { - // GIVEN - IntIterator items = PrimitiveIntCollections.iterator( 1, 1, 2, 3, 2 ); - - // WHEN - IntIterator deduped = PrimitiveIntCollections.deduplicate( items ); - - // THEN - assertItems( deduped, 1, 2, 3 ); - } - - private static final class CountingPrimitiveIntIteratorResource implements IntIterator, AutoCloseable - { - private final IntIterator delegate; - private final AtomicInteger closeCounter; - - private CountingPrimitiveIntIteratorResource( IntIterator delegate, AtomicInteger closeCounter ) - { - this.delegate = delegate; - this.closeCounter = closeCounter; - } - - @Override - public void close() - { - closeCounter.incrementAndGet(); - } - - @Override - public boolean hasNext() - { - return delegate.hasNext(); - } - - @Override - public int next() - { - return delegate.next(); - } - } - - @Test - public void iteratorAsSet() - { - // GIVEN - IntIterator items = PrimitiveIntCollections.iterator( 1, 2, 3 ); - - // WHEN - IntSet set = PrimitiveIntCollections.asSet( items ); - - // THEN - assertTrue( set.contains( 1 ) ); - assertTrue( set.contains( 2 ) ); - assertTrue( set.contains( 3 ) ); - assertFalse( set.contains( 4 ) ); - try - { - PrimitiveIntCollections.asSet( PrimitiveIntCollections.iterator( 1, 2, 1 ) ); - fail( "Should fail on duplicates" ); - } - catch ( IllegalStateException e ) - { // good - } - } - - @Test - public void shouldNotContinueToCallNextOnHasNextFalse() - { - // GIVEN - AtomicInteger count = new AtomicInteger( 2 ); - IntIterator iterator = new PrimitiveIntCollections.PrimitiveIntBaseIterator() - { - @Override - protected boolean fetchNext() - { - return count.decrementAndGet() >= 0 && next( count.get() ); - } - }; - - // WHEN/THEN - assertTrue( iterator.hasNext() ); - assertTrue( iterator.hasNext() ); - assertEquals( 1L, iterator.next() ); - assertTrue( iterator.hasNext() ); - assertTrue( iterator.hasNext() ); - assertEquals( 0L, iterator.next() ); - assertFalse( iterator.hasNext() ); - assertFalse( iterator.hasNext() ); - assertEquals( -1L, count.get() ); - } - - @Test - public void shouldDeduplicate() - { - // GIVEN - int[] array = new int[] {1, 6, 2, 5, 6, 1, 6}; - - // WHEN - int[] deduped = PrimitiveIntCollections.deduplicate( array ); - - // THEN - assertArrayEquals( new int[] {1, 6, 2, 5}, deduped ); - } - - @Test - public void copyMap() - { - PrimitiveIntObjectMap originalMap = Primitive.intObjectMap(); - originalMap.put( 1, "a" ); - originalMap.put( 2, "b" ); - originalMap.put( 3, "c" ); - PrimitiveIntObjectMap copyMap = PrimitiveIntCollections.copy( originalMap ); - assertNotSame( originalMap, copyMap ); - assertEquals( 3, copyMap.size() ); - assertEquals( "a", copyMap.get( 1 ) ); - assertEquals( "b", copyMap.get( 2 ) ); - assertEquals( "c", copyMap.get( 3 ) ); - } - - private void assertNoMoreItems( IntIterator iterator ) - { - assertFalse( iterator + " should have no more items", iterator.hasNext() ); - try - { - iterator.next(); - fail( "Invoking next() on " + iterator + - " which has no items left should have thrown NoSuchElementException" ); - } - catch ( NoSuchElementException e ) - { // Good - } - } - - private void assertNextEquals( long expected, IntIterator iterator ) - { - assertTrue( iterator + " should have had more items", iterator.hasNext() ); - assertEquals( expected, iterator.next() ); - } - - private void assertItems( IntIterator iterator, int... expectedItems ) - { - for ( long expectedItem : expectedItems ) - { - assertNextEquals( expectedItem, iterator ); - } - assertNoMoreItems( iterator ); - } - - private int[] reverse( int[] items ) - { - int[] result = new int[items.length]; - for ( int i = 0; i < items.length; i++ ) - { - result[i] = items[items.length - i - 1]; - } - return result; - } -} diff --git a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveCollectionEqualityTest.java b/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveCollectionEqualityTest.java index 0fab9298e7df4..5ea5ec728bc1d 100644 --- a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveCollectionEqualityTest.java +++ b/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveCollectionEqualityTest.java @@ -35,7 +35,6 @@ import org.neo4j.collection.primitive.Primitive; import org.neo4j.collection.primitive.PrimitiveCollection; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.collection.primitive.PrimitiveLongObjectMap; import org.neo4j.function.Factory; @@ -83,32 +82,6 @@ public boolean isApplicable( Factory factory ) // ==== Test Value Producers ==== - @DataPoint - public static ValueProducer intObjV = - new ValueProducer( PrimitiveIntObjectMap.class ) - { - @Override - public Value randomValue() - { - final int x = randomInt(); - final Object y = new Object(); - return new Value() - { - @Override - public void add( PrimitiveIntObjectMap coll ) - { - coll.put( x, y ); - } - - @Override - public boolean remove( PrimitiveIntObjectMap coll ) - { - return coll.remove( x ) == y; - } - }; - } - }; - @DataPoint public static ValueProducer longObjV = new ValueProducer( PrimitiveLongObjectMap.class ) @@ -137,13 +110,6 @@ public boolean remove( PrimitiveLongObjectMap coll ) // ==== Primitive Collection Implementations ==== - @DataPoint - public static Factory intObjMap = Primitive::intObjectMap; - - @DataPoint - public static Factory intObjMapWithCapacity = - () -> Primitive.intObjectMap( randomCapacity() ); - @DataPoint public static Factory longObjectMap = Primitive::longObjectMap; diff --git a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveIntObjectHashMapTest.java b/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveIntObjectHashMapTest.java deleted file mode 100644 index 8308e6a2e9821..0000000000000 --- a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveIntObjectHashMapTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2002-2018 "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 . - */ -package org.neo4j.collection.primitive.hopscotch; - -import org.junit.Test; - -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; - -import static org.junit.Assert.assertEquals; - -public class PrimitiveIntObjectHashMapTest -{ - - @Test - public void doNotComputeValueIfPresent() - { - PrimitiveIntObjectMap intObjectMap = Primitive.intObjectMap(); - intObjectMap.put( 1, "a" ); - assertEquals("a", intObjectMap.computeIfAbsent( 1, value -> "b" )); - } - - @Test - public void computeValueIfAbsent() - { - PrimitiveIntObjectMap intObjectMap = Primitive.intObjectMap(); - intObjectMap.put( 1, "a" ); - assertEquals("b", intObjectMap.computeIfAbsent( 2, value -> "b" )); - } - -} diff --git a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveLongMapTest.java b/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveLongMapTest.java deleted file mode 100644 index 606691cb5ea6f..0000000000000 --- a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/PrimitiveLongMapTest.java +++ /dev/null @@ -1,879 +0,0 @@ -/* - * Copyright (c) 2002-2018 "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 . - */ -package org.neo4j.collection.primitive.hopscotch; - -import org.eclipse.collections.api.map.primitive.MutableLongIntMap; -import org.eclipse.collections.impl.map.mutable.primitive.LongIntHashMap; -import org.junit.Test; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; - -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; -import org.neo4j.collection.primitive.PrimitiveIntObjectVisitor; -import org.neo4j.collection.primitive.PrimitiveIntVisitor; -import org.neo4j.collection.primitive.PrimitiveLongObjectMap; -import org.neo4j.collection.primitive.PrimitiveLongObjectVisitor; - -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; - -public class PrimitiveLongMapTest -{ - @Test - public void shouldContainAddedValues() - { - // GIVEN - Map expectedEntries = new HashMap<>(); - expectedEntries.put( 1994703545L, 59 ); - expectedEntries.put( 1583732120L, 98 ); - expectedEntries.put( 756530774L, 56 ); - expectedEntries.put( 1433091763L, 22 ); - - PrimitiveLongObjectMap map = Primitive.longObjectMap(); - for ( Map.Entry entry : expectedEntries.entrySet() ) - { - map.put( entry.getKey(), entry.getValue() ); - } - - // WHEN/THEN - boolean existedBefore = map.containsKey( 1433091763 ); - Integer valueBefore = map.get( 1433091763 ); - Integer previous = map.put( 1433091763, 35 ); - boolean existsAfter = map.containsKey( 1433091763 ); - Integer valueAfter = map.get( 1433091763 ); - assertTrue( "1433091763 should exist before putting here", existedBefore ); - assertEquals( (Integer) 22, valueBefore ); - assertEquals( (Integer) 22, previous ); - assertTrue( "(1433091763, 35) should exist", existsAfter ); - assertEquals( (Integer) 35, valueAfter ); - expectedEntries.put( 1433091763L, 35 ); - - final Map visitedEntries = new HashMap<>(); - map.visitEntries( ( key, value ) -> - { - visitedEntries.put( key, value ); - return false; - } ); - assertEquals( expectedEntries, visitedEntries ); - } - - @Test - public void shouldContainAddedValues_2() - { - // GIVEN - PrimitiveLongObjectMap map = Primitive.longObjectMap(); - map.put( 1950736976, 4 ); - map.put( 1054824202, 58 ); - map.put( 348690619, 54 ); - map.put( 1224909480, 79 ); - map.put( 1508493474, 82 ); - // WHEN/THEN - boolean existedBefore = map.containsKey( 1508493474 ); - Integer valueBefore = map.get( 1508493474 ); - Integer previous = map.put( 1508493474, 62 ); - boolean existsAfter = map.containsKey( 1508493474 ); - Integer valueAfter = map.get( 1508493474 ); - assertTrue( "1508493474 should exist before putting here", existedBefore ); - assertEquals( "value before should be 82", (Integer) 82, valueBefore ); - assertEquals( "value returned from put should be 82", (Integer) 82, previous ); - assertTrue( "1508493474 should exist", existsAfter ); - assertEquals( "value after putting should be 62", (Integer) 62, valueAfter ); - } - - @Test - public void shouldContainAddedValues_3() - { - // GIVEN - PrimitiveLongObjectMap map = Primitive.longObjectMap(); - map.remove( 1338037218 ); - map.put( 680125236, 83 ); - map.put( 680125236, 76 ); - map.put( 680125236, 47 ); - map.put( 680125236, 30 ); - map.put( 2080483597, 52 ); - map.put( 867107519, 80 ); - map.remove( 710100384 ); - map.put( 671477921, 88 ); - map.put( 1163609643, 17 ); - map.put( 680125236, 57 ); - map.put( 1163609643, 70 ); - map.put( 2080483597, 89 ); - map.put( 1472451898, 62 ); - map.put( 1379499183, 93 ); - map.put( 680125236, 17 ); - map.put( 567842571, 43 ); - map.put( 2045599221, 60 ); - map.remove( 641295711 ); - map.remove( 867107519 ); - map.put( 2045599221, 30 ); - map.remove( 2094689486 ); - map.put( 1572965945, 79 ); - map.remove( 1329473388 ); - map.put( 1572965945, 39 ); - map.put( 264067586, 60 ); - map.put( 1751846500, 5 ); - map.put( 1163609643, 25 ); - map.put( 1379499183, 54 ); - map.remove( 671477921 ); - map.put( 1572965945, 59 ); - map.put( 880140639, 87 ); - // WHEN/THEN - boolean existedBefore = map.containsKey( 468007595 ); - Integer valueBefore = map.get( 468007595 ); - Integer previous = map.put( 468007595, 67 ); - boolean existsAfter = map.containsKey( 468007595 ); - Integer valueAfter = map.get( 468007595 ); - assertFalse( "468007595 should not exist before putting here", existedBefore ); - assertNull( "value before putting should be null", valueBefore ); - assertNull( "value returned from putting should be null", previous ); - assertTrue( "468007595 should exist", existsAfter ); - assertEquals( "value after putting should be 67", (Integer) 67, valueAfter ); - } - - @Test - public void shouldHaveCorrectSize() - { - // GIVEN - PrimitiveLongObjectMap map = Primitive.longObjectMap(); - map.put( 152407843, 17 ); - map.put( 435803197, 29 ); - map.put( 2063473573, 75 ); - map.put( 162922679, 36 ); - map.put( 923042422, 47 ); - map.put( 204556993, 28 ); - map.put( 109670524, 80 ); - map.put( 214127443, 88 ); - map.put( 297958695, 97 ); - map.put( 873122371, 73 ); - map.put( 398704786, 25 ); - map.put( 376378917, 62 ); - map.put( 1948985185, 3 ); - map.put( 918339266, 4 ); - map.put( 1126937431, 48 ); - map.put( 568627750, 6 ); - map.put( 887668742, 1 ); - map.put( 888089153, 88 ); - map.put( 1671871078, 26 ); - map.put( 479217936, 11 ); - map.put( 1874408328, 56 ); - map.put( 1517450283, 83 ); - map.put( 1352952211, 57 ); - map.put( 686066722, 92 ); - map.put( 1593196310, 71 ); - map.put( 1535351391, 62 ); - map.put( 296560052, 59 ); - map.put( 1513542622, 49 ); - map.put( 1899330306, 57 ); - map.put( 746190595, 31 ); - map.put( 1216091366, 90 ); - map.put( 353922939, 16 ); - map.put( 680935464, 16 ); - map.put( 235368309, 8 ); - map.put( 1988133681, 32 ); - map.put( 330747855, 81 ); - map.put( 492627887, 74 ); - map.put( 1005495348, 8 ); - map.put( 2107419277, 82 ); - map.put( 1421265494, 15 ); - map.put( 1669915469, 92 ); - map.put( 2008247215, 9 ); - map.put( 2010142383, 77 ); - map.put( 829081830, 25 ); - map.put( 1349259272, 38 ); - map.put( 1987482877, 8 ); - map.put( 974334859, 83 ); - map.put( 1376908873, 10 ); - map.put( 2120105656, 22 ); - map.put( 1634193445, 8 ); - map.put( 1160987255, 34 ); - map.put( 2030156381, 16 ); - map.put( 2012943328, 22 ); - map.put( 75749275, 54 ); - map.put( 1415817090, 35 ); - map.put( 562352348, 43 ); - map.put( 658501173, 96 ); - map.put( 441278652, 24 ); - map.put( 633855945, 82 ); - map.put( 579807215, 31 ); - map.put( 1125922962, 33 ); - map.put( 1995076951, 91 ); - map.put( 322776761, 4 ); - map.put( 1011369342, 36 ); - // WHEN/THEN - int sizeBefore = map.size(); - boolean existedBefore = map.containsKey( 679686325 ); - Integer valueBefore = map.get( 679686325 ); - Integer previous = map.put( 679686325, 63 ); - boolean existsAfter = map.containsKey( 679686325 ); - Integer valueAfter = map.get( 679686325 ); - int sizeAfter = map.size(); - assertEquals( "Size before put should have been 64", 64, sizeBefore ); - assertFalse( "679686325 should not exist before putting here", existedBefore ); - assertNull( "value before putting should be null", valueBefore ); - assertNull( "value returned from putting should be null", previous ); - assertTrue( "679686325 should exist", existsAfter ); - assertEquals( "value after putting should be 63", (Integer) 63, valueAfter ); - assertEquals( "Size after put should have been 65", 65, sizeAfter ); - } - - @Test - public void shouldMoveValuesWhenMovingEntriesAround() - { - // GIVEN - PrimitiveLongObjectMap map = Primitive.longObjectMap(); - map.put( 206243105, 47 ); - map.put( 2083304695, 63 ); - map.put( 689837337, 7 ); - map.remove( 206243105 ); - // WHEN/THEN - int sizeBefore = map.size(); - boolean existedBefore = map.containsKey( 689837337 ); - Integer valueBefore = map.get( 689837337 ); - Integer previous = map.put( 689837337, 20 ); - boolean existsAfter = map.containsKey( 689837337 ); - Integer valueAfter = map.get( 689837337 ); - int sizeAfter = map.size(); - assertEquals( "Size before put should have been 2", 2, sizeBefore ); - assertTrue( "689837337 should exist before putting here", existedBefore ); - assertEquals( "value before should be 7", (Integer) 7, valueBefore ); - assertEquals( "value returned from put should be 7", (Integer) 7, previous ); - assertTrue( "689837337 should exist", existsAfter ); - assertEquals( "value after putting should be 20", (Integer) 20, valueAfter ); - assertEquals( "Size after put should have been 2", 2, sizeAfter ); - } - - @Test - public void shouldOnlyContainAddedValues_3() - { - // GIVEN - PrimitiveLongObjectMap map = Primitive.longObjectMap(); - map.put( 2083704227957337692L, 50 ); - map.put( 1039748383662879297L, 12 ); - map.put( 6296247210943123044L, 45 ); - map.put( 8004677065031068097L, 5 ); - map.put( 1039748383662879297L, 70 ); - map.put( 5386804704064477958L, 97 ); - map.remove( 1506507783133586973L ); - map.put( 4287434858289406631L, 29 ); - map.put( 8004677065031068097L, 17 ); - map.put( 986286772325632801L, 14 ); - map.put( 7880139640446289959L, 68 ); - map.put( 8004677065031068097L, 23 ); - map.put( 5386804704064477958L, 72 ); - map.put( 5386804704064477958L, 71 ); - map.put( 2300381985575721987L, 0 ); - map.put( 6144230340727188436L, 31 ); - map.put( 425423457410117293L, 88 ); - map.put( 2083704227957337692L, 65 ); - map.put( 7805027477403310582L, 72 ); - map.put( 2254081933055750443L, 66 ); - map.put( 5386804704064477958L, 46 ); - map.put( 5787098127909281443L, 45 ); - map.put( 5508645210651400664L, 45 ); - map.put( 6092264867460428040L, 65 ); - map.put( 4551026293109220157L, 52 ); - map.put( 4669163071261559807L, 33 ); - map.put( 5790325306669462860L, 96 ); - map.put( 4337317298737908324L, 78 ); - map.put( 986286772325632801L, 71 ); - map.put( 4287434858289406631L, 47 ); - map.put( 1827085004206892313L, 30 ); - map.put( 6070945099342863711L, 88 ); - map.remove( 6300957726732252611L ); - map.put( 2300381985575721987L, 22 ); - map.put( 2083704227957337692L, 2 ); - map.put( 2885272279767063039L, 71 ); - map.put( 3627867780921264529L, 5 ); - map.remove( 5330274310754559602L ); - map.put( 8902857048431919030L, 23 ); - map.remove( 4287434858289406631L ); - map.put( 5459968256561120197L, 8 ); - map.put( 5790325306669462860L, 17 ); - map.put( 9003964541346458616L, 45 ); - map.put( 3832091967762842783L, 79 ); - map.put( 1332274446340546922L, 62 ); - map.put( 6610784890222945257L, 20 ); - map.put( 3627867780921264529L, 65 ); - map.put( 7988336790991560848L, 89 ); - map.put( 5386804704064477958L, 15 ); - map.put( 6296247210943123044L, 19 ); - map.put( 7776019112299874624L, 67 ); - map.put( 5827611175622537127L, 18 ); - map.remove( 8004677065031068097L ); - map.put( 2451971987846333787L, 48 ); - map.put( 3627867780921264529L, 16 ); - map.put( 2506727685914893570L, 61 ); - map.put( 6629089416451699826L, 89 ); - map.put( 875078333857781813L, 38 ); - map.put( 439984342972777679L, 51 ); - map.put( 9077428346047966819L, 19 ); - map.put( 7045299269724516542L, 73 ); - map.put( 8055487013098459354L, 24 ); - map.put( 6610784890222945257L, 65 ); - map.put( 986286772325632801L, 29 ); - map.put( 133928815519522465L, 81 ); - map.put( 5780114596098993316L, 15 ); - map.put( 3790785290324207363L, 91 ); - map.put( 2795040354588080479L, 48 ); - map.put( 4218658174275197144L, 59 ); - map.put( 6610784890222945257L, 70 ); - map.remove( 3722940212039795685L ); - map.put( 1817899559164238906L, 30 ); - map.put( 4551026293109220157L, 35 ); - map.put( 986286772325632801L, 57 ); - map.put( 3811462607668925015L, 57 ); - map.put( 2795040354588080479L, 85 ); - map.put( 8460476221939231932L, 86 ); - map.remove( 8957537157979159052L ); - map.put( 2032224502814063026L, 57 ); - map.remove( 8924941903092284834L ); - map.put( 5386804704064477958L, 2 ); - map.put( 6629089416451699826L, 18 ); - map.put( 425423457410117293L, 31 ); - map.put( 4337317298737908324L, 35 ); - map.remove( 5337770067730257989L ); - map.put( 6150561851033498431L, 49 ); - map.put( 5067121328094576685L, 46 ); - map.remove( 3742103310924563011L ); - map.put( 1327614778938791146L, 49 ); - map.put( 255729841510922319L, 16 ); - map.put( 8785988080128503533L, 69 ); - map.put( 4218658174275197144L, 20 ); - map.put( 1265271287408386915L, 43 ); - map.put( 255729841510922319L, 5 ); - map.put( 8651736753344997668L, 41 ); - map.put( 4363375305508283265L, 4 ); - map.put( 4185381066643227500L, 29 ); - map.put( 3790785290324207363L, 58 ); - map.put( 3058911485922749695L, 1 ); - map.put( 8629268898854377850L, 66 ); - map.put( 1762013345156514959L, 5 ); - map.remove( 4354754593499656793L ); - map.put( 1332274446340546922L, 16 ); - map.put( 4953501292937412915L, 87 ); - map.put( 2330841365833073849L, 83 ); - map.put( 8096564328797694553L, 44 ); - map.put( 8935185623148330821L, 7 ); - map.put( 6150561851033498431L, 48 ); - map.remove( 5827611175622537127L ); - map.put( 8048363335369773749L, 25 ); - map.put( 3627867780921264529L, 48 ); - map.put( 4806848030248674690L, 14 ); - map.put( 5430628648110105698L, 30 ); - map.remove( 7261476188677343032L ); - map.put( 1265271287408386915L, 61 ); - map.put( 9077428346047966819L, 32 ); - map.put( 1827085004206892313L, 95 ); - map.put( 6377023652046870199L, 8 ); - map.remove( 8096564328797694553L ); - map.put( 458594253548258561L, 37 ); - map.put( 4418108647578170347L, 60 ); - map.put( 4363375305508283265L, 50 ); - map.remove( 3220719966247388754L ); - map.put( 5067121328094576685L, 86 ); - map.put( 8030171618634928529L, 9 ); - map.remove( 5790325306669462860L ); - map.remove( 1693435088303118108L ); - map.put( 1817899559164238906L, 48 ); - map.put( 2823063986711596775L, 58 ); - map.put( 5065867711051034527L, 1 ); - map.put( 6144553725832876585L, 16 ); - map.put( 6066303112518690730L, 96 ); - map.put( 1627429134135319103L, 64 ); - map.put( 2083704227957337692L, 48 ); - map.put( 5074984076240598083L, 46 ); - map.put( 273737562207470342L, 60 ); - map.put( 5065867711051034527L, 7 ); - map.put( 1425720210238734727L, 23 ); - map.put( 8840483239403421070L, 42 ); - map.put( 622393419539870960L, 66 ); - map.put( 4649317581471627693L, 84 ); - map.put( 6344284253098418581L, 10 ); - map.put( 6066303112518690730L, 14 ); - map.put( 2032224502814063026L, 72 ); - map.put( 3860451022347437817L, 26 ); - map.put( 1931469116507191845L, 30 ); - map.put( 7264376865632246862L, 81 ); - map.put( 875078333857781813L, 41 ); - map.put( 6066303112518690730L, 65 ); - map.put( 357446231240164192L, 80 ); - map.put( 90138258774469874L, 73 ); - map.put( 2550828149718879762L, 72 ); - map.put( 357446231240164192L, 17 ); - map.put( 4233359298058523722L, 83 ); - map.put( 7879882017779927485L, 33 ); - map.put( 4554977248866184403L, 64 ); - map.put( 2032224502814063026L, 11 ); - map.put( 8460476221939231932L, 65 ); - map.put( 4404294840535520232L, 58 ); - map.put( 439984342972777679L, 83 ); - map.put( 143440583901416159L, 59 ); - map.put( 6980461179076170770L, 9 ); - map.put( 4253079906814783119L, 93 ); - map.put( 6377023652046870199L, 20 ); - map.put( 2885272279767063039L, 5 ); - map.put( 1115850061381524772L, 37 ); - map.put( 4288489609244987651L, 22 ); - map.put( 1869499448099043543L, 73 ); - map.put( 2233583342469238733L, 84 ); - map.put( 8785988080128503533L, 61 ); - map.put( 7396264003126204068L, 81 ); - map.put( 6553509363155186775L, 96 ); - map.put( 1265663249510580286L, 89 ); - map.put( 8824139147632000339L, 49 ); - map.put( 8629268898854377850L, 10 ); - map.put( 6463027127151126151L, 57 ); - map.put( 2577561266405706623L, 46 ); - map.put( 2942302849662258387L, 40 ); - map.put( 2233583342469238733L, 56 ); - map.put( 7971826071187872579L, 53 ); - map.put( 1425720210238734727L, 27 ); - map.remove( 7194434791627009043L ); - map.put( 1429250394105883546L, 82 ); - map.put( 8048363335369773749L, 19 ); - map.put( 425423457410117293L, 51 ); - map.remove( 3570674569632664356L ); - map.remove( 5925614419318569326L ); - map.put( 245367449754197583L, 27 ); - map.put( 8724491045048677021L, 55 ); - map.put( 1037934857236019066L, 66 ); - map.put( 8902857048431919030L, 61 ); - map.put( 4806848030248674690L, 17 ); - map.put( 8840483239403421070L, 95 ); - map.put( 2931578375554111170L, 54 ); - map.put( 5352224688502007093L, 36 ); - map.put( 6675404627060358866L, 64 ); - map.put( 5011448804620449550L, 48 ); - map.put( 9003964541346458616L, 44 ); - map.put( 8614830761978541860L, 70 ); - map.put( 3790785290324207363L, 95 ); - map.put( 3524676886726253569L, 54 ); - map.put( 6858076293577130289L, 60 ); - map.put( 6721253107702965701L, 41 ); - map.put( 655525227420977141L, 94 ); - map.put( 2344362186561469072L, 29 ); - map.put( 6144230340727188436L, 76 ); - map.put( 6751209943070153529L, 22 ); - map.put( 5528119873376392874L, 44 ); - map.put( 6675404627060358866L, 20 ); - map.put( 6167523814676644161L, 50 ); - map.put( 4288489609244987651L, 82 ); - map.remove( 3362704467864439992L ); - map.put( 8629268898854377850L, 50 ); - map.remove( 8824139147632000339L ); - map.remove( 8563575034946766108L ); - map.put( 4391871381220263726L, 20 ); - map.remove( 6143313773038364355L ); - map.remove( 3225044803974988142L ); - map.remove( 8048363335369773749L ); - map.remove( 439984342972777679L ); - map.put( 7776019112299874624L, 8 ); - map.put( 5414055783993307402L, 13 ); - map.put( 425423457410117293L, 91 ); - map.put( 8407567928758710341L, 30 ); - map.put( 6070945099342863711L, 14 ); - map.put( 5644323748441073606L, 91 ); - map.put( 5297141920581728538L, 61 ); - map.put( 7880139640446289959L, 1 ); - map.put( 2300381985575721987L, 92 ); - map.put( 8253246663621301435L, 26 ); - map.remove( 2074764355175726009L ); - map.remove( 3823843425563676964L ); - map.put( 8314906688468605292L, 91 ); - map.put( 6864119235983684905L, 56 ); - map.put( 6610784890222945257L, 85 ); - map.put( 3790785290324207363L, 7 ); - map.put( 9077428346047966819L, 20 ); - map.put( 5594781060356781714L, 76 ); - map.put( 4288489609244987651L, 24 ); - map.put( 5427718399315377322L, 93 ); - map.put( 6858076293577130289L, 41 ); - map.put( 4233359298058523722L, 43 ); - map.put( 3058911485922749695L, 88 ); - map.remove( 1327614778938791146L ); - map.put( 4665341449948530032L, 26 ); - map.remove( 2860868006143077426L ); - map.put( 6167523814676644161L, 70 ); - map.remove( 8314906688468605292L ); - map.put( 6396314739926743170L, 25 ); - map.put( 8924527320597926970L, 40 ); - map.put( 1817899559164238906L, 84 ); - map.remove( 4391871381220263726L ); - map.put( 8850817829384121639L, 50 ); - map.put( 6513548978704592547L, 52 ); - map.remove( 6066303112518690730L ); - map.remove( 3946964103425920940L ); - map.put( 7971826071187872579L, 71 ); - map.put( 90138258774469874L, 78 ); - map.put( 8309039683334256753L, 44 ); - map.put( 327300646665050265L, 52 ); - map.put( 4239841777571533415L, 22 ); - map.put( 7391753878925882699L, 46 ); - map.put( 5987501380005333533L, 31 ); - map.put( 6734545541042861356L, 45 ); - map.remove( 6566682167801344029L ); - map.put( 4218658174275197144L, 16 ); - map.put( 4363586488886891680L, 88 ); - map.put( 8030171618634928529L, 19 ); - map.put( 6513548978704592547L, 95 ); - map.put( 6721253107702965701L, 55 ); - map.put( 2153470608693815785L, 9 ); - map.put( 5807454155419905847L, 7 ); - map.remove( 4528425347504500078L ); - map.put( 339083533777732657L, 72 ); - map.put( 5162811261582626928L, 68 ); - map.put( 5459968256561120197L, 89 ); - map.put( 946125626260258615L, 97 ); - map.put( 986286772325632801L, 26 ); - map.put( 8309039683334256753L, 74 ); - map.put( 1609193622622537433L, 84 ); - map.put( 2506727685914893570L, 9 ); - map.put( 143440583901416159L, 33 ); - map.put( 7716482408003289208L, 30 ); - map.put( 7880139640446289959L, 74 ); - map.put( 5472992709007694577L, 27 ); - map.put( 3367972495572249232L, 8 ); - map.put( 6002824320296423294L, 71 ); - map.put( 5162811261582626928L, 10 ); - map.remove( 8309039683334256753L ); - map.put( 3103455156394998975L, 1 ); - map.put( 4943074037151902792L, 38 ); - map.put( 1455801901314190156L, 98 ); - map.put( 3502583509759951230L, 22 ); - map.remove( 8464127935014315372L ); - map.put( 6858076293577130289L, 35 ); - map.put( 8487179770790306175L, 5 ); - map.put( 946125626260258615L, 85 ); - map.put( 722144778357869055L, 1 ); - map.remove( 6832604792388788147L ); - map.remove( 7879882017779927485L ); - map.put( 4636443662717865247L, 98 ); - map.put( 6950926592851406543L, 12 ); - map.put( 8536120340569832116L, 73 ); - map.put( 86730768989854734L, 66 ); - map.put( 4558683789229895837L, 26 ); - map.put( 4806848030248674690L, 11 ); - map.put( 425423457410117293L, 38 ); - map.put( 8713875164075871710L, 97 ); - map.put( 3790785290324207363L, 77 ); - map.put( 4632006356221328093L, 21 ); - map.put( 7628512490650429100L, 28 ); - map.remove( 4651124484202085669L ); - map.put( 4320012891688937760L, 22 ); - map.put( 6092264867460428040L, 86 ); - map.put( 6610784890222945257L, 71 ); - map.remove( 3515175120945606156L ); - map.put( 5787098127909281443L, 10 ); - map.put( 5057609667342409825L, 50 ); - map.put( 5903362554916539560L, 75 ); - map.remove( 5339209082212961633L ); - map.put( 3502583509759951230L, 36 ); - map.put( 4198420341072443663L, 75 ); - map.put( 5037754181090593008L, 34 ); - map.put( 39606137866137388L, 19 ); - map.remove( 622393419539870960L ); - map.put( 2783004740411041924L, 79 ); - map.put( 6232331175163415825L, 72 ); - map.put( 4367206208262757151L, 33 ); - map.remove( 5879159150292946046L ); - map.put( 722144778357869055L, 80 ); - map.put( 9006426844471489361L, 92 ); - map.put( 550025535839604778L, 32 ); - map.remove( 5855895659233120621L ); - map.put( 1455801901314190156L, 24 ); - map.put( 3860451022347437817L, 81 ); - map.put( 2672104991948169160L, 57 ); - map.remove( 3860451022347437817L ); - map.remove( 655525227420977141L ); - map.put( 2413633498546493443L, 68 ); - map.put( 4185381066643227500L, 54 ); - map.put( 1280345971255663584L, 39 ); - map.put( 5796123963544961504L, 76 ); - map.put( 1892786158672061630L, 55 ); - map.remove( 5352224688502007093L ); - map.put( 3711105805930144213L, 47 ); - map.put( 4608237982157900285L, 41 ); - map.put( 4175794211341763944L, 31 ); - map.put( 2315250912582233395L, 81 ); - map.put( 357446231240164192L, 87 ); - map.put( 4110861648946406824L, 75 ); - map.put( 6912381889380280106L, 22 ); - map.put( 6721253107702965701L, 43 ); - map.put( 8536120340569832116L, 87 ); - map.put( 9134483648483594929L, 77 ); - map.put( 9132976039160654816L, 69 ); - map.remove( 7698175804504341415L ); - map.remove( 9134483648483594929L ); - map.put( 215721718639621876L, 11 ); - map.put( 8367455298026304238L, 78 ); - map.put( 215721718639621876L, 13 ); - map.put( 1398628381776162625L, 12 ); - map.put( 3818698536247649025L, 91 ); - map.put( 146020861698406718L, 41 ); - map.put( 39606137866137388L, 93 ); - map.put( 2032224502814063026L, 29 ); - map.remove( 6363504799104250810L ); - map.put( 7198198302699040275L, 75 ); - map.put( 1659665859871881503L, 35 ); - map.put( 2032224502814063026L, 25 ); - map.put( 7006780191094382053L, 2 ); - map.put( 2626850727701928459L, 97 ); - map.put( 5371963064889126677L, 49 ); - map.put( 2777831232791546183L, 35 ); - map.remove( 1265271287408386915L ); - map.remove( 1078791602714388223L ); - map.put( 7355915493826998767L, 39 ); - map.remove( 1557741259882614531L ); - map.put( 318456745029053198L, 18 ); - map.put( 5731549637584761783L, 77 ); - map.put( 875078333857781813L, 80 ); - map.remove( 4288489609244987651L ); - map.put( 6296247210943123044L, 67 ); - map.put( 6513548978704592547L, 60 ); - map.put( 7484688824700837146L, 79 ); - map.put( 4551026293109220157L, 77 ); - map.put( 2961669147182343860L, 80 ); - map.put( 4481942776688563562L, 28 ); - map.put( 5879809531485088687L, 63 ); - map.put( 5799223884087101214L, 94 ); - map.put( 8394473765965282856L, 59 ); - map.remove( 7273585073251585620L ); - map.remove( 5518575735665118270L ); - map.put( 1946691597339845823L, 64 ); - map.put( 1191724556568067952L, 33 ); - map.remove( 1803989601564179749L ); - map.put( 7909563548070411816L, 98 ); - // WHEN/THEN - int sizeBefore = map.size(); - boolean existedBefore = map.containsKey( 5826258075197365143L ); - Integer valueBefore = map.get( 5826258075197365143L ); - Integer previous = map.put( 5826258075197365143L, 6 ); - boolean existsAfter = map.containsKey( 5826258075197365143L ); - Integer valueAfter = map.get( 5826258075197365143L ); - int sizeAfter = map.size(); - assertEquals( "Size before put should have been 199", 199, sizeBefore ); - assertFalse( "5826258075197365143 should not exist before putting here", existedBefore ); - assertNull( "value before putting should be null", valueBefore ); - assertNull( "value returned from putting should be null", previous ); - assertTrue( "5826258075197365143 should exist", existsAfter ); - assertEquals( "value after putting should be 6", (Integer) 6, valueAfter ); - assertEquals( "Size after put should have been 200", 200, sizeAfter ); - } - - @SuppressWarnings( "unchecked" ) - @Test - public void longObjectEntryVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() - { - // GIVEN - PrimitiveLongObjectMap map = Primitive.longObjectMap(); - map.put( 1, 100 ); - map.put( 2, 200 ); - map.put( 3, 300 ); - PrimitiveLongObjectVisitor visitor = mock( PrimitiveLongObjectVisitor.class ); - - // WHEN - map.visitEntries( visitor ); - - // THEN - verify( visitor ).visited( 1, 100 ); - verify( visitor ).visited( 2, 200 ); - verify( visitor ).visited( 3, 300 ); - verifyNoMoreInteractions( visitor ); - } - - @Test - public void longObjectEntryVisitorShouldNotSeeEntriesAfterRequestingBreakOut() - { - // GIVEN - PrimitiveLongObjectMap map = Primitive.longObjectMap(); - map.put( 1, 100 ); - map.put( 2, 200 ); - map.put( 3, 300 ); - map.put( 4, 400 ); - final AtomicInteger counter = new AtomicInteger(); - - // WHEN - map.visitEntries( ( key, value ) -> counter.incrementAndGet() > 2 ); - - // THEN - assertThat( counter.get(), is( 3 ) ); - } - - @SuppressWarnings( "unchecked" ) - @Test - public void intObjectEntryVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() - { - // GIVEN - PrimitiveIntObjectMap map = Primitive.intObjectMap(); - map.put( 1, 100 ); - map.put( 2, 200 ); - map.put( 3, 300 ); - PrimitiveIntObjectVisitor visitor = mock( PrimitiveIntObjectVisitor.class ); - - // WHEN - map.visitEntries( visitor ); - - // THEN - verify( visitor ).visited( 1, 100 ); - verify( visitor ).visited( 2, 200 ); - verify( visitor ).visited( 3, 300 ); - verifyNoMoreInteractions( visitor ); - } - - @Test - public void intObjectEntryVisitorShouldNotSeeEntriesAfterRequestingBreakOut() - { - // GIVEN - PrimitiveIntObjectMap map = Primitive.intObjectMap(); - map.put( 1, 100 ); - map.put( 2, 200 ); - map.put( 3, 300 ); - map.put( 4, 400 ); - final AtomicInteger counter = new AtomicInteger(); - - // WHEN - map.visitEntries( ( key, value ) -> counter.incrementAndGet() > 2 ); - - // THEN - assertThat( counter.get(), is( 3 ) ); - } - - @SuppressWarnings( "unchecked" ) - @Test - public void intObjectKeyVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() - { - // GIVEN - PrimitiveIntObjectMap map = Primitive.intObjectMap(); - map.put( 1, 100 ); - map.put( 2, 200 ); - map.put( 3, 300 ); - PrimitiveIntVisitor visitor = mock( PrimitiveIntVisitor.class ); - - // WHEN - map.visitKeys( visitor ); - - // THEN - verify( visitor ).visited( 1 ); - verify( visitor ).visited( 2 ); - verify( visitor ).visited( 3 ); - verifyNoMoreInteractions( visitor ); - } - - @Test - public void intObjectKeyVisitorShouldNotSeeEntriesAfterRequestingBreakOut() - { - // GIVEN - PrimitiveIntObjectMap map = Primitive.intObjectMap(); - map.put( 1, 100 ); - map.put( 2, 200 ); - map.put( 3, 300 ); - map.put( 4, 400 ); - final AtomicInteger counter = new AtomicInteger(); - - // WHEN - map.visitKeys( value -> counter.incrementAndGet() > 2 ); - - // THEN - assertThat( counter.get(), is( 3 ) ); - } - - @Test - public void longObjectMapValuesContainsAllValues() - { - PrimitiveLongObjectMap map = Primitive.longObjectMap(); - map.put( 1, "a" ); - map.put( 2, "b" ); - map.put( 3, "c" ); - - assertThat( map.values(), containsInAnyOrder( "a", "b", "c" ) ); - } - - @Test - public void recursivePutGrowInterleavingShouldNotDropOriginalValues() - { - // List of values which causes calls to put() call grow(), which will call put() which calls grow() again - List lst = Arrays.asList( - 44988L, 44868L, 44271L, 44399L, 44502L, 44655L, 44348L, 44843L, - 44254L, 44774L, 44476L, 44664L, 44485L, 44237L, 44953L, 44468L, - 44970L, 44808L, 44527L, 44987L, 44672L, 44647L, 44467L, 44825L, - 44740L, 44220L, 44851L, 44902L, 44791L, 44416L, 44365L, 44382L, - 44885L, 44510L, 44553L, 44894L, 44288L, 44306L, 44450L, 44689L, - 44305L, 44374L, 44323L, 44493L, 44706L, 44681L, 44578L, 44723L, - 44331L, 44936L, 44289L, 44919L, 44433L, 44826L, 44757L, 44561L, - 44595L, 44612L, 44996L, 44646L, 44834L, 44314L, 44544L, 44629L, - 44357L // <-- this value will cause a grow, which during new table population will cause another grow. - ); - - verifyMapRetainsAllEntries( lst ); - } - - @Test - public void recursivePutGrowInterleavingShouldNotDropOriginalValuesEvenWhenFirstGrowAddsMoreValuesAfterSecondGrow() - { - // List of values that cause recursive growth like above, but this time the first grow wants to add more values - // to the table *after* the second grow has occurred. - List lst = Arrays.asList( - 85380L, 85124L, 85252L, 85259L, 85005L, 85260L, 85132L, 85141L, - 85397L, 85013L, 85269L, 85277L, 85149L, 85404L, 85022L, 85150L, - 85029L, 85414L, 85158L, 85286L, 85421L, 85039L, 85167L, 85294L, - 85166L, 85431L, 85303L, 85046L, 85311L, 85439L, 85438L, 85184L, - 85056L, 85063L, 85320L, 85448L, 85201L, 85073L, 85329L, 85456L, - 85328L, 85337L, 85081L, 85465L, 85080L, 85208L, 85473L, 85218L, - 85346L, 85090L, 85097L, 85225L, 85354L, 85098L, 85482L, 85235L, - 85363L, 85107L, 85490L, 85115L, 85499L, 85242L, 85175L, 85371L, - 85192L // <-- this value will cause a grow, which during new table population will cause another grow. - ); - - verifyMapRetainsAllEntries( lst ); - } - - private void verifyMapRetainsAllEntries( List lst ) - { - MutableLongIntMap map = new LongIntHashMap(); - Set set = new HashSet<>(); - for ( Long value : lst ) - { - assertFalse( map.containsKey( value ) ); - map.put( value, 1 ); - assertTrue( set.add( value ) ); - } - - assertThat( map.size(), is( set.size() ) ); - for ( Long aLong : set ) - { - assertThat( map.get( aLong ), is( 1 ) ); - } - } -} diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/token/ReplicatedTokenHolderTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/token/ReplicatedTokenHolderTest.java index d8ccb7ccb044c..6a815ae47337a 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/token/ReplicatedTokenHolderTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/token/ReplicatedTokenHolderTest.java @@ -127,7 +127,7 @@ private StorageEngine mockedStorageEngine() throws Exception txState.accept( new TxStateVisitor.Adapter() { @Override - public void visitCreatedLabelToken( String name, int id ) + public void visitCreatedLabelToken( int id, String name ) { LabelTokenRecord before = new LabelTokenRecord( id ); LabelTokenRecord after = before.clone(); diff --git a/enterprise/kernel/src/main/java/org/neo4j/kernel/impl/enterprise/PropertyExistenceEnforcer.java b/enterprise/kernel/src/main/java/org/neo4j/kernel/impl/enterprise/PropertyExistenceEnforcer.java index e3d5dfa5f1233..801ab0778d5e8 100644 --- a/enterprise/kernel/src/main/java/org/neo4j/kernel/impl/enterprise/PropertyExistenceEnforcer.java +++ b/enterprise/kernel/src/main/java/org/neo4j/kernel/impl/enterprise/PropertyExistenceEnforcer.java @@ -20,8 +20,10 @@ package org.neo4j.kernel.impl.enterprise; import org.eclipse.collections.api.iterator.IntIterator; +import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.set.primitive.MutableIntSet; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; import java.util.ArrayList; @@ -31,8 +33,6 @@ import java.util.Set; import java.util.function.Function; -import org.neo4j.collection.primitive.Primitive; -import org.neo4j.collection.primitive.PrimitiveIntObjectMap; import org.neo4j.cursor.Cursor; import org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; @@ -66,8 +66,8 @@ static PropertyExistenceEnforcer getOrCreatePropertyExistenceEnforcerFrom( Store private final List nodeConstraints; private final List relationshipConstraints; - private final PrimitiveIntObjectMap mandatoryNodePropertiesByLabel = Primitive.intObjectMap(); - private final PrimitiveIntObjectMap mandatoryRelationshipPropertiesByType = Primitive.intObjectMap(); + private final MutableIntObjectMap mandatoryNodePropertiesByLabel = new IntObjectHashMap<>(); + private final MutableIntObjectMap mandatoryRelationshipPropertiesByType = new IntObjectHashMap<>(); private PropertyExistenceEnforcer( List nodes, List rels ) { @@ -85,7 +85,7 @@ private PropertyExistenceEnforcer( List nodes, List map, int key, int[] sortedValues ) + private static void update( MutableIntObjectMap map, int key, int[] sortedValues ) { int[] current = map.get( key ); if ( current != null ) @@ -324,7 +324,7 @@ private void validateNodeProperties( long id, IntSet labelIds, IntSet propertyKe { if ( labelIds.size() > mandatoryNodePropertiesByLabel.size() ) { - for ( IntIterator labels = mandatoryNodePropertiesByLabel.intIterator(); labels.hasNext(); ) + for ( IntIterator labels = mandatoryNodePropertiesByLabel.keySet().intIterator(); labels.hasNext(); ) { int label = labels.next(); if ( labelIds.contains( label ) )