activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r829202 - in /activemq/sandbox/activemq-apollo: activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/ hawtdb/src/main/java/org/apache/hawtdb/api/ hawtdb/src/main/java/org/apache/hawtdb/internal/index/ hawtdb/src/test/java/org...
Date Fri, 23 Oct 2009 20:14:55 GMT
Author: chirino
Date: Fri Oct 23 20:14:54 2009
New Revision: 829202

URL: http://svn.apache.org/viewvc?rev=829202&view=rev
Log:
Fixing compile issue and updating IndexVisitor impl in hawtdb

Modified:
    activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/DestinationEntity.java
    activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/KahaDBStore.java
    activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/Marshallers.java
    activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/MessageKeys.java
    activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/RootEntity.java
    activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/api/Index.java
    activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/api/IndexVisitor.java
    activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/index/HashIndex.java
    activemq/sandbox/activemq-apollo/hawtdb/src/test/java/org/apache/hawtdb/internal/index/BTreeIndexBenchmark.java
    activemq/sandbox/activemq-apollo/hawtdb/src/test/java/org/apache/hawtdb/internal/index/HashIndexBenchmark.java

Modified: activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/DestinationEntity.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/DestinationEntity.java?rev=829202&r1=829201&r2=829202&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/DestinationEntity.java
(original)
+++ activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/DestinationEntity.java
Fri Oct 23 20:14:54 2009
@@ -25,7 +25,6 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Map;
-import java.util.TreeSet;
 import java.util.Map.Entry;
 
 import org.apache.activemq.broker.store.Store;
@@ -37,7 +36,6 @@
 import org.apache.activemq.util.marshaller.Marshaller;
 import org.apache.activemq.util.marshaller.VariableMarshaller;
 import org.apache.kahadb.index.BTreeIndex;
-import org.apache.kahadb.journal.Location;
 import org.apache.kahadb.page.Page;
 import org.apache.kahadb.page.Transaction;
 
@@ -61,6 +59,10 @@
             dataOut.writeLong(value.metaData.getPageId());
         }
 
+        public int estimatedSize(DestinationEntity object) {
+            throw new UnsupportedOperationException();
+        }
+
     };
 
     public final static Marshaller<DestinationMetaData> META_DATA_MARSHALLER = new
VariableMarshaller<DestinationMetaData>() {
@@ -75,6 +77,10 @@
             dataOut.writeInt(value.count);
             dataOut.writeLong(value.size);
         }
+
+        public int estimatedSize(DestinationMetaData object) {
+            throw new UnsupportedOperationException();
+        }
     };
 
     public Class<DestinationEntity> getType() {

Modified: activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/KahaDBStore.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/KahaDBStore.java?rev=829202&r1=829201&r2=829202&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/KahaDBStore.java
(original)
+++ activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/KahaDBStore.java
Fri Oct 23 20:14:54 2009
@@ -18,7 +18,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Iterator;

Modified: activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/Marshallers.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/Marshallers.java?rev=829202&r1=829201&r2=829202&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/Marshallers.java
(original)
+++ activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/Marshallers.java
Fri Oct 23 20:14:54 2009
@@ -65,6 +65,10 @@
                 dataOut.writeBoolean(false);
             }
         }
+
+        public int estimatedSize(QueueRecord object) {
+            throw new UnsupportedOperationException();
+        }
     };
 
     public final static Marshaller<Location> LOCATION_MARSHALLER = new Marshaller<Location>()
{
@@ -93,6 +97,10 @@
             return 8;
         }
 
+        public int estimatedSize(Location object) {
+            throw new UnsupportedOperationException();
+        }
+
     };
 
     public final static Marshaller<AsciiBuffer> ASCII_BUFFER_MARSHALLER = new VariableMarshaller<AsciiBuffer>()
{
@@ -107,6 +115,10 @@
             dataOut.writeShort(object.length);
             dataOut.write(object.data, object.offset, object.length);
         }
+
+        public int estimatedSize(AsciiBuffer object) {
+            throw new UnsupportedOperationException();
+        }
     };
 
     public final static Marshaller<Buffer> BUFFER_MARSHALLER = new VariableMarshaller<Buffer>()
{
@@ -121,6 +133,10 @@
             dataOut.writeShort(object.length);
             dataOut.write(object.data, object.offset, object.length);
         }
