directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1551277 - in /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree: AbstractPage.java memory/Node.java persisted/Node.java
Date Mon, 16 Dec 2013 17:36:33 GMT
Author: elecharny
Date: Mon Dec 16 17:36:33 2013
New Revision: 1551277

URL: http://svn.apache.org/r1551277
Log:
Moved many methods from the in-memory and persisted Node into the AbstractPage class

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java?rev=1551277&r1=1551276&r2=1551277&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java
Mon Dec 16 17:36:33 2013
@@ -25,6 +25,7 @@ import java.lang.reflect.Array;
 
 import org.apache.directory.mavibot.btree.KeyHolder;
 import org.apache.directory.mavibot.btree.Page;
+import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 
 
@@ -116,6 +117,113 @@ public abstract class AbstractPage<K, V>
             return null;
         }
     }
+    
+    
+    /**
+     * {@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().hasKey( key );
+        }
+        else
+        {
+            Page<K, V> page = children[pos].getValue();
+
+            if ( page == null )
+            {
+                System.out.println( "Page is null for pos = " + pos + ", children = " + children[pos]
);
+            }
+
+            return page.hasKey( key );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Page<K, V> getReference( int pos ) throws IOException
+    {
+        if ( pos < nbElems + 1 )
+        {
+            return children[pos].getValue();
+        }
+        else
+        {
+            return null;
+        }
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public TupleCursor<K, V> browse( K key, Transaction<K, V> transaction, ParentPos<K,
V>[] stack, int depth )
+        throws IOException
+    {
+        int pos = findPos( key );
+
+        if ( pos < 0 )
+        {
+            pos = -pos;
+        }
+
+        // We first stack the current page
+        stack[depth++] = new ParentPos<K, V>( this, pos );
+        
+        Page<K, V> page = children[pos].getValue();
+
+        return page.browse( key, transaction, stack, depth );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean contains( K key, V value ) 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().contains( key, value );
+        }
+        else
+        {
+            return children[pos].getValue().contains( key, value );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public V get( K key ) throws IOException, KeyNotFoundException
+    {
+        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().get( key );
+        }
+        else
+        {
+            return children[pos].getValue().get( key );
+        }
+    }
 
     
     /**
@@ -147,6 +255,41 @@ public abstract class AbstractPage<K, V>
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public ValueCursor<V> getValues( K key ) throws KeyNotFoundException, IOException,
IllegalArgumentException
+    {
+        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().getValues( key );
+        }
+        else
+        {
+            return children[pos].getValue().getValues( key );
+        }
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public TupleCursor<K, V> browse( Transaction<K, V> transaction, ParentPos<K,
V>[] stack, int depth )
+        throws IOException
+    {
+        stack[depth++] = new ParentPos<K, V>( this, 0 );
+        
+        Page<K, V> page = children[0].getValue();
+    
+        return page.browse( transaction, stack, depth );
+    }
+
+
+    /**
      * Selects the sibling (the previous or next page with the same parent) which has
      * the more element assuming it's above N/2
      * 
@@ -422,6 +565,24 @@ public abstract class AbstractPage<K, V>
 
 
     /**
+     * {@inheritDoc}
+     */
+    public Tuple<K, V> findLeftMost() throws EndOfFileExceededException, IOException
+    {
+        return children[0].getValue().findLeftMost();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Tuple<K, V> findRightMost() throws EndOfFileExceededException, IOException
+    {
+        return children[nbElems].getValue().findRightMost();
+    }
+
+
+    /**
      * @return the btree
      */
     public BTree<K, V> getBtree()
@@ -435,10 +596,26 @@ public abstract class AbstractPage<K, V>
      */
     public String dumpPage( String tabs )
     {
-        return "";
-    }
+        StringBuilder sb = new StringBuilder();
+
+        if ( nbElems > 0 )
+        {
+            // Start with the first child
+            sb.append( children[0].getValue().dumpPage( tabs + "    " ) );
 
+            for ( int i = 0; i < nbElems; i++ )
+            {
+                sb.append( tabs );
+                sb.append( "<" );
+                sb.append( getKey( i ) ).append( ">\n" );
+                sb.append( children[i + 1].getValue().dumpPage( tabs + "    " ) );
+            }
+        }
 
+        return sb.toString();
+    }
+
+    
     /**
      * @see Object#toString()
      */

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java?rev=1551277&r1=1551276&r2=1551277&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java
Mon Dec 16 17:36:33 2013
@@ -36,15 +36,9 @@ import org.apache.directory.mavibot.btre
 import org.apache.directory.mavibot.btree.NotPresentResult;
 import org.apache.directory.mavibot.btree.Page;
 import org.apache.directory.mavibot.btree.PageHolder;
-import org.apache.directory.mavibot.btree.ParentPos;
 import org.apache.directory.mavibot.btree.RemoveResult;
 import org.apache.directory.mavibot.btree.SplitResult;
