[Mulgara-svn] r860 - projects/xa2/object-pool/src
andrae at mulgara.org
andrae at mulgara.org
Mon Apr 28 10:57:21 UTC 2008
Author: andrae
Date: 2008-04-28 03:57:20 -0700 (Mon, 28 Apr 2008)
New Revision: 860
Modified:
projects/xa2/object-pool/src/CompMemTrie.java
Log:
Removed more control-flow exceptions.
I wish java supported continuations.
Modified: projects/xa2/object-pool/src/CompMemTrie.java
===================================================================
--- projects/xa2/object-pool/src/CompMemTrie.java 2008-04-28 08:58:12 UTC (rev 859)
+++ projects/xa2/object-pool/src/CompMemTrie.java 2008-04-28 10:57:20 UTC (rev 860)
@@ -39,9 +39,7 @@
if (root == null) {
root = new TrieLeaf(key, value);
} else {
- try {
- root.insert(key, value);
- } catch (TrieNode.InsertAbove k) {
+ if (!root.insert(key, value)) {
root = new TrieBranch(root, key, value);
}
}
@@ -124,10 +122,6 @@
}
protected abstract static class TrieNode {
- @SuppressWarnings("serial")
- protected static class InsertAbove extends Exception {} ;
- protected static final InsertAbove cont = new InsertAbove();
-
protected TrieLeaf aLeaf;
/**
* Offset into block of this TrieNode.
@@ -135,8 +129,11 @@
*/
protected short location = 0;
- public void insert(byte[] key, long value) throws InsertAbove {
- insert(new TrieLeaf(key, value), 0);
+ /**
+ * @return false if we need to insert key above this node.
+ */
+ public boolean insert(byte[] key, long value) {
+ return insert(new TrieLeaf(key, value), 0);
}
public long lookup(byte[] key) throws NotFound {
@@ -153,7 +150,7 @@
protected abstract void write(ByteBuffer index, FileChannel data) throws IOException;
protected abstract int totalIndexSize();
protected abstract int totalDataSize();
- protected abstract void insert(TrieLeaf node, int parentLcd) throws InsertAbove;
+ protected abstract boolean insert(TrieLeaf node, int parentLcd);
protected abstract long lookup(byte[] key, int parentLcd) throws NotFound;
protected static boolean regionMatches(byte[] lhs, int lhsOff, byte[] rhs, int rhsOff, int len) {
@@ -305,9 +302,9 @@
}
}
- protected void insert(TrieLeaf node, int parentLcp) throws InsertAbove {
+ protected boolean insert(TrieLeaf node, int parentLcp) {
if (!regionMatches(aLeaf.key, parentLcp, node.key, parentLcp, offset - parentLcp)) {
- throw cont;
+ return false;
} else {
// new node matches the lcp of this node.
if (node.key.length == offset) {
@@ -315,7 +312,7 @@
if (term == null) {
term = node;
} else {
- term.insert(node, offset);
+ return term.insert(node, offset);
}
} else {
// new node is expected to terminate in one of this nodes children.
@@ -324,14 +321,14 @@
// this is the first node to be inserted on this branching key.
children.insert(node.key[offset], node);
} else {
- try {
- // there is an existing child node branching on this branching key.
- child.insert(node, offset);
- } catch (InsertAbove k) {
- children.insert(node.key[offset], new TrieBranch(child, node));
+ // there is an existing child node branching on this branching key.
+ if (!child.insert(node, offset)) {
+ children.insert(node.key[offset], new TrieBranch(child, node));
}
}
}
+
+ return true;
}
}
@@ -395,13 +392,13 @@
this.aLeaf = this;
}
- protected void insert(TrieLeaf node, int parentLcp) throws InsertAbove {
+ protected boolean insert(TrieLeaf node, int parentLcp) {
if (key.length != node.key.length) {
- throw cont;
+ return false;
} else if (!regionMatches(key, parentLcp, node.key, parentLcp, key.length - parentLcp)) {
- throw cont;
+ return false;
} else if (value == node.value) {
- return; // Duplicate key/value pair.
+ return true; // Duplicate key/value pair.
} else {
throw new IllegalArgumentException("Attempt to insert multiple values for same key");
}
More information about the Mulgara-svn
mailing list