[Mulgara-svn] r863 - projects/xa2/object-pool/src
andrae at mulgara.org
andrae at mulgara.org
Tue Apr 29 03:03:57 UTC 2008
Author: andrae
Date: 2008-04-28 20:03:56 -0700 (Mon, 28 Apr 2008)
New Revision: 863
Modified:
projects/xa2/object-pool/src/CompBlockTrie.java
projects/xa2/object-pool/src/CompMemTrie.java
Log:
Continue to migrate IO code over into the BlockTrie.
Modified: projects/xa2/object-pool/src/CompBlockTrie.java
===================================================================
--- projects/xa2/object-pool/src/CompBlockTrie.java 2008-04-29 02:24:10 UTC (rev 862)
+++ projects/xa2/object-pool/src/CompBlockTrie.java 2008-04-29 03:03:56 UTC (rev 863)
@@ -6,7 +6,9 @@
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
+import java.util.HashMap;
/**
* Extends CompMemTrie to guarantee the trie will fit within a single block.
@@ -44,6 +46,7 @@
private int blockSize;
public CompBlockTrie(int blockSize) {
+ super();
assert blockSize > 1024;
assert blockSize <= 32*1024;
this.blockSize = blockSize;
@@ -51,7 +54,50 @@
}
public CompBlockTrie(ByteBuffer index, FileChannel data) throws IOException {
- super(index, data);
+ super();
+ index.rewind(); // Note sure if I should doing this here or delegating to the caller.
+ int magic = index.getInt();
+ if (magic != MAGIC) {
+ if (magic == INVERT_MAGIC) {
+ index.order(index.order().equals(ByteOrder.BIG_ENDIAN) ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
+ } else {
+ throw new IllegalArgumentException("Bad magic in index buffer: " + magic + ", MAGIC=" + MAGIC);
+ }
+ }
+
+ // I should be able to replace this with a stack.
+ // The child->parent relationship is implicit in the ordering of the nodes in the file.
+ // The only thing we need to know is when to stop reading nodes and that is provided by rootLocation.
+ // If treated as a stack once we have read the root the stack should contain only a single element - the
+ // root node.
+ // For now I'm hoping the HashMap will help with debugging - but it is wasteful of memory in the long run.
+ HashMap<Short, TrieNode> nodeMap = new HashMap<Short, TrieNode>();
+
+ short rootLocation = -1;
+ while (rootLocation == -1) {
+ short location = (short)index.position();
+ byte type = index.get();
+ switch (type) {
+ case TYPE_BRANCH_TERM:
+ nodeMap.put(location, new TrieBranch(index, true, nodeMap));
+ break;
+ case TYPE_BRANCH_NOTERM:
+ nodeMap.put(location, new TrieBranch(index, false, nodeMap));
+ break;
+ case TYPE_LEAF:
+ nodeMap.put(location, new TrieLeaf(index, data));
+ break;
+ case TYPE_ROOT_LOC:
+ index.get();
+ rootLocation = index.getShort();
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid trie-node");
+ }
+ }
+
+ root = nodeMap.get(rootLocation);
+
this.space = 0; // If this gets modified it will be recalculated automaticly then.
}
Modified: projects/xa2/object-pool/src/CompMemTrie.java
===================================================================
--- projects/xa2/object-pool/src/CompMemTrie.java 2008-04-29 02:24:10 UTC (rev 862)
+++ projects/xa2/object-pool/src/CompMemTrie.java 2008-04-29 03:03:56 UTC (rev 863)
@@ -64,51 +64,6 @@
}
}
- 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();
- if (magic != MAGIC) {
- if (magic == INVERT_MAGIC) {
- index.order(index.order().equals(ByteOrder.BIG_ENDIAN) ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
- } else {
- throw new IllegalArgumentException("Bad magic in index buffer: " + magic + ", MAGIC=" + MAGIC);
- }
- }
-
- // I should be able to replace this with a stack.
- // The child->parent relationship is implicit in the ordering of the nodes in the file.
- // The only thing we need to know is when to stop reading nodes and that is provided by rootLocation.
- // If treated as a stack once we have read the root the stack should contain only a single element - the
- // root node.
- // For now I'm hoping the HashMap will help with debugging - but it is wasteful of memory in the long run.
- HashMap<Short, TrieNode> nodeMap = new HashMap<Short, TrieNode>();
-
- short rootLocation = -1;
- while (rootLocation == -1) {
- short location = (short)index.position();
- byte type = index.get();
- switch (type) {
- case TYPE_BRANCH_TERM:
- nodeMap.put(location, new TrieBranch(index, true, nodeMap));
- break;
- case TYPE_BRANCH_NOTERM:
- nodeMap.put(location, new TrieBranch(index, false, nodeMap));
- break;
- case TYPE_LEAF:
- nodeMap.put(location, new TrieLeaf(index, data));
- break;
- case TYPE_ROOT_LOC:
- index.get();
- rootLocation = index.getShort();
- break;
- default:
- throw new IllegalArgumentException("Invalid trie-node");
- }
- }
-
- root = nodeMap.get(rootLocation);
- }
-
protected abstract static class TrieNode {
protected TrieLeaf aLeaf;
/**
@@ -156,7 +111,7 @@
}
}
- private static class TrieBranch extends TrieNode {
+ protected static class TrieBranch extends TrieNode {
private int offset;
private ByteMap<TrieNode> children;
private TrieLeaf term;
@@ -355,7 +310,7 @@
}
}
- private static class TrieLeaf extends TrieNode {
+ protected static class TrieLeaf extends TrieNode {
final byte[] key;
final long value;
More information about the Mulgara-svn
mailing list