+
+        public int estimatedSize(Buffer object) {
+            throw new UnsupportedOperationException();
+        }
     };
 
     public final static Marshaller<QueueDescriptor> QUEUE_DESCRIPTOR_MARSHALLER = new
VariableMarshaller<QueueDescriptor>() {
@@ -149,5 +165,8 @@
                 dataOut.writeBoolean(false);
             }
         }
+        public int estimatedSize(QueueDescriptor object) {
+            throw new UnsupportedOperationException();
+        }
     };
 }
\ No newline at end of file

Modified: activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/MessageKeys.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/MessageKeys.java?rev=829202&r1=829201&r2=829202&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/MessageKeys.java
(original)
+++ activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/MessageKeys.java
Fri Oct 23 20:14:54 2009
@@ -53,5 +53,9 @@
             dataOut.writeShort(object.messageId.length);
             dataOut.write(object.messageId.data, object.messageId.offset, object.messageId.length);
         }
+
+        public int estimatedSize(MessageKeys object) {
+            throw new UnsupportedOperationException();
+        }
     };
 }
\ No newline at end of file

Modified: activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/RootEntity.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/RootEntity.java?rev=829202&r1=829201&r2=829202&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/RootEntity.java
(original)
+++ activemq/sandbox/activemq-apollo/activemq-kaha/src/main/java/org/apache/activemq/broker/store/kahadb/RootEntity.java
Fri Oct 23 20:14:54 2009
@@ -95,6 +95,10 @@
                 os.writeBoolean(false);
             }
         }
+
+        public int estimatedSize(RootEntity object) {
+            throw new UnsupportedOperationException();
+        }
     };
 
     // The root page the this object's state is stored on.

Modified: activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/api/Index.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/api/Index.java?rev=829202&r1=829201&r2=829202&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/api/Index.java
(original)
+++ activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/api/Index.java
Fri Oct 23 20:14:54 2009
@@ -80,11 +80,20 @@
      * @param tx
      * @return
      * @throws IOException
-     * @trhows UnsupportedOperationException 
-     *         if the index does not support fast iteration of the elements.
+     * throws UnsupportedOperationException if the index does not support fast iteration
of the elements.
      */
     Iterator<Map.Entry<Key,Value>> iterator() throws UnsupportedOperationException;
 
+
+    /**
+     * Traverses the visitor over the stored entries in this index.  The visitor can control
+     * which keys and values are visited.
+     * 
+     * @param visitor
+     * @throws UnsupportedOperationException if this is not an ordered index.
+     */
+    public void visit(IndexVisitor<Key, Value> visitor) throws UnsupportedOperationException;
+
     int getPage();
     
 }

Modified: activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/api/IndexVisitor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/api/IndexVisitor.java?rev=829202&r1=829201&r2=829202&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/api/IndexVisitor.java
(original)
+++ activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/api/IndexVisitor.java
Fri Oct 23 20:14:54 2009
@@ -19,181 +19,288 @@
 import java.util.List;
 
 /**
- * Interface used to selectively visit the entries in a sorted index.
- * 
- * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ * Interface used to selectively visit the entries in a BTree.
+ *
+ * @param <Key>
+ * @param <Value>
  */