-import org.apache.directory.mavibot.btree.Transaction;
 import org.apache.directory.mavibot.btree.Tuple;
-import org.apache.directory.mavibot.btree.TupleCursor;
-import org.apache.directory.mavibot.btree.ValueCursor;
-import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
-import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 
 
 /**
@@ -578,7 +572,7 @@ import org.apache.directory.mavibot.btre
         // If we just modified the child, return a modified page
         if ( deleteResult instanceof RemoveResult )
         {
-            RemoveResult<K, V> removeResult = handleRemoveResult( (org.apache.directory.mavibot.btree.RemoveResult<K,
V> ) deleteResult, index, pos,
+            RemoveResult<K, V> removeResult = handleRemoveResult( (RemoveResult<K,
V> ) deleteResult, index, pos,
                 found );
 
             return removeResult;
@@ -800,96 +794,6 @@ import org.apache.directory.mavibot.btre
 
 
     /**
-     * {@inheritDoc}
-     */
-    public V get( K key ) throws IOException, KeyNotFoundException
-    {
-        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().get( key );
-        }
-        else
-        {
-            return children[pos].getValue().get( key );
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public ValueCursor<V> getValues( K key ) throws KeyNotFoundException, IOException,
IllegalArgumentException
-    {
-        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().getValues( key );
-        }
-        else
-        {
-            return children[pos].getValue().getValues( key );
-        }
-    }
-
-
-    /**
-     * {@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().hasKey( key );
-        }
-        else
-        {
-            Page<K, V> page = children[pos].getValue();
-
-            if ( page == null )
-            {
-                System.out.println( "Page is null for pos = " + pos + ", children = " + children[pos]
);
-            }
-
-            return page.hasKey( key );
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean contains( K key, V value ) 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().contains( key, value );
-        }
-        else
-        {
-            return children[pos].getValue().contains( key, value );
-        }
-    }
-
-
-    /**
      * Set the value at a give position
      * 
      * @param pos The position in the values array
@@ -902,58 +806,6 @@ import org.apache.directory.mavibot.btre
 
 
     /**
-     * {@inheritDoc}
-     */
-    public Page<K, V> getReference( int pos ) throws IOException
-    {
-        if ( pos < nbElems + 1 )
-        {
-            return children[pos].getValue();
-        }
-        else
-        {
-            return null;
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public TupleCursor<K, V> browse( K key, Transaction<K, V> transaction, ParentPos<K,
V>[] stack, int depth )
-        throws IOException
-    {
-        int pos = findPos( key );
-
-        if ( pos < 0 )
-        {
-            pos = -pos;
-        }
-
-        // We first stack the current page
-        stack[depth++] = new ParentPos<K, V>( this, pos );
-        
-        Page<K, V> page = children[pos].getValue();
-
-        return page.browse( key, transaction, stack, depth );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public TupleCursor<K, V> browse( Transaction<K, V> transaction, ParentPos<K,
V>[] stack, int depth )
-        throws IOException
-    {
-        stack[depth++] = new ParentPos<K, V>( this, 0 );
-        
-        Page<K, V> page = children[0].getValue();
-
-        return page.browse( transaction, stack, depth );
-    }
-
-
-    /**
      * This method is used when we have to replace a child in a page when we have
      * found the key in the tree (the value will be changed, so we have made
      * copies of the existing pages).
@@ -1184,24 +1036,6 @@ import org.apache.directory.mavibot.btre
 
 
     /**
-     * {@inheritDoc}
-     */
-    public Tuple<K, V> findLeftMost() throws EndOfFileExceededException, IOException
-    {
-        return children[0].getValue().findLeftMost();
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public Tuple<K, V> findRightMost() throws EndOfFileExceededException, IOException
-    {
-        return children[nbElems].getValue().findRightMost();
-    }
-
-
-    /**
      * @see Object#toString()
      */
     public String toString()
@@ -1243,29 +1077,4 @@ import org.apache.directory.mavibot.btre
 
         return sb.toString();
     }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public String dumpPage( String tabs )
-    {
-        StringBuilder sb = new StringBuilder();
-
-        if ( nbElems > 0 )
-        {
-            // Start with the first child
-            sb.append( children[0].getValue().dumpPage( tabs + "    " ) );
-
-            for ( int i = 0; i < nbElems; i++ )
-            {
-                sb.append( tabs );
-                sb.append( "<" );
-                sb.append( getKey( i ) ).append( ">\n" );
-                sb.append( children[i + 1].getValue().dumpPage( tabs + "    " ) );
-            }
-        }
-
-        return sb.toString();
-    }
 }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java?rev=1551277&r1=1551276&r2=1551277&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java
Mon Dec 16 17:36:33 2013
@@ -35,16 +35,9 @@ import org.apache.directory.mavibot.btre
 import org.apache.directory.mavibot.btree.ModifyResult;
 import org.apache.directory.mavibot.btree.NotPresentResult;
 import org.apache.directory.mavibot.btree.Page;
-import org.apache.directory.mavibot.btree.ParentPos;
 import org.apache.directory.mavibot.btree.RemoveResult;
 import org.apache.directory.mavibot.btree.SplitResult;
-import org.apache.directory.mavibot.btree.Transaction;
 import org.apache.directory.mavibot.btree.Tuple;
-import org.apache.directory.mavibot.btree.TupleCursor;
-import org.apache.directory.mavibot.btree.ValueCursor;
-import org.apache.directory.mavibot.btree.ValueHolder;
-import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
-import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 
 
 /**
@@ -628,7 +621,7 @@ import org.apache.directory.mavibot.btre
         // the current page
         if ( deleteResult instanceof BorrowedFromSiblingResult )
         {
-            RemoveResult<K, V> removeResult = handleBorrowedResult( (org.apache.directory.mavibot.btree.BorrowedFromSiblingResult<K,
V> ) deleteResult,
+            RemoveResult<K, V> removeResult = handleBorrowedResult( (BorrowedFromSiblingResult<K,
V> ) deleteResult,
                 pos );
 
             return removeResult;
@@ -859,96 +852,6 @@ import org.apache.directory.mavibot.btre
 
 
     /**
-     * {@inheritDoc}
-     */
-    public V get( K key ) throws IOException, KeyNotFoundException
-    {
-        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().get( key );
-        }
-        else
-        {
-            return children[pos].getValue().get( key );
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public ValueCursor<V> getValues( K key ) throws KeyNotFoundException, IOException,
IllegalArgumentException
-    {
-        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().getValues( key );
-        }
-        else
-        {
-            return children[pos].getValue().getValues( key );
-        }
-    }
-
-
-    /**
-     * {@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().hasKey( key );
-        }
-        else
-        {
-            Page<K, V> page = children[pos].getValue();
-
-            if ( page == null )
-            {
-                System.out.println( "Page is null for pos = " + pos + ", children = " + children[pos]
);
-            }
-
-            return page.hasKey( key );
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean contains( K key, V value ) 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().contains( key, value );
-        }
-        else
-        {
-            return children[pos].getValue().contains( key, value );
-        }
-    }
-
-
-    /**
      * Set the value at a give position
      * 
      * @param pos The position in the values array
@@ -961,58 +864,6 @@ import org.apache.directory.mavibot.btre
 
 
     /**
-     * {@inheritDoc}
-     */
-    public Page<K, V> getReference( int pos ) throws IOException
-    {
-        if ( pos < nbElems + 1 )
-        {
-            return children[pos].getValue();
-        }
-        else
-        {
-            return null;
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public TupleCursor<K, V> browse( K key, Transaction<K, V> transaction, ParentPos<K,
V>[] stack, int depth )
-        throws IOException
-    {
-        int pos = findPos( key );
-
-        if ( pos < 0 )
-        {
-            pos = -pos;
-        }
-
-        // We first stack the current page
-        stack[depth++] = new ParentPos<K, V>( this, pos );
-        
-        Page<K, V> page = children[pos].getValue();
-
-        return page.browse( key, transaction, stack, depth );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public TupleCursor<K, V> browse( Transaction<K, V> transaction, ParentPos<K,
V>[] stack, int depth )
-        throws IOException
-    {
-        stack[depth++] = new ParentPos<K, V>( this, 0 );
-        
-        Page<K, V> page = children[0].getValue();
-
-        return page.browse( transaction, stack, depth );
-    }
-
-
-    /**
      * This method is used when we have to replace a child in a page when we have
      * found the key in the tree (the value will be changed, so we have made
      * copies of the existing pages).
@@ -1276,24 +1127,6 @@ import org.apache.directory.mavibot.btre
 
 
     /**
-     * {@inheritDoc}
-     */
-    public Tuple<K, V> findLeftMost() throws EndOfFileExceededException, IOException
-    {
-        return children[0].getValue().findLeftMost();
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public Tuple<K, V> findRightMost() throws EndOfFileExceededException, IOException
-    {
-        return children[nbElems].getValue().findRightMost();
-    }
-
-
-    /**
      * @see Object#toString()
      */
     public String toString()
@@ -1335,29 +1168,4 @@ import org.apache.directory.mavibot.btre
 
         return sb.toString();
     }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public String dumpPage( String tabs )
-    {
-        StringBuilder sb = new StringBuilder();
-
-        if ( nbElems > 0 )
-        {
-            // Start with the first child
-            sb.append( children[0].getValue().dumpPage( tabs + "    " ) );
-
-            for ( int i = 0; i < nbElems; i++ )
-            {
-                sb.append( tabs );
-                sb.append( "<" );
-                sb.append( keys[i] ).append( ">\n" );
-                sb.append( children[i + 1].getValue().dumpPage( tabs + "    " ) );
-            }
-        }
-
-        return sb.toString();
-    }
 }



Mime
View raw message