Skip to content

Commit

Permalink
Replaced primitive stacks with eclipse-collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Koval committed May 8, 2018
1 parent be773f3 commit 0562120
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 479 deletions.
Expand Up @@ -19,10 +19,13 @@
*/ */
package org.neo4j.index.internal.gbptree; package org.neo4j.index.internal.gbptree;


import org.eclipse.collections.api.stack.primitive.IntStack;
import org.eclipse.collections.api.stack.primitive.MutableIntStack;
import org.eclipse.collections.impl.stack.mutable.primitive.IntArrayStack;

import java.util.Arrays; import java.util.Arrays;
import java.util.StringJoiner; import java.util.StringJoiner;


import org.neo4j.collection.primitive.PrimitiveIntStack;
import org.neo4j.io.pagecache.PageCursor; import org.neo4j.io.pagecache.PageCursor;


import static java.lang.String.format; import static java.lang.String.format;
Expand Down Expand Up @@ -90,8 +93,8 @@ public class TreeNodeDynamicSize<KEY, VALUE> extends TreeNode<KEY,VALUE>
private static final int LEAST_NUMBER_OF_ENTRIES_PER_PAGE = 2; private static final int LEAST_NUMBER_OF_ENTRIES_PER_PAGE = 2;
private static final int MINIMUM_ENTRY_SIZE_CAP = Long.SIZE; private static final int MINIMUM_ENTRY_SIZE_CAP = Long.SIZE;
private final int keyValueSizeCap; private final int keyValueSizeCap;
private final PrimitiveIntStack deadKeysOffset = new PrimitiveIntStack(); private final MutableIntStack deadKeysOffset = new IntArrayStack();
private final PrimitiveIntStack aliveKeysOffset = new PrimitiveIntStack(); private final MutableIntStack aliveKeysOffset = new IntArrayStack();
private final int maxKeyCount = pageSize / (bytesKeyOffset() + SIZE_KEY_SIZE + SIZE_VALUE_SIZE); private final int maxKeyCount = pageSize / (bytesKeyOffset() + SIZE_KEY_SIZE + SIZE_VALUE_SIZE);
private final int[] oldOffset = new int[maxKeyCount]; private final int[] oldOffset = new int[maxKeyCount];
private final int[] newOffset = new int[maxKeyCount]; private final int[] newOffset = new int[maxKeyCount];
Expand Down Expand Up @@ -471,25 +474,25 @@ For each dead space of size X (can be multiple consecutive dead keys)
int deadRangeOffset; // Everything between this point and aliveRangeOffset is dead space int deadRangeOffset; // Everything between this point and aliveRangeOffset is dead space


// Rightmost alive keys does not need to move // Rightmost alive keys does not need to move
while ( deadKeysOffset.peek() < aliveKeysOffset.peek() ) while ( peek( deadKeysOffset ) < peek( aliveKeysOffset ) )
{ {
aliveRangeOffset = aliveKeysOffset.poll(); aliveRangeOffset = poll( aliveKeysOffset );
} }


do do
{ {
// Locate next range of dead keys // Locate next range of dead keys
deadRangeOffset = aliveRangeOffset; deadRangeOffset = aliveRangeOffset;
while ( aliveKeysOffset.peek() < deadKeysOffset.peek() ) while ( peek( aliveKeysOffset ) < peek( deadKeysOffset ) )
{ {
deadRangeOffset = deadKeysOffset.poll(); deadRangeOffset = poll( deadKeysOffset );
} }


// Locate next range of alive keys // Locate next range of alive keys
int moveOffset = deadRangeOffset; int moveOffset = deadRangeOffset;
while ( deadKeysOffset.peek() < aliveKeysOffset.peek() ) while ( peek( deadKeysOffset ) < peek( aliveKeysOffset ) )
{ {
int moveKey = aliveKeysOffset.poll(); int moveKey = poll( aliveKeysOffset );
oldOffset[oldOffsetCursor++] = moveKey; oldOffset[oldOffsetCursor++] = moveKey;
moveOffset = moveKey; moveOffset = moveKey;
} }
Expand Down Expand Up @@ -551,6 +554,16 @@ For each dead space of size X (can be multiple consecutive dead keys)
setDeadSpace( cursor, 0 ); setDeadSpace( cursor, 0 );
} }


