directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1528047 - in /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed: AbstractPage.java BTreeBuilder.java CursorImpl.java KeyHolder.java Leaf.java Node.java
Date Tue, 01 Oct 2013 11:41:01 GMT
Author: elecharny
Date: Tue Oct  1 11:41:01 2013
New Revision: 1528047

URL: http://svn.apache.org/r1528047
Log:
Added a KeyHolder to store the key or a reference if it's not yet deserialized

Added:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/KeyHolder.java
Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/AbstractPage.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTreeBuilder.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/CursorImpl.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Node.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/AbstractPage.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/AbstractPage.java?rev=1528047&r1=1528046&r2=1528047&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/AbstractPage.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/AbstractPage.java
Tue Oct  1 11:41:01 2013
@@ -42,7 +42,7 @@ import java.lang.reflect.Array;
     protected long revision;
 
     /** Keys of children nodes */
-    protected K[] keys;
+    protected KeyHolder<K>[] keys;
 
     /** The number of current values in the Page */
     protected int nbElems;
@@ -79,7 +79,7 @@ import java.lang.reflect.Array;
         // We get the type of array to create from the btree
         // Yes, this is an hack...
         Class<?> keyType = btree.getKeyType();
-        this.keys = ( K[] ) Array.newInstance( keyType, nbElems );
+        this.keys = ( KeyHolder[] ) Array.newInstance( KeyHolder.class, nbElems );
     }
 
 
