Skip to content

Commit

Permalink
Replaced PrimitiveLongSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Koval committed May 8, 2018
1 parent 230ee93 commit dd976be
Show file tree
Hide file tree
Showing 75 changed files with 418 additions and 1,761 deletions.
Expand Up @@ -19,14 +19,15 @@
*/
package org.neo4j.consistency.checking.full;

import org.eclipse.collections.api.set.primitive.MutableLongSet;
import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.consistency.checking.CheckerEngine;
import org.neo4j.consistency.checking.LabelChainWalker;
import org.neo4j.consistency.report.ConsistencyReport;
Expand Down Expand Up @@ -101,7 +102,7 @@ public static long[] getListOfLabels( NodeRecord nodeRecord, RecordStore<Dynamic
if ( NodeLabelsField.fieldPointsToDynamicRecordOfLabels( field ) )
{
List<DynamicRecord> recordList = new ArrayList<>();
PrimitiveLongSet alreadySeen = Primitive.longSet( 16 );
final MutableLongSet alreadySeen = new LongHashSet();
long id = NodeLabelsField.firstDynamicLabelRecordId( field );
while ( !Record.NULL_REFERENCE.is( id ) )
{
Expand Down
Expand Up @@ -41,8 +41,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.consistency.ConsistencyCheckSettings;
import org.neo4j.consistency.RecordType;
import org.neo4j.consistency.checking.GraphStoreFixture;
Expand Down Expand Up @@ -525,11 +523,6 @@ private long[] asArray( List<? extends Number> in )
return longs;
}

private PrimitiveLongSet asPrimitiveLongSet( List<? extends Number> in )
{
return PrimitiveLongCollections.setOf( asArray( in ) );
}

@Test
public void shouldReportMismatchedInlinedLabels() throws Exception
{
Expand Down
Expand Up @@ -22,8 +22,11 @@ package org.neo4j.cypher.internal.spi.v2_3
import java.net.URL
import java.util.function.Predicate

import org.eclipse.collections.api.collection.primitive.ImmutableLongCollection
import org.eclipse.collections.api.iterator.LongIterator
import org.neo4j.collection.primitive.base.Empty.EMPTY_PRIMITIVE_LONG_COLLECTION
import org.eclipse.collections.impl.factory.primitive.LongSets
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator
import org.eclipse.collections.impl.utility.internal.primitive.LongIteratorIterate
import org.neo4j.cypher.InternalException
import org.neo4j.cypher.internal.compiler.v2_3.MinMaxOrdering.{BY_NUMBER, BY_STRING, BY_VALUE}
import org.neo4j.cypher.internal.compiler.v2_3._
Expand Down
Expand Up @@ -23,6 +23,7 @@ import java.net.URL
import java.util.function.Predicate

import org.eclipse.collections.api.iterator.LongIterator
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator
import org.neo4j.collection.RawIterator
import org.neo4j.cypher.InternalException
import org.neo4j.cypher.internal.compiler.v3_1.MinMaxOrdering.{BY_NUMBER, BY_STRING, BY_VALUE}
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.cypher.internal.runtime.interpreted.pipes

import org.neo4j.collection.primitive.PrimitiveLongSet
import org.eclipse.collections.api.set.primitive.LongSet
import org.neo4j.cypher.internal.runtime.interpreted.commands.expressions.PathValueBuilder
import org.neo4j.cypher.internal.runtime.interpreted.commands.predicates.{InCheckContainer, SingleThreadedLRUCache}
import org.neo4j.cypher.internal.runtime.interpreted.{ExecutionContext, MapExecutionContext, MutableMaps}
Expand All @@ -36,7 +36,7 @@ class QueryState(val query: QueryContext,
val decorator: PipeDecorator = NullPipeDecorator,
val timeReader: TimeReader = new TimeReader,
val initialContext: Option[ExecutionContext] = None,
val triadicState: mutable.Map[String, PrimitiveLongSet] = mutable.Map.empty,
val triadicState: mutable.Map[String, LongSet] = mutable.Map.empty,
val repeatableReads: mutable.Map[Pipe, Seq[ExecutionContext]] = mutable.Map.empty,
val cachedIn: SingleThreadedLRUCache[Any, InCheckContainer] =
new SingleThreadedLRUCache(maxSize = 16)) {
Expand Down
Expand Up @@ -19,7 +19,8 @@
*/
package org.neo4j.cypher.internal.runtime.interpreted.pipes

import org.neo4j.collection.primitive.{Primitive, PrimitiveLongSet}
import org.eclipse.collections.api.set.primitive.{LongSet, MutableLongSet}
import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet
import org.neo4j.cypher.internal.util.v3_5.CypherTypeException
import org.neo4j.cypher.internal.runtime.interpreted.ExecutionContext
import org.neo4j.cypher.internal.util.v3_5.attribution.Id
Expand All @@ -34,7 +35,7 @@ case class TriadicSelectionPipe(positivePredicate: Boolean, left: Pipe, source:
extends PipeWithSource(left) {

override protected def internalCreateResults(input: Iterator[ExecutionContext], state: QueryState) = {
var triadicState: PrimitiveLongSet = null
var triadicState: LongSet = null
// 1. Build
new LazyGroupingIterator[ExecutionContext](input) {
override def getKey(row: ExecutionContext) = row(source)
Expand All @@ -45,7 +46,7 @@ extends PipeWithSource(left) {
case x => throw new CypherTypeException(s"Expected a node at `$seen` but got $x")
}

override def setState(triadicSet: PrimitiveLongSet) = triadicState = triadicSet
override def setState(triadicSet: LongSet) = triadicState = triadicSet

// 2. pass through 'right'
}.flatMap { (outerContext) =>
Expand All @@ -65,7 +66,7 @@ extends PipeWithSource(left) {
}

abstract class LazyGroupingIterator[ROW >: Null <: AnyRef](val input: Iterator[ROW]) extends AbstractIterator[ROW] {
def setState(state: PrimitiveLongSet)
def setState(state: LongSet)
def getKey(row: ROW): Any
def getValue(row: ROW): Option[Long]

Expand All @@ -92,7 +93,7 @@ abstract class LazyGroupingIterator[ROW >: Null <: AnyRef](val input: Iterator[R
}
else {
val buffer = new ListBuffer[ROW]
val valueSet = Primitive.longSet()
val valueSet = new LongHashSet()
setState(valueSet)
buffer += firstRow
update(valueSet, firstRow)
Expand All @@ -114,7 +115,7 @@ abstract class LazyGroupingIterator[ROW >: Null <: AnyRef](val input: Iterator[R
}
}

def update(triadicSet: PrimitiveLongSet, row: ROW): AnyVal = {
def update(triadicSet: MutableLongSet, row: ROW): AnyVal = {
for (value <- getValue(row))
triadicSet.add(value)
}
Expand Down
Expand Up @@ -19,7 +19,8 @@
*/
package org.neo4j.cypher.internal.runtime.interpreted.pipes

import org.neo4j.collection.primitive.{PrimitiveLongCollection, PrimitiveLongSet}
import org.eclipse.collections.api.LongIterable
import org.eclipse.collections.api.set.primitive.LongSet
import org.neo4j.cypher.internal.util.v3_5.test_helpers.CypherFunSuite

class LazyGroupingIteratorTest extends CypherFunSuite {
Expand Down Expand Up @@ -88,9 +89,9 @@ class LazyGroupingIteratorTest extends CypherFunSuite {
}

class LazyGroupingRowIterator(rows: Row*) extends LazyGroupingIterator[Row](rows.iterator) {
var state: PrimitiveLongSet = null
var state: LongSet = null

override def setState(state: PrimitiveLongSet) = {
override def setState(state: LongSet) = {
this.state = state
}

Expand All @@ -99,7 +100,7 @@ class LazyGroupingIteratorTest extends CypherFunSuite {
override def getKey(row: Row) = row.key
}

def asScalaSet(in: PrimitiveLongCollection): Set[Long] = {
def asScalaSet(in: LongIterable): Set[Long] = {
val builder = Set.newBuilder[Long]
val iter = in.longIterator()
while (iter.hasNext) {
Expand Down
Expand Up @@ -19,13 +19,14 @@
*/
package org.neo4j.graphdb.traversal;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.eclipse.collections.api.set.primitive.MutableLongSet;
import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet;

import org.neo4j.graphdb.Path;

class GloballyUnique extends AbstractUniquenessFilter
{
private final PrimitiveLongSet visited = Primitive.longSet( 1 << 12 );
private final MutableLongSet visited = new LongHashSet( 1 << 12 );

GloballyUnique( PrimitiveTypeFetcher type )
{
Expand Down
Expand Up @@ -19,14 +19,16 @@
*/
package org.neo4j.graphdb.traversal;

import org.eclipse.collections.api.set.primitive.MutableLongSet;
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.PrimitiveLongSet;
import org.neo4j.graphdb.Path;

class LevelUnique extends AbstractUniquenessFilter
{
private final PrimitiveIntObjectMap<PrimitiveLongSet> idsPerLevel = Primitive.intObjectMap();
private final PrimitiveIntObjectMap<MutableLongSet> idsPerLevel = Primitive.intObjectMap();

LevelUnique( PrimitiveTypeFetcher type )
{
Expand All @@ -37,10 +39,10 @@ class LevelUnique extends AbstractUniquenessFilter
public boolean check( TraversalBranch branch )
{
int level = branch.length();
PrimitiveLongSet levelIds = idsPerLevel.get( level );
MutableLongSet levelIds = idsPerLevel.get( level );
if ( levelIds == null )
{
levelIds = Primitive.longSet();
levelIds = new LongHashSet();
idsPerLevel.put( level, levelIds );
}
return levelIds.add( type.getId( branch ) );
Expand Down
Expand Up @@ -20,6 +20,8 @@
package org.neo4j.index.internal.gbptree;

import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.collections.api.set.primitive.MutableLongSet;
import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet;

import java.io.Closeable;
import java.io.File;
Expand All @@ -32,8 +34,6 @@
import java.util.function.LongSupplier;
import java.util.function.Supplier;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.cursor.RawCursor;
import org.neo4j.helpers.Exceptions;
import org.neo4j.io.pagecache.IOLimiter;
Expand Down Expand Up @@ -1081,7 +1081,7 @@ boolean consistencyCheck() throws IOException
boolean check = consistencyChecker.check( cursor, rootGeneration );
root.goTo( cursor );

PrimitiveLongSet freelistIds = Primitive.longSet();
final MutableLongSet freelistIds = new LongHashSet();
freeList.visitFreelistPageIds( freelistIds::add );
freeList.visitUnacquiredIds( freelistIds::add, unstableGeneration );
boolean checkSpace = consistencyChecker.checkSpace( cursor, freeList.lastId(), freelistIds.longIterator() );
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.index.internal.gbptree;

import org.eclipse.collections.api.set.primitive.MutableLongSet;
import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -28,8 +30,6 @@
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.index.internal.gbptree.FreeListIdProvider.Monitor;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.io.pagecache.PagedFile;
Expand Down Expand Up @@ -112,7 +112,7 @@ public void shouldPutFreedFreeListPagesIntoFreeListAsWell() throws Exception
long prevId;
long acquiredId = BASE_ID + 1;
long freelistPageId = BASE_ID + 1;
PrimitiveLongSet released = Primitive.longSet();
MutableLongSet released = new LongHashSet();
do
{
prevId = acquiredId;
Expand All @@ -137,7 +137,7 @@ public void shouldPutFreedFreeListPagesIntoFreeListAsWell() throws Exception
public void shouldStayBoundUnderStress() throws Exception
{
// GIVEN
PrimitiveLongSet acquired = Primitive.longSet();
MutableLongSet acquired = new LongHashSet();
List<Long> acquiredList = new ArrayList<>(); // for quickly finding random to remove
long stableGeneration = GenerationSafePointer.MIN_GENERATION;
long unstableGeneration = stableGeneration + 1;
Expand Down Expand Up @@ -192,15 +192,21 @@ public void shouldStayBoundUnderStress() throws Exception
public void shouldVisitUnacquiredIds() throws Exception
{
// GIVEN a couple of released ids
PrimitiveLongSet expected = Primitive.longSet();
MutableLongSet expected = new LongHashSet();
for ( int i = 0; i < 100; i++ )
{
expected.add( freelist.acquireNewId( GENERATION_ONE, GENERATION_TWO ) );
}
expected.visitKeys( id ->
expected.forEach( id ->
{
freelist.releaseId( GENERATION_ONE, GENERATION_TWO, id );
return false;
try
{
freelist.releaseId( GENERATION_ONE, GENERATION_TWO, id );
}
catch ( IOException e )
{
throw new RuntimeException( e );
}
} );
// and only a few acquired
for ( int i = 0; i < 10; i++ )
Expand All @@ -218,7 +224,7 @@ public void shouldVisitUnacquiredIds() throws Exception
public void shouldVisitFreelistPageIds() throws Exception
{
// GIVEN a couple of released ids
PrimitiveLongSet expected = Primitive.longSet();
MutableLongSet expected = new LongHashSet();
// Add the already allocated free-list page id
expected.add( BASE_ID + 1 );
monitor.set( new Monitor()
Expand Down
Expand Up @@ -19,6 +19,9 @@
*/
package org.neo4j.io.pagecache.randomharness;

import org.eclipse.collections.api.set.primitive.LongSet;
import org.eclipse.collections.impl.factory.primitive.LongSets;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -28,8 +31,6 @@
import java.util.Random;
import java.util.Set;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.io.pagecache.TinyLockManager;
Expand Down Expand Up @@ -184,7 +185,7 @@ private Action readRecord()

private Action writeRecord()
{
return buildWriteAction( null, Primitive.longSet() );
return buildWriteAction( null, LongSets.immutable.empty() );
}

private Action readMulti()
Expand All @@ -201,11 +202,10 @@ private Action readMulti()
private Action writeMulti()
{
int count = rng.nextInt( 5 ) + 1;
PrimitiveLongSet recordIds = Primitive.longSet();
Action action = null;
for ( int i = 0; i < count; i++ )
{
action = buildWriteAction( action, recordIds );
action = buildWriteAction( action, LongSets.immutable.empty() );
}
return action;
}
Expand All @@ -227,7 +227,7 @@ private Action buildReadRecord( Action innerAction )
return new ReadAction( file, recordId, pageId, pageOffset, expectedRecord, innerAction );
}

private Action buildWriteAction( Action innerAction, PrimitiveLongSet forbiddenRecordIds )
private Action buildWriteAction( Action innerAction, LongSet forbiddenRecordIds )
{
int mappedFilesCount = mappedFiles.size();
if ( mappedFilesCount == 0 )
Expand Down
Expand Up @@ -19,10 +19,10 @@
*/
package org.neo4j.internal.kernel.api;

import org.eclipse.collections.api.set.primitive.MutableLongSet;
import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet;
import org.junit.Test;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.RelationshipType;
Expand Down Expand Up @@ -99,9 +99,9 @@ public void shouldTraverseTreeOfDepthThree()
try ( NodeCursor node = cursors.allocateNodeCursor();
RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor();
RelationshipTraversalCursor relationship1 = cursors.allocateRelationshipTraversalCursor();
RelationshipTraversalCursor relationship2 = cursors.allocateRelationshipTraversalCursor();
PrimitiveLongSet leafs = Primitive.longSet() )
RelationshipTraversalCursor relationship2 = cursors.allocateRelationshipTraversalCursor() )
{
MutableLongSet leafs = new LongHashSet();
long total = 0;

// when
Expand Down

0 comments on commit dd976be

Please sign in to comment.