Skip to content

Commit

Permalink
Changes GenericKeyState hierarchy
Browse files Browse the repository at this point in the history
To be isolated to only the generic keys and not affect
any other key implementation. So going from:

  GenericKeyState
    -> NativeIndexKey
      -> GenericKey
        -> SingleGenericKey
        -> CompositeGenericKey
      -> NativeIndexSingleValueKey
        -> ... all the other keys ...

To:

  NativeIndexKey
    -> GenericKey (single-value)
      -> CompositeGenericKey
    -> NativeIndexSingleValueKey
        -> ... all the other keys ...
  • Loading branch information
tinwelint committed Oct 2, 2018
1 parent 41517fd commit 46bd5d4
Show file tree
Hide file tree
Showing 33 changed files with 958 additions and 1,089 deletions.
Expand Up @@ -44,21 +44,21 @@
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.SchemaIndex.NATIVE_BTREE10; import static org.neo4j.graphdb.factory.GraphDatabaseSettings.SchemaIndex.NATIVE_BTREE10;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.default_schema_provider; import static org.neo4j.graphdb.factory.GraphDatabaseSettings.default_schema_provider;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_BOOLEAN; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_BOOLEAN;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_DATE; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_DATE;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_DURATION; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_DURATION;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_GEOMETRY; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_GEOMETRY;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_LOCAL_DATE_TIME; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_LOCAL_DATE_TIME;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_LOCAL_TIME; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_LOCAL_TIME;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_NUMBER_BYTE; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_NUMBER_BYTE;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_NUMBER_DOUBLE; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_NUMBER_DOUBLE;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_NUMBER_FLOAT; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_NUMBER_FLOAT;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_NUMBER_INT; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_NUMBER_INT;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_NUMBER_LONG; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_NUMBER_LONG;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_NUMBER_SHORT; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_NUMBER_SHORT;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_STRING_LENGTH; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_STRING_LENGTH;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_ZONED_DATE_TIME; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_ZONED_DATE_TIME;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_ZONED_TIME; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_ZONED_TIME;
import static org.neo4j.test.TestLabels.LABEL_ONE; import static org.neo4j.test.TestLabels.LABEL_ONE;


public class GenericIndexValidationIT public class GenericIndexValidationIT
Expand Down
Expand Up @@ -29,10 +29,10 @@
import org.neo4j.values.storable.Values; import org.neo4j.values.storable.Values;


import static java.lang.Integer.min; import static java.lang.Integer.min;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.BIGGEST_REASONABLE_ARRAY_LENGTH; import static org.neo4j.kernel.impl.index.schema.GenericKey.BIGGEST_REASONABLE_ARRAY_LENGTH;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.SIZE_ARRAY_LENGTH; import static org.neo4j.kernel.impl.index.schema.GenericKey.SIZE_ARRAY_LENGTH;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.setCursorException; import static org.neo4j.kernel.impl.index.schema.GenericKey.setCursorException;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.toNonNegativeShortExact; import static org.neo4j.kernel.impl.index.schema.GenericKey.toNonNegativeShortExact;


