You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/01/20 19:38:00 UTC
svn commit: r1234057 -
/directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/Page.java
Author: elecharny
Date: Fri Jan 20 18:37:59 2012
New Revision: 1234057
URL: http://svn.apache.org/viewvc?rev=1234057&view=rev
Log:
o Added the missing Javadoc
o A bit of cleanup
Modified:
directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/Page.java
Modified: directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/Page.java
URL: http://svn.apache.org/viewvc/directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/Page.java?rev=1234057&r1=1234056&r2=1234057&view=diff
==============================================================================
--- directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/Page.java (original)
+++ directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/Page.java Fri Jan 20 18:37:59 2012
@@ -21,6 +21,11 @@ package org.apache.directory.btree;
/**
+ * A MVCC Page. It contains the keys and the values, plus references to the child pages.
+ *
+ * @param <K> The type for the Key
+ * @param <V> The type for the stored value
+
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class Page<K, V> implements Cloneable
@@ -76,7 +81,7 @@ public class Page<K, V> implements Clone
* @param revisio the current revision
*/
@SuppressWarnings("unchecked") // Cannot create an array of generic objects
- /** No qualifier */ Page( BTree<K,V> btree, K key, V value )
+ /* No qualifier */ Page( BTree<K,V> btree, K key, V value )
{
this.btree = btree;
this.revision = btree.generateRevision();
@@ -99,8 +104,15 @@ public class Page<K, V> implements Clone
}
+ /**
+ * Creates a new root page, when the root is not anymore a leaf, and has been split.
+ *
+ * @param revision The new page revision
+ * @param btree The associated btree
+ * @param result The split Page
+ */
@SuppressWarnings("unchecked")
- /** No qualifier */ Page( long revision, BTree<K, V> btree, OverflowResult<K, V> result )
+ /* No qualifier */ Page( long revision, BTree<K, V> btree, OverflowResult<K, V> result )
{
this.revision = revision;
this.btree = btree;
@@ -117,7 +129,13 @@ public class Page<K, V> implements Clone
}
- /** No qualifier */ V find( K key )
+ /**
+ * Find a value in the tree, using its key. If it's not found, this method returns null
+ *
+ * @param key The key of the searched value
+ * @return The value, if its key is present in the tree
+ */
+ /* No qualifier */ V find( K key )
{
int index = findIndex( key );
@@ -144,40 +162,44 @@ public class Page<K, V> implements Clone
* Get largest key under this BPage. Null is considered to be the
* greatest possible key.
*/
- /** No qualifier */ K getLargestKey()
+ /* No qualifier */ K getLargestKey()
{
return keys[btree.pageSize - 1];
}
/**
- * @return The record ID
+ * @return The record ID of this page
*/
- /** No qualifier */ long getRecordId()
+ /* No qualifier */ long getRecordId()
{
return recordId;
}
/**
- * @return The revision
+ * @return The page's revision
*/
- /** No qualifier */ long getRevision()
+ /* No qualifier */ long getRevision()
{
return revision;
}
/**
- * @return The number of elements
+ * @return The number of elements in this page
*/
- /** No qualifier */ long getNbElems()
+ /* No qualifier */ long getNbElems()
{
return nbElems;
}
- /** No qualifier */ boolean isLeaf()
+ /**
+ * Tells if this page has children or not
+ * @return true if the page has no children
+ */
+ /* No qualifier */ boolean isLeaf()
{
return isLeaf;
}
@@ -335,7 +357,6 @@ public class Page<K, V> implements Clone
OverflowResult<K, V> overflow = (OverflowResult<K, V>)result;
return addAndSplit( revision, index, overflow.pivotKey, overflow.pivotValue, overflow.leftPage, overflow.rightPage );
- //return split( revision, (OverflowResult<K, V>)result, index );
}
}
}
@@ -397,6 +418,15 @@ public class Page<K, V> implements Clone
}
+ /**
+ * Inject an element from a split page into the current page, which can contain it without
+ * being split itself.
+ *
+ * @param revision The new revision
+ * @param result The overflow element
+ * @param index The position of the overflow element in the current page
+ * @return The modified page containing the overflow element
+ */
@SuppressWarnings("unchecked")
private InsertResult<K, V> insertOverflow( long revision, OverflowResult<K, V> result, int index )
{
@@ -543,6 +573,12 @@ public class Page<K, V> implements Clone
return newPage;
}
+
+ /**
+ * Private method used to print an array, for debug purposes.
+ *
+ * @param array The array to dump
+ */
private void dump( Object[] array )
{
boolean isFirst = true;
@@ -567,6 +603,10 @@ public class Page<K, V> implements Clone
}
+ /**
+ * Copy an array into a new one, with a dump if we get an OOBE. this method is
+ * only used for debug purposes.
+ */
void arrayCopy( Object[] src, int srcPos, Object[] dest, int destPos, int length )
{
try
@@ -748,37 +788,48 @@ public class Page<K, V> implements Clone
}
- private final int compare( K value1, K value2 )
+ /**
+ * Compare two keys
+ * @param key1 The first key
+ * @param key2 The second key
+ * @return -1 if the first key is above the second one, 1 if it's below, and 0
+ * if the two keys are equal
+ */
+ private final int compare( K key1, K key2 )
{
- if ( value1 == value2 )
+ if ( key1 == key2 )
{
return 0;
}
- if ( value1 == null )
+ if ( key1 == null )
{
return 1;
}
- if ( value2 == null )
+ if ( key2 == null )
{
return -1;
}
- return btree.getComparator().compare( value1, value2 );
+ return btree.getComparator().compare( key1, key2 );
}
- /** STATIC INNER CLASS
+ /**
* Result from insert() method call. If the insertion has created
* a new page, it will be contained in the overflow field.
* If the inserted element already exist, then we will store
* the existing element.
*/
- interface InsertResult<K, V>
+ /* No qualifier */ interface InsertResult<K, V>
{
}
+ /**
+ * A inner class used to store a split page. It has a pivot element
+ * and a left and right page.
+ */
static class OverflowResult<K, V> implements InsertResult<K, V>
{
/** The Left page if it has been split, or the new page containing the new value */
@@ -793,6 +844,9 @@ public class Page<K, V> implements Clone
/** The Value that must be copied in the parent page if the page was full */
V pivotValue;
+ /**
+ * @see Object#toString()
+ */
public String toString()
{
// This is a split page
@@ -801,15 +855,27 @@ public class Page<K, V> implements Clone
}
}
+
+ /**
+ * An inner class used to store a modified page.
+ */
static class PageResult<K, V> implements InsertResult<K, V>
{
+ /** The modified page */
Page<K, V> page;
+ /**
+ * Create the instance of a PageResult
+ * @param page The modified page
+ */
private PageResult( Page<K, V> page )
{
this.page = page;
}
+ /**
+ * @see Object#toString()
+ */
public String toString()
{
return "Modified Page [" + page.recordId + ", r" + page.revision + "]";