You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2013/12/16 15:36:39 UTC
svn commit: r1551216 - in
/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree:
AbstractPage.java AbstractTupleCursor.java memory/TupleCursorImpl.java
persisted/Node.java persisted/TupleCursorImpl.java
Author: elecharny
Date: Mon Dec 16 14:36:38 2013
New Revision: 1551216
URL: http://svn.apache.org/r1551216
Log:
o Moved the afterLast and beforeFirst methods down to the AbstractTupleCursor class
o Added the getValue( pos ) method in AbstractPage
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/AbstractTupleCursor.java
directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java
directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java
directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/TupleCursorImpl.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=1551216&r1=1551215&r2=1551216&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 14:36:38 2013
@@ -273,6 +273,16 @@ public abstract class AbstractPage<K, V>
/**
+ * {@inheritDoc}
+ */
+ public ValueHolder<V> getValue( int pos )
+ {
+ // Node don't have values. Leaf.getValue() will return the value
+ return null;
+ }
+
+
+ /**
* @return the revision
*/
public long getRevision()
Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTupleCursor.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTupleCursor.java?rev=1551216&r1=1551215&r2=1551216&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTupleCursor.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTupleCursor.java Mon Dec 16 14:36:38 2013
@@ -19,6 +19,9 @@
*/
package org.apache.directory.mavibot.btree;
+import java.io.IOException;
+
+
/**
* A Cursor is used to fetch elements in a BTree and is returned by the
* @see BTree#browse method. The cursor <strng>must</strong> be closed
@@ -61,6 +64,99 @@ public abstract class AbstractTupleCurso
/**
* {@inheritDoc}
*/
+ public void afterLast() throws IOException
+ {
+ // First check that we have elements in the BTree
+ if ( ( stack == null ) || ( stack.length == 0 ) )
+ {
+ return;
+ }
+
+ Page<K, V> child = null;
+
+ for ( int i = 0; i < depth; i++ )
+ {
+ ParentPos<K, V> parentPos = stack[i];
+
+ if ( child != null )
+ {
+ parentPos.page = child;
+ parentPos.pos = child.getNbElems();
+ }
+ else
+ {
+ // We have N+1 children if the page is a Node, so we don't decrement the nbElems field
+ parentPos.pos = parentPos.page.getNbElems();
+ }
+
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.pos );
+ }
+
+ // and leaf
+ ParentPos<K, V> parentPos = stack[depth];
+
+ if ( child == null )
+ {
+ parentPos.pos = parentPos.page.getNbElems() - 1;
+ }
+ else
+ {
+ parentPos.page = child;
+ parentPos.pos = child.getNbElems() - 1;
+ }
+
+ parentPos.valueCursor = ((AbstractPage<K, V>)parentPos.page).getValue( parentPos.pos ).getCursor();
+ parentPos.valueCursor.afterLast();
+ parentPos.pos = AFTER_LAST;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void beforeFirst() throws IOException
+ {
+ // First check that we have elements in the BTree
+ if ( ( stack == null ) || ( stack.length == 0 ) )
+ {
+ return;
+ }
+
+ Page<K, V> child = null;
+
+ for ( int i = 0; i < depth; i++ )
+ {
+ ParentPos<K, V> parentPos = stack[i];
+ parentPos.pos = 0;
+
+ if ( child != null )
+ {
+ parentPos.page = child;
+ }
+
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( 0 );
+ }
+
+ // and leaf
+ ParentPos<K, V> parentPos = stack[depth];
+ parentPos.pos = BEFORE_FIRST;
+
+ if ( child != null )
+ {
+ parentPos.page = child;
+ }
+
+ if ( parentPos.valueCursor != null )
+ {
+ parentPos.valueCursor = ((AbstractPage<K, V>)parentPos.page).getValue( 0 ).getCursor();
+ parentPos.valueCursor.beforeFirst();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
public void close()
{
transaction.close();
Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java?rev=1551216&r1=1551215&r2=1551216&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java Mon Dec 16 14:36:38 2013
@@ -23,6 +23,7 @@ package org.apache.directory.mavibot.btr
import java.io.IOException;
import java.util.NoSuchElementException;
+import org.apache.directory.mavibot.btree.AbstractPage;
import org.apache.directory.mavibot.btree.AbstractTupleCursor;
import org.apache.directory.mavibot.btree.BTree;
import org.apache.directory.mavibot.btree.Page;
@@ -59,99 +60,6 @@ public class TupleCursorImpl<K, V> exten
/**
- * {@inheritDoc}
- */
- public void afterLast() throws IOException
- {
- // First check that we have elements in the BTree
- if ( ( stack == null ) || ( stack.length == 0 ) )
- {
- return;
- }
-
- Page<K, V> child = null;
-
- for ( int i = 0; i < depth; i++ )
- {
- ParentPos<K, V> parentPos = stack[i];
-
- if ( child != null )
- {
- parentPos.page = child;
- parentPos.pos = child.getNbElems();
- }
- else
- {
- // We have N+1 children if the page is a Node, so we don't decrement the nbElems field
- parentPos.pos = parentPos.page.getNbElems();
- }
-
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.pos );
- }
-
- // and leaf
- ParentPos<K, V> parentPos = stack[depth];
-
- if ( child == null )
- {
- parentPos.pos = parentPos.page.getNbElems() - 1;
- }
- else
- {
- parentPos.page = child;
- parentPos.pos = child.getNbElems() - 1;
- }
-
- parentPos.valueCursor = ((InMemoryLeaf<K, V>)parentPos.page).values[parentPos.pos].getCursor();
- parentPos.valueCursor.afterLast();
- parentPos.pos = AFTER_LAST;
- }
-
-
- /**
- * {@inheritDoc}
- */
- public void beforeFirst() throws IOException
- {
- // First check that we have elements in the BTree
- if ( ( stack == null ) || ( stack.length == 0 ) )
- {
- return;
- }
-
- Page<K, V> child = null;
-
- for ( int i = 0; i < depth; i++ )
- {
- ParentPos<K, V> parentPos = stack[i];
- parentPos.pos = 0;
-
- if ( child != null )
- {
- parentPos.page = child;
- }
-
- child = ((Node<K, V>)parentPos.page).getPage( 0 );
- }
-
- // and leaf
- ParentPos<K, V> parentPos = stack[depth];
- parentPos.pos = BEFORE_FIRST;
-
- if ( child != null )
- {
- parentPos.page = child;
- }
-
- if ( parentPos.valueCursor != null )
- {
- parentPos.valueCursor = ((InMemoryLeaf<K, V>)parentPos.page).values[0].getCursor();
- parentPos.valueCursor.beforeFirst();
- }
- }
-
-
- /**
* Find the leaf containing the following elements.
*
* @return the new ParentPos instance, or null if we have no following leaf
@@ -185,7 +93,7 @@ public class TupleCursorImpl<K, V> exten
{
// We can pick the next element at this level
parentPos.pos++;
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.pos );
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.pos );
// and go down the tree through the nodes
while ( currentDepth < depth - 1 )
@@ -194,7 +102,7 @@ public class TupleCursorImpl<K, V> exten
parentPos = stack[currentDepth];
parentPos.pos = 0;
parentPos.page = child;
- child = ((Node<K, V>)child).getPage( 0 );
+ child = ((AbstractPage<K, V>)child).getPage( 0 );
}
// and the leaf
@@ -245,7 +153,7 @@ public class TupleCursorImpl<K, V> exten
{
// We can pick the next element at this level
parentPos.pos--;
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.pos );
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.pos );
// and go down the tree through the nodes
while ( currentDepth < depth - 1 )
@@ -254,7 +162,7 @@ public class TupleCursorImpl<K, V> exten
parentPos = stack[currentDepth];
parentPos.pos = child.getNbElems();
parentPos.page = child;
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.page.getNbElems() );
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.page.getNbElems() );
}
// and the leaf
@@ -402,13 +310,13 @@ public class TupleCursorImpl<K, V> exten
else
{
// We can pick the next element at this level
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.pos + 1 );
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.pos + 1 );
// and go down the tree through the nodes
while ( currentDepth < depth - 1 )
{
currentDepth++;
- child = ((Node<K, V>)child).getPage( 0 );
+ child = ((AbstractPage<K, V>)child).getPage( 0 );
}
return true;
@@ -548,13 +456,13 @@ public class TupleCursorImpl<K, V> exten
else
{
// We can pick the previous element at this level
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.pos - 1 );
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.pos - 1 );
// and go down the tree through the nodes
while ( currentDepth < depth - 1 )
{
currentDepth++;
- child = ((Node<K, V>)child).getPage( child.getNbElems() );
+ child = ((AbstractPage<K, V>)child).getPage( child.getNbElems() );
}
return true;
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=1551216&r1=1551215&r2=1551216&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 14:36:38 2013
@@ -42,6 +42,7 @@ import org.apache.directory.mavibot.btre
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;
Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/TupleCursorImpl.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/TupleCursorImpl.java?rev=1551216&r1=1551215&r2=1551216&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/TupleCursorImpl.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/TupleCursorImpl.java Mon Dec 16 14:36:38 2013
@@ -23,6 +23,7 @@ package org.apache.directory.mavibot.btr
import java.io.IOException;
import java.util.NoSuchElementException;
+import org.apache.directory.mavibot.btree.AbstractPage;
import org.apache.directory.mavibot.btree.AbstractTupleCursor;
import org.apache.directory.mavibot.btree.BTree;
import org.apache.directory.mavibot.btree.Page;
@@ -183,7 +184,7 @@ public class TupleCursorImpl<K, V> exten
{
// We can pick the next element at this level
parentPos.pos++;
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.pos );
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.pos );
// and go down the tree through the nodes
while ( currentDepth < depth - 1 )
@@ -192,7 +193,7 @@ public class TupleCursorImpl<K, V> exten
parentPos = stack[currentDepth];
parentPos.pos = 0;
parentPos.page = child;
- child = ((Node<K, V>)child).getPage( 0 );
+ child = ((AbstractPage<K, V>)child).getPage( 0 );
}
// and the leaf
@@ -242,13 +243,13 @@ public class TupleCursorImpl<K, V> exten
else
{
// We can pick the next element at this level
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.pos + 1 );
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.pos + 1 );
// and go down the tree through the nodes
while ( currentDepth < depth - 1 )
{
currentDepth++;
- child = ((Node<K, V>)child).getPage( 0 );
+ child = ((AbstractPage<K, V>)child).getPage( 0 );
}
return true;
@@ -292,13 +293,13 @@ public class TupleCursorImpl<K, V> exten
else
{
// We can pick the previous element at this level
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.pos - 1 );
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.pos - 1 );
// and go down the tree through the nodes
while ( currentDepth < depth - 1 )
{
currentDepth++;
- child = ((Node<K, V>)child).getPage( child.getNbElems() );
+ child = ((AbstractPage<K, V>)child).getPage( child.getNbElems() );
}
return true;
@@ -343,7 +344,7 @@ public class TupleCursorImpl<K, V> exten
{
// We can pick the next element at this level
parentPos.pos--;
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.pos );
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.pos );
// and go down the tree through the nodes
while ( currentDepth < depth - 1 )
@@ -352,7 +353,7 @@ public class TupleCursorImpl<K, V> exten
parentPos = stack[currentDepth];
parentPos.pos = child.getNbElems();
parentPos.page = child;
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.page.getNbElems() );
+ child = ((AbstractPage<K, V>)parentPos.page).getPage( parentPos.page.getNbElems() );
}
// and the leaf
@@ -774,95 +775,4 @@ public class TupleCursorImpl<K, V> exten
}
- /**
- * {@inheritDoc}
- */
- public void beforeFirst() throws IOException
- {
- // First check that we have elements in the BTree
- if ( ( stack == null ) || ( stack.length == 0 ) )
- {
- return;
- }
-
- Page<K, V> child = null;
-
- for ( int i = 0; i < depth; i++ )
- {
- ParentPos<K, V> parentPos = stack[i];
- parentPos.pos = 0;
-
- if ( child != null )
- {
- parentPos.page = child;
- }
-
- child = ((Node<K, V>)parentPos.page).getPage( 0 );
- }
-
- // and leaf
- ParentPos<K, V> parentPos = stack[depth];
- parentPos.pos = BEFORE_FIRST;
-
- if ( child != null )
- {
- parentPos.page = child;
- }
-
- if ( parentPos.valueCursor != null )
- {
- parentPos.valueCursor = ((PersistedLeaf<K, V>)parentPos.page).values[0].getCursor();
- parentPos.valueCursor.beforeFirst();
- }
- }
-
-
- /**
- * {@inheritDoc}
- */
- public void afterLast() throws IOException
- {
- // First check that we have elements in the BTree
- if ( ( stack == null ) || ( stack.length == 0 ) )
- {
- return;
- }
-
- Page<K, V> child = null;
-
- for ( int i = 0; i < depth; i++ )
- {
- ParentPos<K, V> parentPos = stack[i];
-
- if ( child != null )
- {
- parentPos.page = child;
- parentPos.pos = child.getNbElems();
- }
- else
- {
- // We have N+1 children if the page is a Node, so we don't decrement the nbElems field
- parentPos.pos = parentPos.page.getNbElems();
- }
-
- child = ((Node<K, V>)parentPos.page).getPage( parentPos.pos );
- }
-
- // and leaf
- ParentPos<K, V> parentPos = stack[depth];
-
- if ( child == null )
- {
- parentPos.pos = parentPos.page.getNbElems() - 1;
- }
- else
- {
- parentPos.page = child;
- parentPos.pos = child.getNbElems() - 1;
- }
-
- parentPos.valueCursor = ((PersistedLeaf<K, V>)parentPos.page).values[parentPos.pos].getCursor();
- parentPos.valueCursor.afterLast();
- parentPos.pos = AFTER_LAST;
- }
}