@@ -186,7 +186,7 @@ import java.lang.reflect.Array;
         {
             int middle = ( min + max + 1 ) >> 1;
 
-            int comp = compare( keys[middle], key );
+            int comp = compare( keys[middle].getKey(), key );
 
             if ( comp < 0 )
             {
@@ -206,7 +206,7 @@ import java.lang.reflect.Array;
         }
 
         // Special case : we don't know if the key is present
-        int comp = compare( keys[max], key );
+        int comp = compare( keys[max].getKey(), key );
 
         if ( comp == 0 )
         {
@@ -271,7 +271,7 @@ import java.lang.reflect.Array;
     {
         if ( pos < nbElems )
         {
-            return keys[pos];
+            return keys[pos].getKey();
         }
         else
         {
@@ -288,7 +288,7 @@ import java.lang.reflect.Array;
      */
     /* No qualifier*/void setKey( int pos, K key )
     {
-        keys[pos] = key;
+        keys[pos] = new KeyHolder( key, null, btree.getKeySerializer() );
     }
 
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTreeBuilder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTreeBuilder.java?rev=1528047&r1=1528046&r2=1528047&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTreeBuilder.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTreeBuilder.java
Tue Oct  1 11:41:01 2013
@@ -21,7 +21,6 @@
 package org.apache.directory.mavibot.btree.managed;
 
 
-import org.apache.directory.mavibot.btree.Tuple;
 import static org.apache.directory.mavibot.btree.managed.BTreeFactory.createLeaf;
 import static org.apache.directory.mavibot.btree.managed.BTreeFactory.createNode;
 import static org.apache.directory.mavibot.btree.managed.BTreeFactory.setKey;
@@ -33,6 +32,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.directory.mavibot.btree.Tuple;
 import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
 
 
@@ -109,10 +109,10 @@ public class BTreeBuilder<K, V>
             {
                 int n = i;
                 lastLeaf.nbElems = n;
-                K[] keys = lastLeaf.keys;
+                KeyHolder<K>[] keys = lastLeaf.keys;
 
                 Class<?> keyType = btree.getKeyType();
-                lastLeaf.keys = ( K[] ) Array.newInstance( keyType, n );
+                lastLeaf.keys = ( KeyHolder[] ) Array.newInstance( keyType, n );
                 System.arraycopy( keys, 0, lastLeaf.keys, 0, n );
 
                 ElementHolder<V, K, V>[] values = lastLeaf.values;
@@ -177,10 +177,10 @@ public class BTreeBuilder<K, V>
             {
                 int n = j;
                 lastNode.nbElems = n;
-                K[] keys = lastNode.keys;
+                KeyHolder<K>[] keys = lastNode.keys;
 
                 Class<?> keyType = btree.getKeyType();
-                lastNode.keys = ( K[] ) Array.newInstance( keyType, n );
+                lastNode.keys = ( KeyHolder[] ) Array.newInstance( keyType, n );
                 System.arraycopy( keys, 0, lastNode.keys, 0, n );
 
                 break;

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/CursorImpl.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/CursorImpl.java?rev=1528047&r1=1528046&r2=1528047&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/CursorImpl.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/CursorImpl.java
Tue Oct  1 11:41:01 2013
@@ -122,7 +122,7 @@ public class CursorImpl<K, V> implements
         }
 
         Leaf<K, V> leaf = ( Leaf<K, V> ) ( parentPos.page );
-        tuple.setKey( leaf.keys[parentPos.pos] );
+        tuple.setKey( leaf.keys[parentPos.pos].getKey() );
 
         if ( allowDuplicates )
         {
@@ -336,7 +336,7 @@ public class CursorImpl<K, V> implements
 
                 if ( mvHolder.isSingleValue() )
                 {
-                    tuple.setKey( leaf.keys[parentPos.pos] );
+                    tuple.setKey( leaf.keys[parentPos.pos].getKey() );
                     tuple.setValue( mvHolder.getValue( btree ) );
                 }
                 else
@@ -372,7 +372,7 @@ public class CursorImpl<K, V> implements
                     parentPos.dupPos--;
                 }
 
-                tuple.setKey( leaf.keys[parentPos.pos] );
+                tuple.setKey( leaf.keys[parentPos.pos].getKey() );
                 if ( parentPos.dupsContainer != null )
                 {
                     tuple.setValue( parentPos.dupsContainer.rootPage.getKey( parentPos.dupPos
) );
@@ -386,7 +386,7 @@ public class CursorImpl<K, V> implements
         else
         {
             parentPos.pos--;
-            tuple.setKey( leaf.keys[parentPos.pos] );
+            tuple.setKey( leaf.keys[parentPos.pos].getKey() );
             tuple.setValue( leaf.values[parentPos.pos].getValue( btree ) );
         }
 

Added: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/KeyHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/KeyHolder.java?rev=1528047&view=auto
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/KeyHolder.java
(added)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/KeyHolder.java
Tue Oct  1 11:41:01 2013
@@ -0,0 +1,131 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.mavibot.btree.managed;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
+import org.apache.directory.mavibot.btree.util.Strings;
+
+
+/**
+ * A class storing either a key, or an offset to the key on the page's byte[]
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KeyHolder<K>
+{
+    /** The deserialized key */
+    private K key;
+
+    /** The ByteBuffer storing the key */
+    private ByteBuffer raw;
+
+    /** The Key serializer */
+    private ElementSerializer<K> keySerializer;
+
+
+    /* No Qualifier */KeyHolder( K key, ElementSerializer<K> keySerializer )
+    {
+        this.key = key;
+        this.keySerializer = keySerializer;
+        raw = ByteBuffer.wrap( keySerializer.serialize( key ) );
+    }
+
+
+    /* No Qualifier */KeyHolder( K key, ByteBuffer raw, ElementSerializer<K> keySerializer
)
+    {
+        this.key = key;
+        this.keySerializer = keySerializer;
+
+        if ( raw != null )
+        {
+            this.raw = raw;
+        }
+        else
+        {
+            raw = ByteBuffer.wrap( keySerializer.serialize( key ) );
+        }
+    }
+
+
+    /**
+     * @return the key
+     */
+    public K getKey()
+    {
+        if ( key == null )
+        {
+            try
+            {
+                key = keySerializer.deserialize( raw );
+            }
+            catch ( IOException ioe )
+            {
+                // Nothing we can do here...
+            }
+        }
+
+        return key;
+    }
+
+
+    /**
+     * @param key the Key to store in into the KeyHolder
+     */
+    public void setKey( K key )
+    {
+        this.key = key;
+        raw = ByteBuffer.wrap( keySerializer.serialize( key ) );
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( "KeyHolder[" );
+
+        if ( key == null )
+        {
+            if ( raw.isDirect() )
+            {
+                sb.append( "raw" );
+            }
+            else
+            {
+                Strings.dumpBytes( raw.array() );
+            }
+        }
+        else
+        {
+            sb.append( key );
+        }
+
+        sb.append( "]" );
+
+        return sb.toString();
+    }
+}

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java?rev=1528047&r1=1528046&r2=1528047&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java
Tue Oct  1 11:41:01 2013
@@ -166,7 +166,7 @@ import org.apache.directory.mavibot.btre
 
             if ( value == null ) // this is a case to delete entire <K,sub-BTree> or
<K,single-V>
             {
-                removedElement = new Tuple<K, V>( keys[index], existingVal ); // the
entire value was removed
+                removedElement = new Tuple<K, V>( keys[index].getKey(), existingVal
); // the entire value was removed
                 keyRemoved = true;
             }
             else
@@ -175,7 +175,7 @@ import org.apache.directory.mavibot.btre
                 {
                     if ( btree.getValueSerializer().compare( value, existingVal ) == 0 )
                     {
-                        removedElement = new Tuple<K, V>( keys[index], existingVal
); // the entire value was removed
+                        removedElement = new Tuple<K, V>( keys[index].getKey(), existingVal
); // the entire value was removed
                         keyRemoved = true;
                     }
                     else
@@ -205,7 +205,7 @@ import org.apache.directory.mavibot.btre
                             }
                         }
 
-                        removedElement = new Tuple<K, V>( keys[index], value ); //
we deleted only one value (even if it is from a tree of size 1)
+                        removedElement = new Tuple<K, V>( keys[index].getKey(), value
); // we deleted only one value (even if it is from a tree of size 1)
                     }
                     else
                     // value is not found
@@ -221,12 +221,12 @@ import org.apache.directory.mavibot.btre
 
             if ( ( ( existing == null ) && ( value == null ) ) || ( value == null
) )
             {
-                removedElement = new Tuple<K, V>( keys[index], existing );
+                removedElement = new Tuple<K, V>( keys[index].getKey(), existing );
                 keyRemoved = true;
             }
             else if ( btree.getValueSerializer().compare( value, existing ) == 0 )
             {
-                removedElement = new Tuple<K, V>( keys[index], value );
+                removedElement = new Tuple<K, V>( keys[index].getKey(), value );
                 keyRemoved = true;
             }
             else
@@ -405,7 +405,7 @@ import org.apache.directory.mavibot.btre
         throws IOException
     {
         // The sibling is on the left, borrow the rightmost element
-        K siblingKey = sibling.keys[sibling.getNbElems() - 1];
+        K siblingKey = sibling.keys[sibling.getNbElems() - 1].getKey();
         ElementHolder<V, K, V> siblingValue = sibling.values[sibling.getNbElems() -
1];
 
         // Create the new sibling, with one less element at the end
@@ -416,7 +416,7 @@ import org.apache.directory.mavibot.btre
         Leaf<K, V> newLeaf = new Leaf<K, V>( btree, revision, nbElems );
 
         // Insert the borrowed element
-        newLeaf.keys[0] = siblingKey;
+        newLeaf.keys[0] = new KeyHolder<K>( siblingKey, btree.getKeySerializer() );
         newLeaf.values[0] = siblingValue;
 
         // Copy the keys and the values up to the insertion position,
@@ -452,7 +452,7 @@ import org.apache.directory.mavibot.btre
         throws IOException
     {
         // The sibling is on the left, borrow the rightmost element
-        K siblingKey = sibling.keys[0];
+        K siblingKey = sibling.keys[0].getKey();
         ElementHolder<V, K, V> siblingHolder = sibling.values[0];
 
         // Create the new sibling
@@ -467,7 +467,7 @@ import org.apache.directory.mavibot.btre
         Leaf<K, V> newLeaf = new Leaf<K, V>( btree, revision, nbElems );
 
         // Insert the borrowed element at the end
-        newLeaf.keys[nbElems - 1] = siblingKey;
+        newLeaf.keys[nbElems - 1] = new KeyHolder<K>( siblingKey, btree.getKeySerializer()
);
         newLeaf.values[nbElems - 1] = siblingHolder;
 
         // Copy the keys and the values up to the deletion position,
@@ -868,7 +868,7 @@ import org.apache.directory.mavibot.btre
         // Deal with the special case of an empty page
         if ( nbElems == 0 )
         {
-            newLeaf.keys[0] = key;
+            newLeaf.keys[0] = new KeyHolder<K>( key, btree.getKeySerializer() );
 
             newLeaf.values[0] = valueHolder;
         }
@@ -879,7 +879,7 @@ import org.apache.directory.mavibot.btre
             System.arraycopy( values, 0, newLeaf.values, 0, pos );
 
             // Add the new element
-            newLeaf.keys[pos] = key;
+            newLeaf.keys[pos] = new KeyHolder<K>( key, btree.getKeySerializer() );
             newLeaf.values[pos] = valueHolder;
 
             // And copy the remaining elements
@@ -924,7 +924,7 @@ import org.apache.directory.mavibot.btre
             System.arraycopy( values, 0, leftLeaf.values, 0, pos );
 
             // Add the new element
-            leftLeaf.keys[pos] = key;
+            leftLeaf.keys[pos] = new KeyHolder<K>( key, btree.getKeySerializer() );
             leftLeaf.values[pos] = valueHolder;
 
             // And copy the remaining elements
@@ -957,7 +957,7 @@ import org.apache.directory.mavibot.btre
             System.arraycopy( values, middle, rightLeaf.values, 0, rightPos );
 
             // Add the new element
-            rightLeaf.keys[rightPos] = key;
+            rightLeaf.keys[rightPos] = new KeyHolder<K>( key, btree.getKeySerializer()
);
             rightLeaf.values[rightPos] = valueHolder;
 
             // And copy the remaining elements
@@ -966,7 +966,7 @@ import org.apache.directory.mavibot.btre
         }
 
         // Get the pivot
-        K pivot = rightLeaf.keys[0];
+        K pivot = rightLeaf.keys[0].getKey();
 
         // Create the result
         InsertResult<K, V> result = new SplitResult<K, V>( pivot, leftLeaf, rightLeaf
);
@@ -980,7 +980,7 @@ import org.apache.directory.mavibot.btre
      */
     public K getLeftMostKey()
     {
-        return keys[0];
+        return keys[0].getKey();
     }
 
 
@@ -989,7 +989,7 @@ import org.apache.directory.mavibot.btre
      */
     public K getRightMostKey()
     {
-        return keys[nbElems - 1];
+        return keys[nbElems - 1].getKey();
     }
 
 
@@ -1010,7 +1010,7 @@ import org.apache.directory.mavibot.btre
             val = values[0].getValue( btree );
         }
 
-        return new Tuple<K, V>( keys[0], val );
+        return new Tuple<K, V>( keys[0].getKey(), val );
     }
 
 
@@ -1031,7 +1031,7 @@ import org.apache.directory.mavibot.btre
             val = values[nbElems - 1].getValue( btree );
         }
 
-        return new Tuple<K, V>( keys[nbElems - 1], val );
+        return new Tuple<K, V>( keys[nbElems - 1].getKey(), val );
     }
 
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Node.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Node.java?rev=1528047&r1=1528046&r2=1528047&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Node.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Node.java
Tue Oct  1 11:41:01 2013
@@ -91,9 +91,9 @@ import org.apache.directory.mavibot.btre
         // We get the type of array to create from the btree
         // Yes, this is an hack...
         Class<?> keyType = btree.getKeyType();
