Skip to content

Commit

Permalink
Use eclipse-collections primitive long iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Koval committed May 8, 2018
1 parent bd56df7 commit d324989
Show file tree
Hide file tree
Showing 131 changed files with 556 additions and 650 deletions.
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.consistency.checking.full;

import org.eclipse.collections.api.iterator.LongIterator;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
Expand All @@ -27,7 +29,6 @@
import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntObjectMap;
import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.consistency.checking.ChainCheck;
import org.neo4j.consistency.checking.CheckerEngine;
import org.neo4j.consistency.checking.RecordCheck;
Expand Down Expand Up @@ -131,7 +132,7 @@ private void verifyNodeCorrectlyIndexedUniquely( long nodeId, Value[] propertyVa
{
IndexQuery[] query = seek( indexRule.schema(), propertyValues );

PrimitiveLongIterator indexedNodeIds = queryIndexOrEmpty( reader, query );
final LongIterator indexedNodeIds = queryIndexOrEmpty( reader, query );

long count = 0;
while ( indexedNodeIds.hasNext() )
Expand Down Expand Up @@ -230,9 +231,9 @@ private IndexQuery[] seek( SchemaDescriptor schema, Value[] propertyValues )
return query;
}

private PrimitiveLongIterator queryIndexOrEmpty( IndexReader reader, IndexQuery[] query )
private LongIterator queryIndexOrEmpty( IndexReader reader, IndexQuery[] query )
{
PrimitiveLongIterator indexedNodeIds;
final LongIterator indexedNodeIds;
try
{
indexedNodeIds = reader.query( query );
Expand Down
Expand Up @@ -21,7 +21,7 @@ package org.neo4j.cypher.internal.compatibility.v3_5

import java.net.URL

import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.eclipse.collections.api.iterator.LongIterator
import org.neo4j.cypher.internal.planner.v3_5.spi.IndexDescriptor
import org.neo4j.cypher.internal.runtime._
import org.neo4j.cypher.internal.runtime.interpreted.{DelegatingOperations, DelegatingQueryTransactionalContext}
Expand Down Expand Up @@ -106,7 +106,7 @@ class ExceptionTranslatingQueryContext(val inner: QueryContext) extends QueryCon
override def getNodesByLabel(id: Int): Iterator[NodeValue] =
translateException(inner.getNodesByLabel(id))

override def getNodesByLabelPrimitive(id: Int): PrimitiveLongIterator =
override def getNodesByLabelPrimitive(id: Int): LongIterator =
translateException(inner.getNodesByLabelPrimitive(id))

override def nodeGetDegree(node: Long, dir: SemanticDirection): Int =
Expand Down Expand Up @@ -301,7 +301,7 @@ class ExceptionTranslatingQueryContext(val inner: QueryContext) extends QueryCon
override def all: Iterator[T] =
translateException(inner.all)

override def allPrimitive: PrimitiveLongIterator =
override def allPrimitive: LongIterator =
translateException(inner.allPrimitive)

override def isDeletedInThisTx(id: Long): Boolean =
Expand Down
Expand Up @@ -19,16 +19,17 @@
*/
package org.neo4j.cypher.internal.compatibility.v3_5.runtime.helpers

import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.eclipse.collections.api.iterator.LongIterator


object PrimitiveLongHelper {
def map[T](in: PrimitiveLongIterator, f: Long => T): Iterator[T] = new Iterator[T] {
def map[T](in: LongIterator, f: Long => T): Iterator[T] = new Iterator[T] {
override def hasNext: Boolean = in.hasNext

override def next(): T = f(in.next())
}

def mapPrimitive(in: PrimitiveLongIterator, f: Long => Long): PrimitiveLongIterator = new PrimitiveLongIterator {
def mapPrimitive(in: LongIterator, f: Long => Long): LongIterator = new LongIterator {
override def hasNext: Boolean = in.hasNext

override def next(): Long = f(in.next())
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.cypher.internal.compatibility.v3_5.runtime.profiler

import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.eclipse.collections.api.iterator.LongIterator
import org.neo4j.cypher.internal.compatibility.v3_5.runtime.helpers.PrimitiveLongHelper
import org.neo4j.cypher.internal.runtime.interpreted.pipes.{Pipe, PipeDecorator, QueryState}
import org.neo4j.cypher.internal.runtime.interpreted.{DelegatingOperations, DelegatingQueryContext, ExecutionContext}
Expand Down Expand Up @@ -146,7 +146,7 @@ final class ProfilingPipeQueryContext(inner: QueryContext, val p: Pipe)
}
}

override protected def manyDbHits[A](value: PrimitiveLongIterator): PrimitiveLongIterator = {
override protected def manyDbHits[A](value: LongIterator): LongIterator = {
increment()
PrimitiveLongHelper.mapPrimitive(value, { x =>
increment()
Expand Down Expand Up @@ -190,7 +190,7 @@ final class ProfilingPipeQueryContext(inner: QueryContext, val p: Pipe)
override protected def singleDbHit[A](value: A): A = self.singleDbHit(value)
override protected def manyDbHits[A](value: Iterator[A]): Iterator[A] = self.manyDbHits(value)

override protected def manyDbHits[A](value: PrimitiveLongIterator): PrimitiveLongIterator = self.manyDbHits(value)
override protected def manyDbHits[A](value: LongIterator): LongIterator = self.manyDbHits(value)
}

override def nodeOps: Operations[NodeValue] = new ProfilerOperations(inner.nodeOps)
Expand Down
Expand Up @@ -22,7 +22,8 @@ package org.neo4j.cypher.internal.spi.v2_3
import java.net.URL
import java.util.function.Predicate

import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.eclipse.collections.api.iterator.LongIterator
import org.neo4j.collection.primitive.base.Empty.EMPTY_PRIMITIVE_LONG_COLLECTION
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 @@ -698,7 +699,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper, val re
})

abstract class BaseOperations[T <: PropertyContainer] extends Operations[T] {
def primitiveLongIteratorToScalaIterator(primitiveIterator: PrimitiveLongIterator): Iterator[Long] =
def primitiveLongIteratorToScalaIterator(primitiveIterator: LongIterator): Iterator[Long] =
new Iterator[Long] {
override def hasNext: Boolean = primitiveIterator.hasNext

Expand Down
Expand Up @@ -22,8 +22,8 @@ package org.neo4j.cypher.internal.spi.v3_1
import java.net.URL
import java.util.function.Predicate

import org.eclipse.collections.api.iterator.LongIterator
import org.neo4j.collection.RawIterator
import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.neo4j.cypher.InternalException
import org.neo4j.cypher.internal.compiler.v3_1.MinMaxOrdering.{BY_NUMBER, BY_STRING, BY_VALUE}
import org.neo4j.cypher.internal.compiler.v3_1._
Expand Down Expand Up @@ -713,7 +713,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper,
tokenWrite.propertyKeyGetOrCreateForName(propertyKey)

abstract class BaseOperations[T <: PropertyContainer] extends Operations[T] {
def primitiveLongIteratorToScalaIterator(primitiveIterator: PrimitiveLongIterator): Iterator[Long] =
def primitiveLongIteratorToScalaIterator(primitiveIterator: LongIterator): Iterator[Long] =
new Iterator[Long] {
override def hasNext: Boolean = primitiveIterator.hasNext

Expand Down
Expand Up @@ -21,7 +21,7 @@ package org.neo4j.cypher.internal.runtime.interpreted

import java.net.URL

import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.eclipse.collections.api.iterator.LongIterator
import org.neo4j.cypher.internal.planner.v3_5.spi.{IndexDescriptor, KernelStatisticProvider}
import org.neo4j.cypher.internal.runtime._
import org.neo4j.cypher.internal.v3_5.expressions.SemanticDirection
Expand All @@ -43,7 +43,8 @@ abstract class DelegatingQueryContext(val inner: QueryContext) extends QueryCont

protected def singleDbHit[A](value: A): A = value
protected def manyDbHits[A](value: Iterator[A]): Iterator[A] = value
protected def manyDbHits[A](value: PrimitiveLongIterator): PrimitiveLongIterator = value

protected def manyDbHits[A](value: LongIterator): LongIterator = value
protected def manyDbHits[A](value: RelationshipIterator): RelationshipIterator = value
protected def manyDbHits[A](value: RelationshipSelectionCursor): RelationshipSelectionCursor = value
protected def manyDbHits(count: Int): Int = count
Expand Down Expand Up @@ -118,7 +119,7 @@ abstract class DelegatingQueryContext(val inner: QueryContext) extends QueryCont

override def indexScan(index: IndexReference): Iterator[NodeValue] = manyDbHits(inner.indexScan(index))

override def indexScanPrimitive(index: IndexReference): PrimitiveLongIterator = manyDbHits(inner.indexScanPrimitive(index))
override def indexScanPrimitive(index: IndexReference): LongIterator = manyDbHits(inner.indexScanPrimitive(index))

override def indexScanByContains(index: IndexReference, value: String): scala.Iterator[NodeValue] =
manyDbHits(inner.indexScanByContains(index, value))
Expand All @@ -128,7 +129,7 @@ abstract class DelegatingQueryContext(val inner: QueryContext) extends QueryCont

override def getNodesByLabel(id: Int): Iterator[NodeValue] = manyDbHits(inner.getNodesByLabel(id))

override def getNodesByLabelPrimitive(id: Int): PrimitiveLongIterator = manyDbHits(inner.getNodesByLabelPrimitive(id))
override def getNodesByLabelPrimitive(id: Int): LongIterator = manyDbHits(inner.getNodesByLabelPrimitive(id))

override def getOrCreateFromSchemaState[K, V](key: K, creator: => V): V =
singleDbHit(inner.getOrCreateFromSchemaState(key, creator))
Expand Down Expand Up @@ -261,7 +262,8 @@ class DelegatingOperations[T](protected val inner: Operations[T]) extends Operat

protected def singleDbHit[A](value: A): A = value
protected def manyDbHits[A](value: Iterator[A]): Iterator[A] = value
protected def manyDbHits[A](value: PrimitiveLongIterator): PrimitiveLongIterator = value

protected def manyDbHits[A](value: LongIterator): LongIterator = value

override def delete(id: Long): Unit = singleDbHit(inner.delete(id))

Expand All @@ -280,7 +282,7 @@ class DelegatingOperations[T](protected val inner: Operations[T]) extends Operat

override def all: Iterator[T] = manyDbHits(inner.all)

override def allPrimitive: PrimitiveLongIterator = manyDbHits(inner.allPrimitive)
override def allPrimitive: LongIterator = manyDbHits(inner.allPrimitive)

override def isDeletedInThisTx(id: Long): Boolean = inner.isDeletedInThisTx(id)

Expand Down
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.cypher.internal.runtime.interpreted

import org.eclipse.collections.api.iterator.{IntIterator, LongIterator}
import org.neo4j.collection.primitive.PrimitiveLongIterator

object JavaConversionSupport {

Expand All @@ -32,7 +31,7 @@ object JavaConversionSupport {
def asScalaENFXSafe(iterator: IntIterator): Iterator[Int] = makeENFXSafe(iterator.hasNext, iterator.next)(Some(_))

// Same as mapToScala, but handles concurrency exceptions by swallowing exceptions
def mapToScalaENFXSafe[T](iterator: PrimitiveLongIterator)(f: Long => Option[T]): Iterator[T] = makeENFXSafe(iterator.hasNext, iterator.next)(f)
def mapToScalaENFXSafe[T](iterator: LongIterator)(f: Long => Option[T]): Iterator[T] = makeENFXSafe(iterator.hasNext, iterator.next)(f)

private def makeENFXSafe[S,T](hasMore: () => Boolean, more: () => S)(f: S => Option[T]): Iterator[T] = new Iterator[T] {
private var _next: Option[T] = fetchNext()
Expand Down
Expand Up @@ -22,8 +22,10 @@ package org.neo4j.cypher.internal.runtime.interpreted
import java.net.URL
import java.util.function.Predicate

import org.eclipse.collections.api.iterator.LongIterator
import org.neo4j.collection.RawIterator
import org.neo4j.collection.primitive.{PrimitiveLongIterator, PrimitiveLongResourceIterator}
import org.neo4j.collection.primitive.PrimitiveLongResourceIterator
import org.neo4j.cypher.InternalException
import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService
import org.neo4j.cypher.internal.planner.v3_5.spi.{IdempotentResult, IndexDescriptor}
import org.neo4j.cypher.internal.runtime._
Expand Down Expand Up @@ -330,7 +332,7 @@ sealed class TransactionBoundQueryContext(val transactionalContext: Transactiona
}
}

override def getNodesByLabelPrimitive(id: Int): PrimitiveLongIterator = {
override def getNodesByLabelPrimitive(id: Int): LongIterator = {
val cursor = allocateAndTraceNodeLabelIndexCursor()
reads().nodeLabelScan(id, cursor)
new PrimitiveCursorIterator {
Expand Down Expand Up @@ -461,7 +463,7 @@ sealed class TransactionBoundQueryContext(val transactionalContext: Transactiona
}
}

override def allPrimitive: PrimitiveLongIterator = {
override def allPrimitive: LongIterator = {
val nodeCursor = allocateAndTraceNodeCursor()
reads().allNodesScan(nodeCursor)
new PrimitiveCursorIterator {
Expand Down Expand Up @@ -593,7 +595,7 @@ sealed class TransactionBoundQueryContext(val transactionalContext: Transactiona
}
}

override def allPrimitive: PrimitiveLongIterator = {
override def allPrimitive: LongIterator = {
val relCursor = allocateAndTraceRelationshipScanCursor()
reads().allRelationshipsScan(relCursor)
new PrimitiveCursorIterator {
Expand All @@ -618,7 +620,7 @@ sealed class TransactionBoundQueryContext(val transactionalContext: Transactiona

abstract class BaseOperations[T] extends Operations[T] {

def primitiveLongIteratorToScalaIterator(primitiveIterator: PrimitiveLongIterator): Iterator[Long] =
def primitiveLongIteratorToScalaIterator(primitiveIterator: LongIterator): Iterator[Long] =
new Iterator[Long] {
override def hasNext: Boolean = primitiveIterator.hasNext

Expand Down
Expand Up @@ -21,7 +21,7 @@ package org.neo4j.cypher.internal.runtime.interpreted

import java.net.URL

import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.eclipse.collections.api.iterator.LongIterator
import org.neo4j.cypher.internal.planner.v3_5.spi.{IdempotentResult, IndexDescriptor}
import org.neo4j.cypher.internal.runtime._
import org.neo4j.cypher.internal.v3_5.expressions.SemanticDirection
Expand Down Expand Up @@ -122,7 +122,7 @@ trait QueryContextAdaptation {

override def indexScan(index: IndexReference): scala.Iterator[NodeValue] = ???

override def indexScanPrimitive(index: IndexReference): PrimitiveLongIterator = ???
override def indexScanPrimitive(index: IndexReference): LongIterator = ???

override def getImportURL(url: URL): Either[String, URL] = ???

Expand All @@ -142,7 +142,7 @@ trait QueryContextAdaptation {

override def getNodesByLabel(id: Int): scala.Iterator[NodeValue] = ???

override def getNodesByLabelPrimitive(id: Int): PrimitiveLongIterator = ???
override def getNodesByLabelPrimitive(id: Int): LongIterator = ???

override def lockingUniqueIndexSeek(index: IndexReference, values: Seq[IndexQuery.ExactPredicate]): Option[NodeValue] = ???

Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.cypher.internal.runtime.interpreted.pipes

import org.neo4j.collection.primitive.{PrimitiveLongIterable, PrimitiveLongSet}
import org.neo4j.collection.primitive.{PrimitiveLongCollection, PrimitiveLongSet}
import org.neo4j.cypher.internal.util.v3_5.test_helpers.CypherFunSuite

class LazyGroupingIteratorTest extends CypherFunSuite {
Expand Down Expand Up @@ -99,9 +99,9 @@ class LazyGroupingIteratorTest extends CypherFunSuite {
override def getKey(row: Row) = row.key
}

def asScalaSet(in: PrimitiveLongIterable): Set[Long] = {
def asScalaSet(in: PrimitiveLongCollection): Set[Long] = {
val builder = Set.newBuilder[Long]
val iter = in.iterator()
val iter = in.longIterator()
while (iter.hasNext) {
builder += iter.next()
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.cypher.internal.runtime.interpreted.pipes

import org.neo4j.collection.primitive.PrimitiveLongIterable
import org.eclipse.collections.api.LongIterable
import org.neo4j.cypher.internal.runtime.interpreted.{ExecutionContext, QueryStateHelper}
import org.neo4j.cypher.internal.util.v3_5.symbols._
import org.neo4j.cypher.internal.util.v3_5.test_helpers.CypherFunSuite
Expand Down Expand Up @@ -154,9 +154,9 @@ class TriadicSelectionPipeTest extends CypherFunSuite {
ids should equal(Set((0, 11), (0, 12), (0, 21), (0, 22), (3, 21), (3, 22), (3, 41), (3, 42)))
}

private def asScalaSet(in: PrimitiveLongIterable): Set[Long] = {
private def asScalaSet(in: LongIterable): Set[Long] = {
val builder = Set.newBuilder[Long]
val iter = in.iterator()
val iter = in.longIterator()
while (iter.hasNext) {
builder += iter.next()
}
Expand Down
Expand Up @@ -21,7 +21,7 @@ package org.neo4j.cypher.internal.runtime

import java.net.URL

import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.eclipse.collections.api.iterator.LongIterator
import org.neo4j.cypher.internal.planner.v3_5.spi.{IdempotentResult, IndexDescriptor, KernelStatisticProvider, TokenContext}
import org.neo4j.cypher.internal.v3_5.expressions.SemanticDirection
import org.neo4j.cypher.internal.v3_5.logical.plans.QualifiedName
Expand Down Expand Up @@ -108,13 +108,13 @@ trait QueryContext extends TokenContext {

def indexScan(index: IndexReference): Iterator[NodeValue]

def indexScanPrimitive(index: IndexReference): PrimitiveLongIterator
def indexScanPrimitive(index: IndexReference): LongIterator

def lockingUniqueIndexSeek(index: IndexReference, queries: Seq[IndexQuery.ExactPredicate]): Option[NodeValue]

def getNodesByLabel(id: Int): Iterator[NodeValue]

def getNodesByLabelPrimitive(id: Int): PrimitiveLongIterator
def getNodesByLabelPrimitive(id: Int): LongIterator

def getOrCreateFromSchemaState[K, V](key: K, creator: => V): V

Expand Down Expand Up @@ -228,7 +228,7 @@ trait Operations[T] {

def all: Iterator[T]

def allPrimitive: PrimitiveLongIterator
def allPrimitive: LongIterator

def acquireExclusiveLock(obj: Long): Unit

Expand Down
Expand Up @@ -19,13 +19,14 @@
*/
package org.neo4j.index.internal.gbptree;

import org.eclipse.collections.api.iterator.LongIterator;

import java.io.IOException;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Comparator;
import java.util.List;

import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.io.pagecache.CursorException;
import org.neo4j.io.pagecache.PageCursor;

Expand Down Expand Up @@ -87,7 +88,7 @@ public boolean check( PageCursor cursor, long expectedGeneration ) throws IOExce
* assert calls.
* @throws IOException on {@link PageCursor} error.
*/
boolean checkSpace( PageCursor cursor, long lastId, PrimitiveLongIterator freelistIds ) throws IOException
boolean checkSpace( PageCursor cursor, long lastId, LongIterator freelistIds ) throws IOException
{
assertOnTreeNode( cursor );

Expand Down

0 comments on commit d324989

Please sign in to comment.