o Set the caseSize to DEFAULT_CACHE_SIZE if it's 0
authorEmmanuel Lécharny <elecharny@apache.org>
Wed, 4 Mar 2015 00:54:41 +0000 (00:54 +0000)
committerEmmanuel Lécharny <elecharny@apache.org>
Wed, 4 Mar 2015 00:54:41 +0000 (00:54 +0000)
o Suppressed some useless code in the browsefrom method

mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java
mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java

index 7e26432..785436e 100644 (file)
@@ -164,7 +164,7 @@ public class PersistedBTree<K, V> extends AbstractBTree<K, V> implements Closeab
 
             if ( cacheSize < 1 )
             {
-                cacheSize = 1;
+                cacheSize = DEFAULT_CACHE_SIZE;
             }
 
             cache = new LRUMap( cacheSize );
index 715a4a4..a6a0ed9 100644 (file)
@@ -842,27 +842,8 @@ import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 
                         return cursor;
                     }
-                    else
-                    {
-                        // go down the tree again, but one position to the right
-                        stack[stackIndex].pos++;
-
-                        for ( int i = stackIndex + 1; i < depth - 1; i++ )
-                        {
-                            ParentPos<K, V> parentPos = new ParentPos<K, V>( this, 0 );
-
-                            stack[i] = parentPos;
-                        }
 
-                        ParentPos<K, V> parentPos = new ParentPos<K, V>( this, 0 );
-
-                        // Create the value cursor
-                        parentPos.valueCursor = values[0].getCursor();
-
-                        stack[depth - 1] = parentPos;
-
-                        return cursor;
-                    }
+                    return cursor;
                 }
             }
         }
index ed70489..e26b8a3 100644 (file)
@@ -1180,6 +1180,8 @@ public class PersistedBTreeBrowseTest
         {
             btreeLong = recordManager1.addBTree( "testLong", LongSerializer.INSTANCE, LongSerializer.INSTANCE, true );
 
+            // Create a set of 500 values from 0 to 499, in a random order
+            // (all the values are there, they are just shuffled)
             int nbKeys = 500;
             List<Long> values = new ArrayList<Long>( nbKeys );
             long[] randomVals = new long[nbKeys];
@@ -1209,7 +1211,7 @@ public class PersistedBTreeBrowseTest
 
             int nbValues = 9;
 
-            // Inject some data
+            // Inject the 500 keys, each of them with 10 values
             for ( int i = 0; i < nbKeys; i++ )
             {
                 Long value = randomVals[i];
@@ -1222,11 +1224,12 @@ public class PersistedBTreeBrowseTest
 
             long t0 = System.currentTimeMillis();
 
-            // Now, browse the BTree starting from 0 to the end
+            // Now, browse the BTree fully, as many time as we have keys.
+            // We always browse from a different position, we should cover all
+            // the possible situations.
             for ( Long i = 0L; i < nbKeys; i++ )
             {
-                //System.out.println( "Browsing from " + i );
-                // Create the cursor
+                // Create the cursor, positionning it before the key
                 TupleCursor<Long, Long> cursor = btreeLong.browseFrom( i );
 
                 assertTrue( cursor.hasNext() );
@@ -1253,7 +1256,7 @@ public class PersistedBTreeBrowseTest
 
             long t00 = System.currentTimeMillis();
 
-            // Now, browse the BTree starting from 0 to the end
+            // Now, browse the BTree backward
             for ( Long i = nbKeys - 1L; i >= 0; i-- )
             {
                 // Create the cursor