-public interface IndexVisitor<Key, Value> {
+public interface IndexVisitor<Key,Value> {
 
     /**
-     * Do you want to visit the range of BTree entries between the first and and
-     * second key?
-     * 
-     * @param first
-     *            if null indicates the range of values before the second key.
-     * @param second
-     *            if null indicates the range of values after the first key.
-     * @return true if you want to visit the values between the first and second
-     *         key.
+     * Do you want to visit the range of BTree entries between the first and and second key?
+     *
+     * @param first if null indicates the range of values before the second key.
+     * @param second if null indicates the range of values after the first key.
+     * @return true if you want to visit the values between the first and second key.
      */
     boolean isInterestedInKeysBetween(Key first, Key second);
 
     /**
      * The keys and values of a BTree leaf node.
-     * 
+     *
      * @param keys
      * @param values
      */
     void visit(List<Key> keys, List<Value> values);
 
     /**
-     * If the visitor wishes to
-     * 
-     * @return
+     * @return true if the visitor has quenched it's thirst for more results
      */
     boolean isSatiated();
 
-    abstract class GTVisitor<Key extends Comparable<? super Key>, Value> implements
IndexVisitor<Key, Value> {
-        final private Key value;
-        int matches = Integer.MAX_VALUE;
-        boolean limited;
+    public interface Predicate<Key> {
+        boolean isInterestedInKeysBetween(Key first, Key second);
+        boolean isInterestedInKey(Key key);
+    }
 
-        public GTVisitor(Key value) {
-            this.value = value;
+    abstract class PredicateVisitor<Key, Value> implements IndexVisitor<Key, Value>,
Predicate<Key> {
+        public static final int UNLIMITED=-1;
+		private int limit;
+
+		public PredicateVisitor(int limit) {
+		    this.limit = limit;
+		}
+
+		final public void visit(List<Key> keys, List<Value> values) {
+			for( int i=0; i < keys.size() && !isSatiated(); i++) {
+				Key key = keys.get(i);
+				if( isInterestedInKey(key) ) {
+				    if(limit > 0 )
+				        limit--;
+					matched(key, values.get(i));
+				}
+			}
+		}
+
+		protected void matched(Key key, Value value) {
         }
 
-        public GTVisitor(Key value, int limit) {
-            this.value = value;
-            limited = true;
-            matches = limit;
+        public boolean isSatiated() {
+            return limit==0;
         }
+    }
 
-        public boolean isInterestedInKeysBetween(Key first, Key second) {
-            return second == null || second.compareTo(value) > 0;
+    class OrVisitor<Key, Value> extends PredicateVisitor<Key, Value> {
+        private final List<Predicate<Key>> conditions;
+
+        public OrVisitor(List<Predicate<Key>> conditions) {
+            this(conditions, UNLIMITED);
         }
 
-        public void visit(List<Key> keys, List<Value> values) {
-            for (int i = 0; i < keys.size() && !isSatiated(); i++) {
-                Key key = keys.get(i);
-                if (key.compareTo(value) > 0) {
-                    matched(key, values.get(i));
-                    if (limited) matches--;
+        public OrVisitor(List<Predicate<Key>> conditions, int limit) {
+            super(limit);
+            this.conditions = conditions;
+        }
+
+		final public boolean isInterestedInKeysBetween(Key first, Key second) {
+            for (Predicate<Key> condition : conditions) {
+                if( condition.isInterestedInKeysBetween(first, second) ) {
+                    return true;
                 }
             }
-        }
+            return false;
+		}
 
-        public boolean isSatiated() {
-            return limited && matches <= 0;
+        final public boolean isInterestedInKey(Key key) {
+            for (Predicate<Key> condition : conditions) {
+                if( condition.isInterestedInKey(key) ) {
+                    return true;
+                }
+            }
+            return false;
         }
 
-        abstract protected void matched(Key key, Value value);
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            boolean first=true;
+            for (Predicate<Key> condition : conditions) {
+                if( !first ) {
+                    sb.append(" OR ");
+                }
+                first=false;
+                sb.append("(");
+                sb.append(condition);
+                sb.append(")");
+            }
+            return sb.toString();
+        }
     }
 
-    abstract class GTEVisitor<Key extends Comparable<? super Key>, Value> implements
IndexVisitor<Key, Value> {
-        final private Key value;
-        int matches = Integer.MAX_VALUE;
-        boolean limited;
+    class AndVisitor<Key, Value> extends PredicateVisitor<Key, Value> {
+        private final List<Predicate<Key>> conditions;
 
-        public GTEVisitor(Key value) {
-            this.value = value;
+        public AndVisitor(List<Predicate<Key>> conditions) {
+            this(conditions, UNLIMITED);
         }
-        
-        public GTEVisitor(Key value, int limit) {
-            this.value = value;
-            limited = true;
-            matches = limit;
+        public AndVisitor(List<Predicate<Key>> conditions, int limit) {
+            super(limit);
+            this.conditions = conditions;
         }
 
-        public boolean isInterestedInKeysBetween(Key first, Key second) {
-            return second == null || second.compareTo(value) >= 0;
+		final public boolean isInterestedInKeysBetween(Key first, Key second) {
+            for (Predicate<Key> condition : conditions) {
+                if( !condition.isInterestedInKeysBetween(first, second) ) {
+                    return false;
+                }
+            }
+            return true;
+		}
+
+        final public boolean isInterestedInKey(Key key) {
+            for (Predicate<Key> condition : conditions) {
+                if( !condition.isInterestedInKey(key) ) {
+                    return false;
+                }
+            }
+            return true;
         }
 
-        public void visit(List<Key> keys, List<Value> values) {
-            for (int i = 0; i < keys.size() && !isSatiated(); i++) {
-                Key key = keys.get(i);
-                if (key.compareTo(value) >= 0) {
-                    matched(key, values.get(i));
-                    if (limited) matches--;
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            boolean first=true;
+            for (Predicate<Key> condition : conditions) {
+                if( !first ) {
+                    sb.append(" AND ");
                 }
+                first=false;
+                sb.append("(");
+                sb.append(condition);
+                sb.append(")");
             }
+            return sb.toString();
         }
+    }
 
-        public boolean isSatiated() {
-            return limited && matches <= 0;
+    class BetweenVisitor<Key extends Comparable<? super Key>, Value> extends
PredicateVisitor<Key, Value> {
+		private final Key first;
+        private final Key last;
+
+        public BetweenVisitor(Key first, Key last) {
+            this(first, last, UNLIMITED);
         }
 
-        abstract protected void matched(Key key, Value value);
-    }
+        public BetweenVisitor(Key first, Key last, int limit) {
+            super(limit);
+			this.first = first;
+            this.last = last;
+        }
 
-    abstract class LTVisitor<Key extends Comparable<? super Key>, Value> implements
IndexVisitor<Key, Value> {
-        final private Key value;
-        int matches = Integer.MAX_VALUE;
-        boolean limited;
+		final public boolean isInterestedInKeysBetween(Key left, Key right) {
+        	return (right==null || right.compareTo(first)>=0)
+                    && (left==null || left.compareTo(last)<0);
+		}
 
-        public LTVisitor(Key value) {
-            this.value = value;
+        final public boolean isInterestedInKey(Key key) {
+            return key.compareTo(first) >=0 && key.compareTo(last) <0;
         }
-        
-        public LTVisitor(Key value, int limit) {
-            this.value = value;
-            limited = true;
-            matches = limit;
+
+        @Override
+        public String toString() {
+            return first+" <= key < "+last;
         }
+    }
 
-        public boolean isInterestedInKeysBetween(Key first, Key second) {
-            return first == null || first.compareTo(value) < 0;
+    class GTVisitor<Key extends Comparable<? super Key>, Value> extends PredicateVisitor<Key,
Value> {
+		final private Key value;
+
+		public GTVisitor(Key value) {
+			this(value, UNLIMITED);
+		}
+		public GTVisitor(Key value, int limit) {
+		    super(limit);
+			this.value = value;
+		}
+
+		final public boolean isInterestedInKeysBetween(Key first, Key second) {
+        	return second==null || isInterestedInKey(second);
+		}
+
+        final public boolean isInterestedInKey(Key key) {
+            return key.compareTo(value)>0;
+        }
+
+        @Override
+        public String toString() {
+            return "key > "+ value;
         }
+    }
 
-        public void visit(List<Key> keys, List<Value> values) {
-            for (int i = 0; i < keys.size() && !isSatiated(); i++) {
-                Key key = keys.get(i);
-                if (key.compareTo(value) < 0) {
-                    matched(key, values.get(i));
-                    if (limited) matches--;
-                }
-            }
+    class GTEVisitor<Key extends Comparable<? super Key>, Value> extends PredicateVisitor<Key,
Value> {
+		final private Key value;
+
+        public GTEVisitor(Key value) {
+            this(value, UNLIMITED);
         }
 
-        public boolean isSatiated() {
-            return limited && matches <= 0;
+		public GTEVisitor(Key value, int limit) {
+            super(limit);
+			this.value = value;
+		}
+
+		final public boolean isInterestedInKeysBetween(Key first, Key second) {
+        	return second==null || isInterestedInKey(second);
+		}
+
+        final public boolean isInterestedInKey(Key key) {
+            return key.compareTo(value)>=0;
         }
 
-        abstract protected void matched(Key key, Value value);
+        @Override
+        public String toString() {
+            return "key >= "+ value;
+        }
     }
 
-    abstract class LTEVisitor<Key extends Comparable<? super Key>, Value> implements
IndexVisitor<Key, Value> {
-        final private Key value;
-        int matches = Integer.MAX_VALUE;
-        boolean limited;
+    class LTVisitor<Key extends Comparable<? super Key>, Value> extends PredicateVisitor<Key,
Value> {
+		final private Key value;
 
-        public LTEVisitor(Key value) {
-            this.value = value;
+        public LTVisitor(Key value) {
+            this(value, UNLIMITED);
         }
+        
+		public LTVisitor(Key value, int limit) {
+            super(limit);
+			this.value = value;
+		}
+
+		final public boolean isInterestedInKeysBetween(Key first, Key second) {
+        	return first==null || isInterestedInKey(first);
+		}
+
+        final public boolean isInterestedInKey(Key key) {
+            return key.compareTo(value)<0;
+        }
+
+        @Override
+        public String toString() {
+            return "key < "+ value;
+        }
+    }
+
+    class LTEVisitor<Key extends Comparable<? super Key>, Value> extends PredicateVisitor<Key,
Value> {
+		final private Key value;
 
+		public LTEVisitor(Key value) {
+            this(value, UNLIMITED);
+		}
         public LTEVisitor(Key value, int limit) {
+            super(limit);
             this.value = value;
-            limited = true;
-            matches = limit;
-        }
-        
-        public boolean isInterestedInKeysBetween(Key first, Key second) {
-            return first == null || first.compareTo(value) <= 0;
         }
 
-        public void visit(List<Key> keys, List<Value> values) {
-            for (int i = 0; i < keys.size() && !isSatiated(); i++) {
-                Key key = keys.get(i);
-                if (key.compareTo(value) <= 0) {
-                    matched(key, values.get(i));
-                    if (limited) matches--;
-                }
-            }
-        }
+		final public boolean isInterestedInKeysBetween(Key first, Key second) {
+        	return first==null || isInterestedInKey(first);
+		}
 
-        public boolean isSatiated() {
-            return limited && matches <= 0;
+        final public boolean isInterestedInKey(Key key) {
+            return key.compareTo(value)<=0;
         }
 
-        abstract protected void matched(Key key, Value value);
+        @Override
+        public String toString() {
+            return "key <= "+ value;
+        }
     }
 }
\ No newline at end of file

Modified: activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/index/HashIndex.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/index/HashIndex.java?rev=829202&r1=829201&r2=829202&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/index/HashIndex.java
(original)
+++ activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/index/HashIndex.java
Fri Oct 23 20:14:54 2009
@@ -35,6 +35,7 @@
 import org.apache.hawtdb.api.IOPagingException;
 import org.apache.hawtdb.api.Index;
 import org.apache.hawtdb.api.IndexException;
+import org.apache.hawtdb.api.IndexVisitor;
 import org.apache.hawtdb.api.Paged;
 
 
@@ -52,6 +53,7 @@
     private final int page;
     private final int maximumBucketCapacity;
     private final int minimumBucketCapacity;
+    private final boolean fixedCapacity;
     private final int loadFactor;
     private final int initialBucketCapacity;
     private final boolean deferredEncoding;
@@ -69,6 +71,7 @@
         this.BIN_FACTORY.setKeyMarshaller(factory.getKeyMarshaller());
         this.BIN_FACTORY.setValueMarshaller(factory.getValueMarshaller());
         this.BIN_FACTORY.setDeferredEncoding(this.deferredEncoding);
+        this.fixedCapacity = this.minimumBucketCapacity==this.maximumBucketCapacity &&
this.maximumBucketCapacity==this.initialBucketCapacity;
     }
 
     public HashIndex<Key, Value> create() {
@@ -93,8 +96,13 @@
     }
     
     public Value put(Key key, Value value) {
+        
         Index<Key, Value> bucket = buckets.bucket(key);
-
+        
+        if( fixedCapacity ) {
+            return bucket.put(key,value);
+        }
+        
         boolean wasEmpty = bucket.isEmpty();
         Value put = bucket.put(key,value);
 
@@ -114,11 +122,16 @@
     
     public Value remove(Key key) {
         Index<Key, Value> bucket = buckets.bucket(key);
-
+        
+        if( fixedCapacity ) {
+            return bucket.remove(key);
+        }
+        
+        boolean wasEmpty = bucket.isEmpty();
         Value rc = bucket.remove(key);
         boolean isEmpty = bucket.isEmpty();
         
-        if (isEmpty) {
+        if (!wasEmpty && isEmpty) {
             buckets.active--;
             storeBuckets();
         }
@@ -142,6 +155,11 @@
     public Iterator<Entry<Key, Value>> iterator() throws UnsupportedOperationException
{
         throw new UnsupportedOperationException();
     }
+
+    @Override
+    public void visit(IndexVisitor<Key, Value> visitor) throws UnsupportedOperationException
{
+        throw new UnsupportedOperationException();
+    }
     
     public int size() {
         int rc=0;

Modified: activemq/sandbox/activemq-apollo/hawtdb/src/test/java/org/apache/hawtdb/internal/index/BTreeIndexBenchmark.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/hawtdb/src/test/java/org/apache/hawtdb/internal/index/BTreeIndexBenchmark.java?rev=829202&r1=829201&r2=829202&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/hawtdb/src/test/java/org/apache/hawtdb/internal/index/BTreeIndexBenchmark.java
(original)
+++ activemq/sandbox/activemq-apollo/hawtdb/src/test/java/org/apache/hawtdb/internal/index/BTreeIndexBenchmark.java
Fri Oct 23 20:14:54 2009
@@ -22,8 +22,6 @@
 import org.apache.hawtdb.api.BTreeIndexFactory;
 import org.apache.hawtdb.api.Index;
 import org.apache.hawtdb.api.Transaction;
-import org.apache.hawtdb.internal.Benchmarker.BenchmarkAction;
-import org.junit.Test;
 
 /**
  * 
@@ -31,8 +29,6 @@
  */
 public class BTreeIndexBenchmark extends IndexBenchmark {
 
-    private boolean deferredEncoding;
-
     public BTreeIndexBenchmark() {
         this.benchmark.setSamples(5);
     }
@@ -41,28 +37,8 @@
         BTreeIndexFactory<Long, Buffer> factory = new BTreeIndexFactory<Long, Buffer>();
         factory.setKeyMarshaller(LongMarshaller.INSTANCE);
         factory.setValueMarshaller(new FixedBufferMarshaller(DATA.length));
-        factory.setDeferredEncoding(deferredEncoding);
         return factory.create(tx, tx.allocator().alloc(1));
     }
 
-    @Test
-    public void insertDeffered() throws Exception {
-        deferredEncoding = true;
-        benchmark.benchmark(1, new BenchmarkAction<IndexActor>("insert with deffered
encoding") {
-            protected void execute(IndexActor actor) throws InterruptedException {
-                actor.benchmarkIndex();
-            }
-        });        
-    }
-
-    @Test
-    public void insert() throws Exception {
-        deferredEncoding = false;
-        benchmark.benchmark(1, new BenchmarkAction<IndexActor>("insert without deffered
encoding") {
-            protected void execute(IndexActor actor) throws InterruptedException {
-                actor.benchmarkIndex();
-            }
-        });        
-    }
-    
+   
 }

Modified: activemq/sandbox/activemq-apollo/hawtdb/src/test/java/org/apache/hawtdb/internal/index/HashIndexBenchmark.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/hawtdb/src/test/java/org/apache/hawtdb/internal/index/HashIndexBenchmark.java?rev=829202&r1=829201&r2=829202&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/hawtdb/src/test/java/org/apache/hawtdb/internal/index/HashIndexBenchmark.java
(original)
+++ activemq/sandbox/activemq-apollo/hawtdb/src/test/java/org/apache/hawtdb/internal/index/HashIndexBenchmark.java
Fri Oct 23 20:14:54 2009
@@ -38,7 +38,7 @@
         HashIndexFactory<Long, Buffer> factory = new HashIndexFactory<Long, Buffer>();
         factory.setKeyMarshaller(LongMarshaller.INSTANCE);
         factory.setValueMarshaller(new FixedBufferMarshaller(DATA.length));
-        factory.setFixedCapacity(1024*10);
+        factory.setFixedCapacity(500);
         return factory.create(tx, tx.allocator().alloc(1));
     }
     



Mime
View raw message