Author: elecharny
Date: Sun Mar 17 08:18:37 2013
New Revision: 1457395
URL: http://svn.apache.org/r1457395
Log:
o Added the offset the AbstractPage toString() method
o Fixed the creation of a new node when the rootPage was previously a leaf
o Handled the insertion of pages in a Node, and written those pages on disk
There is still one case to handle : the split of a node when it's full.
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Node.java
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java?rev=1457395&r1=1457394&r2=1457395&view=diff
==============================================================================
---
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java
(original)
+++
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java
Sun Mar 17 08:18:37 2013
@@ -314,6 +314,11 @@ public abstract class AbstractPage<K, V>
sb.append( "r" ).append( revision );
sb.append( ", nbElems:" ).append( nbElems );
+ if ( offset > 0 )
+ {
+ sb.append( ", offset:" ).append( offset );
+ }
+
return sb.toString();
}
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java?rev=1457395&r1=1457394&r2=1457395&view=diff
==============================================================================
---
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
(original)
+++
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
Sun Mar 17 08:18:37 2013
@@ -1058,7 +1058,7 @@ public class BTree<K, V>
.setOffset( ( ( ReferenceHolder ) holderRight
).getOffset() );
// Create the new rootPage
- newRootPage = new Node<K, V>( this, revision, pivot, leftPage,
rightPage );
+ newRootPage = new Node<K, V>( this, revision, pivot,
holderLeft, holderRight );
}
else
{
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Node.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Node.java?rev=1457395&r1=1457394&r2=1457395&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Node.java
(original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Node.java
Sun Mar 17 08:18:37 2013
@@ -941,31 +941,56 @@ public class Node<K, V> extends Abstract
* @param rightPage The right child
* @param pos The position into the page
* @return The modified page with the <K,V> element added
+ * @throws IOException
*/
private InsertResult<K, V> insertChild( long revision, K key, Page<K, V>
leftPage, Page<K, V> rightPage, int pos )
+ throws IOException
{
// First copy the current page, but add one element in the copied page
Node<K, V> newNode = new Node<K, V>( btree, revision, nbElems + 1 );
- // Deal with the special case of an empty page
- if ( nbElems == 0 )
- {
- newNode.keys[0] = key;
- newNode.children[0] = btree.createHolder( leftPage );
- newNode.children[1] = btree.createHolder( rightPage );
- }
- else
+ // Copy the keys and the children up to the insertion position
+ if ( nbElems > 0 )
{
- // Copy the keys and the children up to the insertion position
System.arraycopy( keys, 0, newNode.keys, 0, pos );
System.arraycopy( children, 0, newNode.children, 0, pos );
+ }
+
+ // Add the new key and children
+ newNode.keys[pos] = key;
+
+ // If the BTree is managed, we now have to write the modified page on
disk
+ // and to add this page to the list of modified pages
+ if ( btree.isManaged() )
+ {
+ ElementHolder<Page<K, V>, K, V> holderLeft =
btree.getRecordManager().writePage( btree, this, leftPage,
+ revision );
+
+ // Store the offset on disk in the page in memory
+ ( ( AbstractPage<K, V> ) leftPage ).setOffset( ( (
ReferenceHolder<Page<K, V>, K, V> ) holderLeft )
+ .getOffset() );
- // Add the new key and children
- newNode.keys[pos] = key;
+ newNode.children[pos] = holderLeft;
+
+ ElementHolder<Page<K, V>, K, V> holderRight =
btree.getRecordManager().writePage( btree, this,
+ rightPage,
+ revision );
+
+ // Store the offset on disk in the page in memory
+ ( ( AbstractPage<K, V> ) rightPage ).setOffset( ( (
ReferenceHolder<Page<K, V>, K, V> ) holderRight )
+ .getOffset() );
+
+ newNode.children[pos + 1] = holderRight;
+ }
+ else
+ {
newNode.children[pos] = btree.createHolder( leftPage );
newNode.children[pos + 1] = btree.createHolder( rightPage );
+ }
- // And copy the remaining keys and children
+ // And copy the remaining keys and children
+ if ( nbElems > 0 )
+ {
System.arraycopy( keys, pos, newNode.keys, pos + 1, keys.length -
pos );
System.arraycopy( children, pos + 1, newNode.children, pos + 2,
children.length - pos - 1 );
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]