You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ka...@apache.org on 2013/04/01 19:31:04 UTC

svn commit: r1463214 - in /labs/mavibot/branches/mavibot-multivalue-support/mavibot/src: main/java/org/apache/mavibot/btree/ test/java/org/apache/mavibot/btree/

Author: kayyagari
Date: Mon Apr  1 17:31:04 2013
New Revision: 1463214

URL: http://svn.apache.org/r1463214
Log:
o fixed the hasKey() method in BTree
o added hasKey() method to Page interface
o made some Cursor class methods public
o added an assert for testing hasKey()

Modified:
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Cursor.java
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Leaf.java
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Node.java
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Page.java
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/InMemoryBTreeTest.java

Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java?rev=1463214&r1=1463213&r2=1463214&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java Mon Apr  1 17:31:04 2013
@@ -961,7 +961,7 @@ public class BTree<K, V>
             return false;
         }
         
-        return rootPage.findPos( key ) < 0;
+        return rootPage.hasKey( key );
     }
 
 

Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Cursor.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Cursor.java?rev=1463214&r1=1463213&r2=1463214&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Cursor.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Cursor.java Mon Apr  1 17:31:04 2013
@@ -38,7 +38,7 @@ import org.apache.mavibot.btree.exceptio
  * @param <K> The type for the Key
  * @param <V> The type for the stored value
  */
-/* No qualifier */class Cursor<K, V>
+public class Cursor<K, V>
 {
     /** The transaction used for this cursor */
     private Transaction<K, V> transaction;
@@ -77,7 +77,7 @@ import org.apache.mavibot.btree.exceptio
      * @throws IOException 
      * @throws EndOfFileExceededException 
      */
-    /* No qualifier */Tuple<K, V> next() throws EndOfFileExceededException, IOException
+    public Tuple<K, V> next() throws EndOfFileExceededException, IOException
     {
         ParentPos<K, V> parentPos = stack.getFirst();
 
@@ -258,7 +258,7 @@ import org.apache.mavibot.btree.exceptio
      * @throws IOException 
      * @throws EndOfFileExceededException 
      */
-    /* No qualifier */Tuple<K, V> prev() throws EndOfFileExceededException, IOException
+    public Tuple<K, V> prev() throws EndOfFileExceededException, IOException
     {
         ParentPos<K, V> parentPos = stack.peek();
 
@@ -330,7 +330,7 @@ import org.apache.mavibot.btree.exceptio
      * @throws IOException 
      * @throws EndOfFileExceededException 
      */
-    /* No qualifier */boolean hasNext() throws EndOfFileExceededException, IOException
+    public boolean hasNext() throws EndOfFileExceededException, IOException
     {
         ParentPos<K, V> parentPos = stack.peek();
 
@@ -365,7 +365,7 @@ import org.apache.mavibot.btree.exceptio
      * @throws IOException 
      * @throws EndOfFileExceededException 
      */
-    /* No qualifier */boolean hasPrev() throws EndOfFileExceededException, IOException
+    public boolean hasPrev() throws EndOfFileExceededException, IOException
     {
         ParentPos<K, V> parentPos = stack.peek();
 

Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Leaf.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Leaf.java?rev=1463214&r1=1463213&r2=1463214&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Leaf.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Leaf.java Mon Apr  1 17:31:04 2013
@@ -500,6 +500,22 @@ public class Leaf<K, V> extends Abstract
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasKey( K key )
+    {
+        int pos = findPos( key );
+
+        if ( pos < 0 )
+        {
+            return true;
+        }
+        
+        return false;
+    }
+
+
     @Override
     public boolean contains( K key, V value ) throws IOException
     {

Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Node.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Node.java?rev=1463214&r1=1463213&r2=1463214&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Node.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Node.java Mon Apr  1 17:31:04 2013
@@ -852,6 +852,27 @@ public class Node<K, V> extends Abstract
      * {@inheritDoc}
      */
     @Override
+    public boolean hasKey( K key ) throws IOException
+    {
+        int pos = findPos( key );
+
+        if ( pos < 0 )
+        {
+            // Here, if we have found the key in the node, then we must go down into
+            // the right child, not the left one
+            return children[-pos].getValue( btree ).hasKey( key );
+        }
+        else
+        {
+            return children[pos].getValue( btree ).hasKey( key );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public boolean contains( K key, V value ) throws IOException
     {
         int pos = findPos( key );

Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Page.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Page.java?rev=1463214&r1=1463213&r2=1463214&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Page.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/Page.java Mon Apr  1 17:31:04 2013
@@ -242,4 +242,13 @@ public interface Page<K, V>
      * @return The position in the page.
      */
     int findPos( K key );
+    
+    
+    /**
+     * Checks if the given key exists.
+     *  
+     * @param key The key we are looking at
+     * @return true if the key is present, false otherwise
+     */
+    boolean hasKey( K key ) throws IOException;
 }

Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/InMemoryBTreeTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/InMemoryBTreeTest.java?rev=1463214&r1=1463213&r2=1463214&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/InMemoryBTreeTest.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/InMemoryBTreeTest.java Mon Apr  1 17:31:04 2013
@@ -1024,6 +1024,7 @@ public class InMemoryBTreeTest
             assertNotNull( btree.get( i ) );
         }
         
+        assertTrue( btree.hasKey( 8 ) );
         assertFalse( btree.hasKey( 11 ) );
         
         Cursor<Integer, String> cursor = btree.browse( 11 );



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org