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 2012/01/22 13:02:13 UTC
svn commit: r1234497 -
/directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java
Author: elecharny
Date: Sun Jan 22 12:02:13 2012
New Revision: 1234497
URL: http://svn.apache.org/viewvc?rev=1234497&view=rev
Log:
Added some Javadoc
Modified:
directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java
Modified: directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java?rev=1234497&r1=1234496&r2=1234497&view=diff
==============================================================================
--- directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java (original)
+++ directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java Sun Jan 22 12:02:13 2012
@@ -43,13 +43,19 @@ public class BTree<K, V>
/** This BTree's record ID in the PageManager. */
private transient long recordId;
+ /** A field used to generate new revisions in a thread safe way */
+ private AtomicLong revision = new AtomicLong(0);
+
+ /** A field used to generate new recordId in a thread safe way */
private transient AtomicLong pageRecordIdGenerator;
/** Comparator used to index entries. */
Comparator<K> comparator;
+ /** The current rootPage */
protected Page<K, V> rootPage;
+ /** A map containing all the existing revisions */
private Map<Long, Page<K, V>> roots = new HashMap<Long, Page<K, V>>();
/**
@@ -58,15 +64,14 @@ public class BTree<K, V>
*/
int bTreeHeight;
- /** Revision */
- private AtomicLong revision = new AtomicLong(0);
-
/** Number of entries in each Page. */
protected int pageSize;
/**
+ * Creates a new BTree with a default page size and a comparator.
*
+ * @param comparator The comparator to use
*/
public BTree( Comparator<K> comparator ) throws IOException
{
@@ -75,7 +80,10 @@ public class BTree<K, V>
/**
+ * Creates a new BTree with a specific page size and a comparator.
*
+ * @param comparator The comparator to use
+ * @param pageSize The number of elements we can store in a page
*/
public BTree( Comparator<K> comparator, int pageSize ) throws IOException
{
@@ -93,14 +101,25 @@ public class BTree<K, V>
}
- public void setPageSize( int pageSize )
+ /**
+ * Find the value associated with the given key.
+ *
+ * @param key Lookup key.
+ * @return Value associated with the key, or null if not found.
+ */
+ public V find( K key ) throws IOException
{
- this.pageSize = pageSize;
+ if ( key == null )
+ {
+ throw new IllegalArgumentException( "Key must not be null" );
+ }
- if ( pageSize <= 0 )
+ if ( rootPage == null )
{
- this.pageSize = DEFAULT_PAGE_SIZE;
+ return null;
}
+
+ return rootPage.find( key );
}
@@ -169,29 +188,33 @@ public class BTree<K, V>
/**
- * Find the value associated with the given key.
- *
- * @param key Lookup key.
- * @return Value associated with the key, or null if not found.
+ * @return The number of element we can stoe in a page
*/
- public V find( K key ) throws IOException
+ public int getPageSize()
{
- if ( key == null )
- {
- throw new IllegalArgumentException( "Key must not be null" );
- }
+ return pageSize;
+ }
+
+
+ /**
+ * Set the maximum number of elements we can store in a page. This must be a
+ * number greater than 1. The default page size is 16.
+ *
+ * @param pageSize The requested page size
+ */
+ public void setPageSize( int pageSize )
+ {
+ this.pageSize = pageSize;
- if ( rootPage == null )
+ if ( pageSize <= 2 )
{
- return null;
+ this.pageSize = DEFAULT_PAGE_SIZE;
}
-
- return rootPage.find( key );
}
/**
- * Return the persistent record identifier of the BTree.
+ * @return the persistent record identifier of the BTree.
*/
public long getRecordId()
{
@@ -208,18 +231,31 @@ public class BTree<K, V>
}
+ /**
+ * Generates a new RecordId.
+ *
+ * @return a new incremental recordId
+ */
/** No qualifier */ long generateRecordId()
{
return pageRecordIdGenerator.getAndIncrement();
}
+ /**
+ * Generates a new revision number.
+ *
+ * @return a new incremental revision number
+ */
/** No qualifier */ long generateRevision()
{
return revision.getAndIncrement();
}
+ /**
+ * @see Object#toString()
+ */
public String toString()
{
StringBuilder sb = new StringBuilder();