-        keys = ( K[] ) Array.newInstance( keyType, btree.getPageSize() );
+        keys = ( KeyHolder[] ) Array.newInstance( keyType, btree.getPageSize() );
 
-        keys[0] = key;
+        keys[0] = new KeyHolder<K>( key, btree.getKeySerializer() );
     }
 
 
@@ -125,9 +125,9 @@ import org.apache.directory.mavibot.btre
         // We get the type of array to create from the btree
         // Yes, this is an hack...
         Class<?> keyType = btree.getKeyType();
-        keys = ( K[] ) Array.newInstance( keyType, btree.getPageSize() );
+        keys = ( KeyHolder[] ) Array.newInstance( KeyHolder.class, btree.getPageSize() );
 
-        keys[0] = key;
+        keys[0] = new KeyHolder( key, btree.getKeySerializer() );
     }
 
 
@@ -219,7 +219,7 @@ import org.apache.directory.mavibot.btre
 
         if ( pos < 0 )
         {
-            newPage.keys[index] = removeResult.getModifiedPage().getLeftMostKey();
+            newPage.keys[index].setKey( removeResult.getModifiedPage().getLeftMostKey() );
         }
 
         // Modify the result and return
@@ -295,7 +295,7 @@ import org.apache.directory.mavibot.btre
         int index = Math.abs( pos );
 
         // Copy the key and children from sibling
