[Mulgara-svn] r862 - projects/xa2/object-pool/src
andrae at mulgara.org
andrae at mulgara.org
Tue Apr 29 02:24:12 UTC 2008
Author: andrae
Date: 2008-04-28 19:24:10 -0700 (Mon, 28 Apr 2008)
New Revision: 862
Modified:
projects/xa2/object-pool/src/CompBlockTrie.java
projects/xa2/object-pool/src/CompMemTrie.java
Log:
Started migration of write code out of memory-trie and into block-trie.
Modified: projects/xa2/object-pool/src/CompBlockTrie.java
===================================================================
--- projects/xa2/object-pool/src/CompBlockTrie.java 2008-04-28 12:16:15 UTC (rev 861)
+++ projects/xa2/object-pool/src/CompBlockTrie.java 2008-04-29 02:24:10 UTC (rev 862)
@@ -13,6 +13,9 @@
*/
public class CompBlockTrie extends CompMemTrie {
@SuppressWarnings("serial")
+ public static class InsufficientSpace extends Exception
+ { public InsufficientSpace(String s) { super(s); } };
+
// Calculated as the worst case size per entry.
// Assumes a full leaf and branch per entry.
// Block: 2-byte type-header
@@ -75,8 +78,36 @@
if (index.remaining() < blockSize) {
throw new InsufficientSpace("Insufficient space remaining in buffer to write block");
}
+
+ // Temporarally set the limit to blocksize.
+ int limit = index.limit();
index.limit(index.position() + blockSize);
- super.write(index, data);
+
+ if (root == null) {
+ throw new IllegalStateException("Attempt to write empty trie");
+ }
+
+ int indexreq = (root == null) ? 8 : root.totalIndexSize() + 4 + 4; // + sizeof(MAGIC) + sizeof(root_loc_type + root_loc)
+ if (indexreq > index.remaining()) {
+ System.err.printf("Index-Req:%d ; remaining:%d ; capacity:%d ; limit:%d ; position:%d\n", indexreq,
+ index.remaining(), index.capacity(), index.limit(), index.position());
+ throw new InsufficientSpace("Attempt to write trie index to bytebuffer with insufficient space");
+ }
+ if (indexreq > 0x00010000) {
+ throw new InsufficientSpace("Attempt to write trie index larger than 64K");
+ }
+
+ index.putInt(MAGIC);
+ if (root != null) {
+ root.write(index, data);
+ }
+ index.put(TYPE_ROOT_LOC);
+ index.put((byte)0xFF);
+ index.putShort(root.location);
+
+ // Set the position to the block size to ensure whole blocks are written.
index.position(index.limit());
+ // Reset the limit to its initial value.
+ index.limit(limit);
}
}
Modified: projects/xa2/object-pool/src/CompMemTrie.java
===================================================================
--- projects/xa2/object-pool/src/CompMemTrie.java 2008-04-28 12:16:15 UTC (rev 861)
+++ projects/xa2/object-pool/src/CompMemTrie.java 2008-04-29 02:24:10 UTC (rev 862)
@@ -20,10 +20,6 @@
public static class NotFound extends Exception {};
private static NotFound notfound = new NotFound();
- @SuppressWarnings("serial")
- public static class InsufficientSpace extends Exception
- { public InsufficientSpace(String s) { super(s); } };
-
static final byte TYPE_BRANCH_TERM = 0x01; // Indicates a trie branch with a termination entry..
static final byte TYPE_BRANCH_NOTERM = 0x02; // Indicates a trie branch without a termination entry..
static final byte TYPE_LEAF = 0x03; // Indicates a trie branch without a termination entry..
@@ -31,7 +27,6 @@
public final static int MAGIC = 0x00020001;
public final static int INVERT_MAGIC = 0x01000200;
-
protected TrieNode root;
public CompMemTrie() {
this.root = null;
@@ -69,27 +64,6 @@
}
}
- public void write(ByteBuffer index, FileChannel data) throws InsufficientSpace, IOException {
- if (root == null) {
- throw new IllegalStateException("Attempt to write empty trie");
- }
- int indexreq = root.totalIndexSize() + 4 + 4; // + sizeof(MAGIC) + sizeof(root_loc_type + root_loc)
- if (indexreq > index.remaining()) {
- System.err.printf("Index-Req:%d ; remaining:%d ; capacity:%d ; limit:%d ; position:%d\n", indexreq,
- index.remaining(), index.capacity(), index.limit(), index.position());
- throw new InsufficientSpace("Attempt to write trie index to bytebuffer with insufficient space");
- }
- if (indexreq > 0x00010000) {
- throw new InsufficientSpace("Attempt to write trie index larger than 64K");
- }
-
- index.putInt(MAGIC);
- root.write(index, data);
- index.put(TYPE_ROOT_LOC);
- index.put((byte)0xFF);
- index.putShort(root.location);
- }
-
public CompMemTrie(ByteBuffer index, FileChannel data) throws IOException {
index.rewind(); // Note sure if I should doing this here or delegating to the caller.
int magic = index.getInt();
More information about the Mulgara-svn
mailing list