/** /**
* Common ancestor of all array-types. Many of the methods are implemented by doing array looping and delegating array item operations * Common ancestor of all array-types. Many of the methods are implemented by doing array looping and delegating array item operations
Expand Down Expand Up @@ -68,17 +68,17 @@ abstract class AbstractArrayType<T> extends Type
} }


@Override @Override
final void copyValue( GenericKeyState to, GenericKeyState from ) final void copyValue( GenericKey to, GenericKey from )
{ {
copyValue( to, from, from.arrayLength ); copyValue( to, from, from.arrayLength );
} }


abstract void copyValue( GenericKeyState to, GenericKeyState from, int arrayLength ); abstract void copyValue( GenericKey to, GenericKey from, int arrayLength );


abstract void initializeArray( GenericKeyState key, int length, ValueWriter.ArrayType arrayType ); abstract void initializeArray( GenericKey key, int length, ValueWriter.ArrayType arrayType );


@Override @Override
void minimalSplitter( GenericKeyState left, GenericKeyState right, GenericKeyState into ) void minimalSplitter( GenericKey left, GenericKey right, GenericKey into )
{ {
int lastEqualIndex = -1; int lastEqualIndex = -1;
if ( left.type == right.type ) if ( left.type == right.type )
Expand All @@ -102,7 +102,7 @@ void minimalSplitter( GenericKeyState left, GenericKeyState right, GenericKeySta
} }


@Override @Override
int compareValue( GenericKeyState left, GenericKeyState right ) int compareValue( GenericKey left, GenericKey right )
{ {
if ( left.isHighestArray || right.isHighestArray ) if ( left.isHighestArray || right.isHighestArray )
{ {
Expand All @@ -122,7 +122,7 @@ int compareValue( GenericKeyState left, GenericKeyState right )
} }


@Override @Override
Value asValue( GenericKeyState state ) Value asValue( GenericKey state )
{ {
T[] array = arrayCreator.apply( state.arrayLength ); T[] array = arrayCreator.apply( state.arrayLength );
for ( int i = 0; i < state.arrayLength; i++ ) for ( int i = 0; i < state.arrayLength; i++ )
Expand All @@ -133,13 +133,13 @@ Value asValue( GenericKeyState state )
} }


@Override @Override
void putValue( PageCursor cursor, GenericKeyState state ) void putValue( PageCursor cursor, GenericKey state )
{ {
putArray( cursor, state, arrayElementWriter ); putArray( cursor, state, arrayElementWriter );
} }


@Override @Override
boolean readValue( PageCursor cursor, int size, GenericKeyState into ) boolean readValue( PageCursor cursor, int size, GenericKey into )
{ {
return readArray( cursor, arrayType, arrayElementReader, into ); return readArray( cursor, arrayType, arrayElementReader, into );
} }
Expand All @@ -150,21 +150,21 @@ boolean readValue( PageCursor cursor, int size, GenericKeyState into )
* @param state key state to initialize as lowest of this type. * @param state key state to initialize as lowest of this type.
*/ */
@Override @Override
void initializeAsLowest( GenericKeyState state ) void initializeAsLowest( GenericKey state )
{ {
state.initializeArrayMeta( 0 ); state.initializeArrayMeta( 0 );
initializeArray( state, 0, arrayType ); initializeArray( state, 0, arrayType );
} }


@Override @Override
void initializeAsHighest( GenericKeyState state ) void initializeAsHighest( GenericKey state )
{ {
state.initializeArrayMeta( 0 ); state.initializeArrayMeta( 0 );
initializeArray( state, 0, arrayType ); initializeArray( state, 0, arrayType );
state.isHighestArray = true; state.isHighestArray = true;
} }


int arrayKeySize( GenericKeyState key, int elementSize ) int arrayKeySize( GenericKey key, int elementSize )
{ {
return SIZE_ARRAY_LENGTH + key.arrayLength * elementSize; return SIZE_ARRAY_LENGTH + key.arrayLength * elementSize;
} }
Expand All @@ -174,21 +174,21 @@ static void putArrayHeader( PageCursor cursor, short arrayLength )
cursor.putShort( arrayLength ); cursor.putShort( arrayLength );
} }


static void putArrayItems( PageCursor cursor, GenericKeyState key, ArrayElementWriter itemWriter ) static void putArrayItems( PageCursor cursor, GenericKey key, ArrayElementWriter itemWriter )
{ {
for ( int i = 0; i < key.arrayLength; i++ ) for ( int i = 0; i < key.arrayLength; i++ )
{ {
itemWriter.write( cursor, key, i ); itemWriter.write( cursor, key, i );
} }
} }