private static int peek( IntStack stack )
{
return stack.isEmpty() ? -1 : stack.peek();
}

private static int poll( MutableIntStack stack )
{
return stack.isEmpty() ? -1 : stack.pop();
}

@Override @Override
boolean leafUnderflow( PageCursor cursor, int keyCount ) boolean leafUnderflow( PageCursor cursor, int keyCount )
{ {
Expand Down Expand Up @@ -855,7 +868,7 @@ private int getAllocSpace( PageCursor cursor, int keyCount, Type type )
return allocOffset - endOfOffsetArray; return allocOffset - endOfOffsetArray;
} }


private void recordDeadAndAliveLeaf( PageCursor cursor, PrimitiveIntStack deadKeysOffset, PrimitiveIntStack aliveKeysOffset ) private void recordDeadAndAliveLeaf( PageCursor cursor, MutableIntStack deadKeysOffset, MutableIntStack aliveKeysOffset )
{ {
int currentOffset = getAllocOffset( cursor ); int currentOffset = getAllocOffset( cursor );
while ( currentOffset < pageSize ) while ( currentOffset < pageSize )
Expand All @@ -878,7 +891,7 @@ private void recordDeadAndAliveLeaf( PageCursor cursor, PrimitiveIntStack deadKe
} }
} }


private void recordDeadAndAliveInternal( PageCursor cursor, PrimitiveIntStack deadKeysOffset, PrimitiveIntStack aliveKeysOffset ) private void recordDeadAndAliveInternal( PageCursor cursor, MutableIntStack deadKeysOffset, MutableIntStack aliveKeysOffset )
{ {
int currentOffset = getAllocOffset( cursor ); int currentOffset = getAllocOffset( cursor );
while ( currentOffset < pageSize ) while ( currentOffset < pageSize )
Expand Down
Expand Up @@ -19,10 +19,12 @@
*/ */
package org.neo4j.unsafe.impl.batchimport.cache.idmapping.string; package org.neo4j.unsafe.impl.batchimport.cache.idmapping.string;


import org.eclipse.collections.api.stack.primitive.MutableLongStack;
import org.eclipse.collections.impl.stack.mutable.primitive.LongArrayStack;

import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;


import org.neo4j.collection.primitive.PrimitiveLongStack;
import org.neo4j.helpers.progress.ProgressListener; import org.neo4j.helpers.progress.ProgressListener;
import org.neo4j.unsafe.impl.batchimport.Utils; import org.neo4j.unsafe.impl.batchimport.Utils;
import org.neo4j.unsafe.impl.batchimport.Utils.CompareType; import org.neo4j.unsafe.impl.batchimport.Utils.CompareType;
Expand Down Expand Up @@ -311,13 +313,13 @@ else if ( comparator.ge( right, pivot ) )


private void qsort( long initialStart, long initialEnd ) private void qsort( long initialStart, long initialEnd )
{ {
PrimitiveLongStack stack = new PrimitiveLongStack( 100 ); final MutableLongStack stack = new LongArrayStack();
stack.push( initialStart ); stack.push( initialStart );
stack.push( initialEnd ); stack.push( initialEnd );
while ( !stack.isEmpty() ) while ( !stack.isEmpty() )
{ {
long end = stack.poll(); long end = stack.isEmpty() ? -1 : stack.pop();
long start = stack.poll(); long start = stack.isEmpty() ? -1 : stack.pop();
long diff = end - start; long diff = end - start;
if ( diff < 2 ) if ( diff < 2 )
{ {
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 0562120

Please sign in to comment.