Skip to content

Commit

Permalink
TreeNodeDynamicSize cleanup
Browse files Browse the repository at this point in the history
We used put- and readKeyOffset and Size when we was in
fact talking about deadSpace and allocOffset.

We now use PageCursorUtil directly instead.
  • Loading branch information
burqen committed Feb 2, 2018
1 parent 336c7bf commit f6a87ae
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ static void putUnsignedShort( PageCursor cursor, int value )
cursor.putShort( (short) value );
}

/**
* Puts the low 2 bytes of the {@code value} into cursor at given offset.
* Puts {@link PageCursor#putShort(short)}.
*
* @param cursor {@link PageCursor} to put into.
* @param offset offset into page where to write.
* @param value the value to put.
*/
static void putUnsignedShort( PageCursor cursor, int offset, int value )
{
if ( (value & ~_2B_MASK) != 0 )
{
throw new IllegalArgumentException( "Illegal 2B value " + value );
}

cursor.putShort( offset, (short) value );
}

/**
* Gets 2 bytes and returns that value as an {@code int}, ignoring its sign.
*
Expand All @@ -98,6 +116,18 @@ static int getUnsignedShort( PageCursor cursor )
return cursor.getShort() & _2B_MASK;
}

/**
* Gets 2 bytes and returns that value as an {@code int}, ignoring its sign.
*
* @param cursor {@link PageCursor} to get from.
* @param offset offset into page from where to read.
* @return {@code int} containing the value of the unsigned {@code short}.
*/
static int getUnsignedShort( PageCursor cursor, int offset )
{
return cursor.getShort( offset ) & _2B_MASK;
}

/**
* Gets 4 bytes and returns that value as an {@code long}, ignoring its sign.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.neo4j.index.internal.gbptree.DynamicSizeUtil.readValueSize;
import static org.neo4j.index.internal.gbptree.DynamicSizeUtil.stripTombstone;
import static org.neo4j.index.internal.gbptree.GenerationSafePointerPair.read;
import static org.neo4j.index.internal.gbptree.PageCursorUtil.putUnsignedShort;
import static org.neo4j.index.internal.gbptree.TreeNode.Type.INTERNAL;
import static org.neo4j.index.internal.gbptree.TreeNode.Type.LEAF;

Expand Down Expand Up @@ -1055,26 +1056,22 @@ private int totalSpaceOfKeyChild( PageCursor cursor, int pos )

private void setAllocOffset( PageCursor cursor, int allocOffset )
{
cursor.setOffset( BYTE_POS_ALLOCOFFSET );
putKeyOffset( cursor, allocOffset );
PageCursorUtil.putUnsignedShort( cursor, BYTE_POS_ALLOCOFFSET, allocOffset );
}

int getAllocOffset( PageCursor cursor )
{
cursor.setOffset( BYTE_POS_ALLOCOFFSET );
return readKeyOffset( cursor );
return PageCursorUtil.getUnsignedShort( cursor, BYTE_POS_ALLOCOFFSET );
}

private void setDeadSpace( PageCursor cursor, int deadSpace )
{
cursor.setOffset( BYTE_POS_DEADSPACE );
putKeySize( cursor, deadSpace );
putUnsignedShort( cursor, BYTE_POS_DEADSPACE, deadSpace );
}

private int getDeadSpace( PageCursor cursor )
{
cursor.setOffset( BYTE_POS_DEADSPACE );
int deadSpace = readKeySize( cursor );
int deadSpace = PageCursorUtil.getUnsignedShort( cursor, BYTE_POS_DEADSPACE );
assert !hasTombstone( deadSpace ) : "Did not expect tombstone in dead space";
return deadSpace;
}
Expand Down

0 comments on commit f6a87ae

Please sign in to comment.