static void putArray( PageCursor cursor, GenericKeyState key, ArrayElementWriter writer ) static void putArray( PageCursor cursor, GenericKey key, ArrayElementWriter writer )
{ {
putArrayHeader( cursor, toNonNegativeShortExact( key.arrayLength ) ); putArrayHeader( cursor, toNonNegativeShortExact( key.arrayLength ) );
putArrayItems( cursor, key, writer ); putArrayItems( cursor, key, writer );
} }


static boolean readArray( PageCursor cursor, ValueWriter.ArrayType type, ArrayElementReader reader, GenericKeyState into ) static boolean readArray( PageCursor cursor, ValueWriter.ArrayType type, ArrayElementReader reader, GenericKey into )
{ {
if ( !setArrayLengthWhenReading( into, cursor, cursor.getShort() ) ) if ( !setArrayLengthWhenReading( into, cursor, cursor.getShort() ) )
{ {
Expand All @@ -206,7 +206,7 @@ static boolean readArray( PageCursor cursor, ValueWriter.ArrayType type, ArrayEl
return true; return true;
} }


static boolean setArrayLengthWhenReading( GenericKeyState state, PageCursor cursor, short arrayLength ) static boolean setArrayLengthWhenReading( GenericKey state, PageCursor cursor, short arrayLength )
{ {
state.arrayLength = arrayLength; state.arrayLength = arrayLength;
if ( state.arrayLength < 0 || state.arrayLength > BIGGEST_REASONABLE_ARRAY_LENGTH ) if ( state.arrayLength < 0 || state.arrayLength > BIGGEST_REASONABLE_ARRAY_LENGTH )
Expand All @@ -221,24 +221,24 @@ static boolean setArrayLengthWhenReading( GenericKeyState state, PageCursor curs
@FunctionalInterface @FunctionalInterface
interface ArrayElementComparator interface ArrayElementComparator
{ {
int compare( GenericKeyState o1, GenericKeyState o2, int i ); int compare( GenericKey o1, GenericKey o2, int i );
} }


@FunctionalInterface @FunctionalInterface
interface ArrayElementReader interface ArrayElementReader
{ {
boolean readFrom( PageCursor cursor, GenericKeyState into ); boolean readFrom( PageCursor cursor, GenericKey into );
} }


@FunctionalInterface @FunctionalInterface
interface ArrayElementWriter interface ArrayElementWriter
{ {
void write( PageCursor cursor, GenericKeyState key, int i ); void write( PageCursor cursor, GenericKey key, int i );
} }


@FunctionalInterface @FunctionalInterface
interface ArrayElementValueFactory<T> interface ArrayElementValueFactory<T>
{ {
T from( GenericKeyState key, int i ); T from( GenericKey key, int i );
} }
} }
Expand Up @@ -24,8 +24,8 @@
import org.neo4j.values.storable.ValueWriter; import org.neo4j.values.storable.ValueWriter;
import org.neo4j.values.storable.Values; import org.neo4j.values.storable.Values;


import static org.neo4j.kernel.impl.index.schema.GenericKeyState.FALSE; import static org.neo4j.kernel.impl.index.schema.GenericKey.FALSE;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.TRUE; import static org.neo4j.kernel.impl.index.schema.GenericKey.TRUE;


// <Boolean> as generic raw type is mostly for show, this class overrides default object:y behaviour to create primitive boolean[] array // <Boolean> as generic raw type is mostly for show, this class overrides default object:y behaviour to create primitive boolean[] array
class BooleanArrayType extends AbstractArrayType<Boolean> class BooleanArrayType extends AbstractArrayType<Boolean>
Expand All @@ -44,26 +44,26 @@ class BooleanArrayType extends AbstractArrayType<Boolean>
} }


@Override @Override
int valueSize( GenericKeyState state ) int valueSize( GenericKey state )
{ {
return arrayKeySize( state, GenericKeyState.SIZE_BOOLEAN ); return arrayKeySize( state, GenericKey.SIZE_BOOLEAN );
} }


@Override @Override
void copyValue( GenericKeyState to, GenericKeyState from, int length ) void copyValue( GenericKey to, GenericKey from, int length )
{ {
initializeArray( to, length, null ); initializeArray( to, length, null );
System.arraycopy( from.long0Array, 0, to.long0Array, 0, length ); System.arraycopy( from.long0Array, 0, to.long0Array, 0, length );
} }


@Override @Override
void initializeArray( GenericKeyState key, int length, ValueWriter.ArrayType arrayType ) void initializeArray( GenericKey key, int length, ValueWriter.ArrayType arrayType )
{ {
key.long0Array = ensureBigEnough( key.long0Array, length ); key.long0Array = ensureBigEnough( key.long0Array, length );
} }


@Override @Override
Value asValue( GenericKeyState state ) Value asValue( GenericKey state )
{ {
boolean[] array = new boolean[state.arrayLength]; boolean[] array = new boolean[state.arrayLength];
for ( int i = 0; i < state.arrayLength; i++ ) for ( int i = 0; i < state.arrayLength; i++ )
Expand All @@ -73,7 +73,7 @@ Value asValue( GenericKeyState state )
return Values.of( array ); return Values.of( array );
} }


void write( GenericKeyState state, int offset, boolean value ) void write( GenericKey state, int offset, boolean value )
{ {
state.long0Array[offset] = value ? TRUE : FALSE; state.long0Array[offset] = value ? TRUE : FALSE;
} }
Expand Down
Expand Up @@ -25,8 +25,8 @@
import org.neo4j.values.storable.ValueGroup; import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.Values; import org.neo4j.values.storable.Values;


import static org.neo4j.kernel.impl.index.schema.GenericKeyState.FALSE; import static org.neo4j.kernel.impl.index.schema.GenericKey.FALSE;
import static org.neo4j.kernel.impl.index.schema.GenericKeyState.TRUE; import static org.neo4j.kernel.impl.index.schema.GenericKey.TRUE;


class BooleanType extends Type class BooleanType extends Type
{ {
Expand All @@ -39,39 +39,39 @@ class BooleanType extends Type
} }


@Override @Override
int valueSize( GenericKeyState state ) int valueSize( GenericKey state )
{ {
return GenericKeyState.SIZE_BOOLEAN; return GenericKey.SIZE_BOOLEAN;
} }


@Override @Override
void copyValue( GenericKeyState to, GenericKeyState from ) void copyValue( GenericKey to, GenericKey from )
{ {
to.long0 = from.long0; to.long0 = from.long0;
} }


@Override @Override
Value asValue( GenericKeyState state ) Value asValue( GenericKey state )
{ {
return asValue( state.long0 ); return asValue( state.long0 );
} }


@Override @Override
int compareValue( GenericKeyState left, GenericKeyState right ) int compareValue( GenericKey left, GenericKey right )
{ {
return compare( return compare(
left.long0, left.long0,
right.long0 ); right.long0 );
} }


@Override @Override
void putValue( PageCursor cursor, GenericKeyState state ) void putValue( PageCursor cursor, GenericKey state )
{ {
put( cursor, state.long0 ); put( cursor, state.long0 );
} }


@Override @Override
boolean readValue( PageCursor cursor, int size, GenericKeyState into ) boolean readValue( PageCursor cursor, int size, GenericKey into )
{ {
return read( cursor, into ); return read( cursor, into );
} }
Expand All @@ -98,13 +98,13 @@ static void put( PageCursor cursor, long long0 )
cursor.putByte( (byte) long0 ); cursor.putByte( (byte) long0 );
} }


static boolean read( PageCursor cursor, GenericKeyState into ) static boolean read( PageCursor cursor, GenericKey into )
{ {
into.writeBoolean( cursor.getByte() == TRUE ); into.writeBoolean( cursor.getByte() == TRUE );
return true; return true;
} }


void write( GenericKeyState state, boolean value ) void write( GenericKey state, boolean value )
{ {
state.long0 = value ? TRUE : FALSE; state.long0 = value ? TRUE : FALSE;
} }
Expand Down

0 comments on commit 46bd5d4

Please sign in to comment.