directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1538151 - in /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed: Leaf.java Node.java RecordManager.java ValueHolder.java
Date Sat, 02 Nov 2013 08:32:17 GMT
Author: elecharny
Date: Sat Nov  2 08:32:17 2013
New Revision: 1538151

URL: http://svn.apache.org/r1538151
Log:
o Added a getKeyHolder method in Node, it's needed if we want to get the raw value
o A fix in the ValueHolder.hasNext() method : we were going one step too far in the elements
stored
o The ValueHolder.remove() method was growing the array used to store the element instead
of decrementing it

Modified:
    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
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java

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=1538151&r1=1538150&r2=1538151&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
Sat Nov  2 08:32:17 2013
@@ -160,15 +160,15 @@ import org.apache.directory.mavibot.btre
         {
             if ( valueHolder.contains( value ) )
             {
+
                 if ( valueHolder.size() == 1 )
                 {
-                    removedElement = new Tuple<K, V>( keys[index].getKey(), value );
// the entire value was removed
+                    removedElement = new Tuple<K, V>( keys[index].getKey(), null );
// the entire value was removed
                     keyRemoved = true;
                 }
                 else
                 {
-                    removedElement = new Tuple<K, V>( keys[index].getKey(), value );
// the entire value was removed
-
+                    removedElement = new Tuple<K, V>( keys[index].getKey(), value );
// only one value was removed
                     valueHolder.remove( value );
                 }
             }
@@ -871,6 +871,11 @@ import org.apache.directory.mavibot.btre
         // Get the pivot
         K pivot = rightLeaf.keys[0].getKey();
 
+        if ( pivot == null )
+        {
+            pivot = rightLeaf.keys[0].getKey();
+        }
+
         // Create the result
         InsertResult<K, V> result = new SplitResult<K, V>( pivot, leftLeaf, rightLeaf
);
 

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=1538151&r1=1538150&r2=1538151&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
Sat Nov  2 08:32:17 2013
@@ -833,6 +833,22 @@ import org.apache.directory.mavibot.btre
     /**
      * {@inheritDoc}
      */
+    /* No qualifier */KeyHolder<K> getKeyHolder( int pos )
+    {
+        if ( pos < nbElems )
+        {
+            return keys[pos];
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public V get( K key ) throws IOException, KeyNotFoundException
     {
         int pos = findPos( key );
@@ -1129,7 +1145,14 @@ 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].getKey(), newLeftPage,
+            pivot = keys[middle - 1].getKey();
+
+            if ( pivot == null )
+            {
+                pivot = keys[middle - 1].getKey();
+            }
+
+            InsertResult<K, V> result = new SplitResult<K, V>( copiedPages, pivot,
newLeftPage,
                 newRightPage );
             result.addCopiedPage( this );
 
@@ -1175,7 +1198,14 @@ 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].getKey(),
newLeftPage,
+            pivot = keys[middle].getKey();
+
+            if ( pivot == null )
+            {
+                pivot = keys[middle].getKey();
+            }
+
+            InsertResult<K, V> result = new SplitResult<K, V>( copiedPages, pivot,
newLeftPage,
                 newRightPage );
             result.addCopiedPage( this );
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java?rev=1538151&r1=1538150&r2=1538151&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java
Sat Nov  2 08:32:17 2013
@@ -1245,7 +1245,8 @@ public class RecordManager
      */
     private <K, V> int serializeNodeKey( Node<K, V> node, int pos, List<byte[]>
serializedData )
     {
-        byte[] buffer = node.btree.getKeySerializer().serialize( node.getKey( pos ) );
+        KeyHolder<K> holder = node.getKeyHolder( pos );
+        byte[] buffer = holder.getBuffer();
         serializedData.add( buffer );
 
         return buffer.length;

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java?rev=1538151&r1=1538150&r2=1538151&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java
Sat Nov  2 08:32:17 2013
@@ -31,7 +31,6 @@ import org.apache.directory.mavibot.btre
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
 import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
 import org.apache.directory.mavibot.btree.serializer.IntSerializer;
-import org.apache.directory.mavibot.btree.util.Strings;
 
 
 /**
@@ -247,7 +246,7 @@ public class ValueHolder<V> implements C
             }
             else
             {
-                return ( valueArray != null ) && ( currentPos < valueArray.length
);
+                return ( valueArray != null ) && ( currentPos < valueArray.length
- 1 );
             }
         }
 
@@ -756,7 +755,7 @@ public class ValueHolder<V> implements C
 
             // Ok, we just have to delete the new element at the right position
             // First, copy the array
-            V[] newValueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), valueArray.length
+ 1 );
+            V[] newValueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), valueArray.length
- 1 );
 
             System.arraycopy( valueArray, 0, newValueArray, 0, pos );
             System.arraycopy( valueArray, pos + 1, newValueArray, pos, valueArray.length
- pos - 1 );
@@ -987,13 +986,14 @@ public class ValueHolder<V> implements C
                     {
                         int size = IntSerializer.deserialize( raw, pos );
                         pos += 4;
+
                         V value = valueSerializer.fromBytes( raw, pos );
                         pos += size;
                         valueArray[index++] = value;
                     }
                     catch ( IOException e )
                     {
-                        System.out.println( Strings.dumpBytes( raw ) );
+                        e.printStackTrace();
                     }
                 }
             }



Mime
View raw message