-        newNode.keys[nbElems - 1] = siblingKey; // 1
+        newNode.keys[nbElems - 1] = new KeyHolder<K>( siblingKey, btree.getKeySerializer()
); // 1
         newNode.children[nbElems] = sibling.children[0]; // 8
 
         if ( index < 2 )
@@ -319,7 +319,8 @@ import org.apache.directory.mavibot.btre
             }
 
             // Inject the new modified page key
-            newNode.keys[index - 2] = mergedResult.getModifiedPage().getLeftMostKey(); //
2
+            newNode.keys[index - 2] = new KeyHolder<K>( mergedResult.getModifiedPage().getLeftMostKey(),
+                btree.getKeySerializer() ); // 2
 
             if ( index < nbElems )
             {
@@ -384,7 +385,8 @@ import org.apache.directory.mavibot.btre
 
         if ( index < 2 )
         {
-            newNode.keys[0] = mergedResult.getModifiedPage().getLeftMostKey();
+            newNode.keys[0] = new KeyHolder<K>( mergedResult.getModifiedPage().getLeftMostKey(),
+                btree.getKeySerializer() );
             System.arraycopy( keys, 1, newNode.keys, 1, nbElems - 1 );
 
             Page<K, V> modifiedPage = mergedResult.getModifiedPage();
@@ -394,7 +396,8 @@ import org.apache.directory.mavibot.btre
         else
         {
             // Set the first key
-            newNode.keys[0] = children[0].getValue( btree ).getLeftMostKey(); //2
+            newNode.keys[0] = new KeyHolder<K>( children[0].getValue( btree ).getLeftMostKey(),
+                btree.getKeySerializer() ); //2
 
             if ( index > 2 )
             {
@@ -403,7 +406,8 @@ import org.apache.directory.mavibot.btre
             }
 
             // Inject the modified key
-            newNode.keys[index - 1] = mergedResult.getModifiedPage().getLeftMostKey(); //
3
+            newNode.keys[index - 1] = new KeyHolder<K>( mergedResult.getModifiedPage().getLeftMostKey(),
+                btree.getKeySerializer() ); // 3
 
             if ( index < nbElems )
             {
@@ -465,7 +469,8 @@ import org.apache.directory.mavibot.btre
             // Then copy all the elements up to the deletion point
             if ( index < 2 )
             {
-                newNode.keys[half] = mergedResult.getModifiedPage().getLeftMostKey();
+                newNode.keys[half] = new KeyHolder<K>( mergedResult.getModifiedPage().getLeftMostKey(),
+                    btree.getKeySerializer() );
                 System.arraycopy( keys, 1, newNode.keys, half + 1, half - 1 );
 
                 Page<K, V> modifiedPage = mergedResult.getModifiedPage();
@@ -476,7 +481,8 @@ import org.apache.directory.mavibot.btre
             {
                 // Copy the left part of the node keys up to the deletion point
                 // Insert the new key
-                newNode.keys[half] = children[0].getValue( btree ).getLeftMostKey(); // 3
+                newNode.keys[half] = new KeyHolder<K>( children[0].getValue( btree
).getLeftMostKey(),
+                    btree.getKeySerializer() ); // 3
 
                 if ( index > 2 )
                 {
@@ -484,7 +490,8 @@ import org.apache.directory.mavibot.btre
                 }
 
                 // Inject the new merged key
-                newNode.keys[half + index - 1] = mergedResult.getModifiedPage().getLeftMostKey();
//5
+                newNode.keys[half + index - 1] = new KeyHolder<K>( mergedResult.getModifiedPage().getLeftMostKey(),
+                    btree.getKeySerializer() ); //5
 
                 if ( index < half )
                 {
@@ -528,7 +535,8 @@ import org.apache.directory.mavibot.btre
                 System.arraycopy( children, 0, newNode.children, 0, index - 1 ); //6
 
                 // Inject the modified key
-                newNode.keys[index - 2] = mergedResult.getModifiedPage().getLeftMostKey();
//2
+                newNode.keys[index - 2] = new KeyHolder<K>( mergedResult.getModifiedPage().getLeftMostKey(),
+                    btree.getKeySerializer() ); //2
 
                 // Inject the modified children
                 Page<K, V> modifiedPage = mergedResult.getModifiedPage();
@@ -545,7 +553,7 @@ import org.apache.directory.mavibot.btre
             }
 
             // Inject the new key from sibling
-            newNode.keys[half - 1] = sibling.findLeftMost().getKey(); //3
+            newNode.keys[half - 1] = new KeyHolder<K>( sibling.findLeftMost().getKey(),
btree.getKeySerializer() ); //3
 
             // Copy the sibling keys
             System.arraycopy( sibling.keys, 0, newNode.keys, half, half );
@@ -710,8 +718,9 @@ import org.apache.directory.mavibot.btre
             if ( borrowedResult.isFromRight() )
             {
                 // Update the keys
-                newPage.keys[pos] = modifiedPage.findLeftMost().getKey();
-                newPage.keys[pos + 1] = modifiedSibling.findLeftMost().getKey();
+                newPage.keys[pos] = new KeyHolder<K>( modifiedPage.findLeftMost().getKey(),
btree.getKeySerializer() );
+                newPage.keys[pos + 1] = new KeyHolder<K>( modifiedSibling.findLeftMost().getKey(),
+                    btree.getKeySerializer() );
 
                 // Update the children
                 newPage.children[pos + 1] = createHolder( modifiedPage );
@@ -720,7 +729,7 @@ import org.apache.directory.mavibot.btre
             else
             {
                 // Update the keys
-                newPage.keys[pos] = modifiedPage.findLeftMost().getKey();
+                newPage.keys[pos] = new KeyHolder<K>( modifiedPage.findLeftMost().getKey(),
btree.getKeySerializer() );
 
                 // Update the children
                 newPage.children[pos] = createHolder( modifiedSibling );
@@ -732,7 +741,7 @@ import org.apache.directory.mavibot.btre
             if ( borrowedResult.isFromRight() )
             {
                 // Update the keys
-                newPage.keys[pos] = modifiedSibling.findLeftMost().getKey();
+                newPage.keys[pos] = new KeyHolder<K>( modifiedSibling.findLeftMost().getKey(),
btree.getKeySerializer() );
 
                 // Update the children
                 newPage.children[pos] = createHolder( modifiedPage );
@@ -741,7 +750,8 @@ import org.apache.directory.mavibot.btre
             else
             {
                 // Update the keys
-                newPage.keys[pos - 1] = modifiedPage.findLeftMost().getKey();
+                newPage.keys[pos - 1] = new KeyHolder<K>( modifiedPage.findLeftMost().getKey(),
+                    btree.getKeySerializer() );
 
                 // Update the children
                 newPage.children[pos - 1] = createHolder( modifiedSibling );
@@ -793,7 +803,8 @@ import org.apache.directory.mavibot.btre
                 System.arraycopy( keys, 0, newNode.keys, 0, index );
             }
 
-            newNode.keys[index] = mergedResult.getModifiedPage().findLeftMost().getKey();
+            newNode.keys[index] = new KeyHolder<K>( mergedResult.getModifiedPage().findLeftMost().getKey(),
+                btree.getKeySerializer() );
 
             if ( index < nbElems - 2 )
             {
@@ -1050,7 +1061,7 @@ import org.apache.directory.mavibot.btre
         }
 
         // Add the new key and children
-        newNode.keys[pos] = key;
+        newNode.keys[pos] = new KeyHolder<K>( key, btree.getKeySerializer() );
 
         // 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
@@ -1109,7 +1120,7 @@ import org.apache.directory.mavibot.btre
             System.arraycopy( children, 0, newLeftPage.children, 0, pos );
 
             // Add the new element
-            newLeftPage.keys[pos] = pivot;
+            newLeftPage.keys[pos] = new KeyHolder<K>( pivot, btree.getKeySerializer()
);
             newLeftPage.children[pos] = createHolder( leftPage );
             newLeftPage.children[pos + 1] = createHolder( rightPage );
 
@@ -1122,7 +1133,8 @@ import org.apache.directory.mavibot.btre
             System.arraycopy( children, middle, newRightPage.children, 0, middle + 1 );
 
             // Create the result
-            InsertResult<K, V> result = new SplitResult<K, V>( copiedPages, keys[middle
- 1], newLeftPage, newRightPage );
+            InsertResult<K, V> result = new SplitResult<K, V>( copiedPages, keys[middle
- 1].getKey(), newLeftPage,
+                newRightPage );
             result.addCopiedPage( this );
 
             return result;
@@ -1158,7 +1170,7 @@ import org.apache.directory.mavibot.btre
             System.arraycopy( children, middle + 1, newRightPage.children, 0, pos - middle
- 1 );
 
             // Add the new element
-            newRightPage.keys[pos - middle - 1] = pivot;
+            newRightPage.keys[pos - middle - 1] = new KeyHolder<K>( pivot, btree.getKeySerializer()
);
             newRightPage.children[pos - middle - 1] = createHolder( leftPage );
             newRightPage.children[pos - middle] = createHolder( rightPage );
 
@@ -1167,7 +1179,8 @@ import org.apache.directory.mavibot.btre
             System.arraycopy( children, pos + 1, newRightPage.children, pos + 1 - middle,
nbElems - pos );
 
             // Create the result
-            InsertResult<K, V> result = new SplitResult<K, V>( copiedPages, keys[middle],
newLeftPage, newRightPage );
+            InsertResult<K, V> result = new SplitResult<K, V>( copiedPages, keys[middle].getKey(),
newLeftPage,
+                newRightPage );
             result.addCopiedPage( this );
 
             return result;



Mime
View raw message