use of org.apache.jena.dboe.trans.bplustree.BPTreeNode in project jena by apache.
the class BPTreeNodeBuilder method hasNext.
@Override
public boolean hasNext() {
if (slot != null)
return true;
if (iter == null)
return false;
if (!iter.hasNext()) {
// Start of next block, no more input.
iter = null;
return false;
}
// At least one element to put in a new node.
// Unknown parent. Does not matter (parent is only in-memory)
BPTreeNode bptNode = mgr.createNode(-1);
bptNode.setIsLeaf(leafLayer);
RecordBuffer recBuff = bptNode.getRecordBuffer();
PtrBuffer ptrBuff = bptNode.getPtrBuffer();
recBuff.setSize(0);
// Creation leaves this junk.
ptrBuff.setSize(0);
final boolean debug = false;
int rMax = recBuff.maxSize();
int pMax = ptrBuff.maxSize();
if (debug)
System.out.printf("Max: (%d, %d)\n", rMax, pMax);
for (; iter.hasNext(); ) {
int X = bptNode.getCount();
int X2 = bptNode.getMaxSize();
int P = ptrBuff.size();
int P2 = ptrBuff.maxSize();
int R = recBuff.size();
int R2 = recBuff.maxSize();
// bptNode.getMaxSize() is drivel
// System.out.printf("N: %d/%d : P %d/%d : R %d/%d\n", X, X2, P, P2,
// R, R2);
Pair<Integer, Record> pair = iter.next();
if (debug)
System.out.println("** Item: " + pair);
Record r = pair.cdr();
// The record is key-only (which is correct) but until FREC fixed,
// we need key,value
r = recordFactory.create(r.getKey());
// There is always one more ptr than record in a B+Tree node.
if (ptrBuff.isFull())
Log.error(this, "PtrBuffer is full");
// Add pointer.
ptrBuff.add(pair.car());
if (ptrBuff.isFull()) {
// Internal consistency check.
if (!ptrBuff.isFull())
Log.error(this, "PtrBuffer is not full");
// The split point for the next level up.
slot = new Pair<>(bptNode.getId(), pair.cdr());
if (debug)
System.out.printf("Write(1): %d\n", bptNode.getId());
if (debug)
System.out.println(bptNode);
if (debug)
System.out.println("Slot = " + slot);
mgr.put(bptNode);
// No count increment needed.
return true;
}
recBuff.add(r);
bptNode.setCount(bptNode.getCount() + 1);
}
// If we get here, the input stream ran out before we finished a
// complete block.
// Fix up block (remove the last record)
Record r = recBuff.getHigh();
recBuff.removeTop();
bptNode.setCount(bptNode.getCount() - 1);
slot = new Pair<>(bptNode.getId(), r);
if (debug)
System.out.printf("Write(2): %d\n", bptNode.getId());
if (debug)
System.out.println(bptNode);
if (debug)
System.out.println("Slot = " + slot);
mgr.put(bptNode);
return true;
}
use of org.apache.jena.dboe.trans.bplustree.BPTreeNode in project jena by apache.
the class BPlusTreeRewriterUtils method printIndexBlocks.
static Iterator<Pair<Integer, Record>> printIndexBlocks(Iterator<Pair<Integer, Record>> iter2, BPTreeNodeMgr bptNodeMgr) {
divider();
List<Pair<Integer, Record>> pairs = Iter.toList(iter2);
System.out.printf(">>Packed index blocks\n");
for (Pair<Integer, Record> pair : pairs) {
System.out.printf(" %s\n", pair);
BPTreeNode bpNode = bptNodeMgr.getRead(pair.car(), BPlusTreeParams.RootParent);
bpNode.setIsLeaf(true);
System.out.printf("BPTreeNode: %d\n", bpNode.getId());
System.out.println(bpNode);
bptNodeMgr.release(bpNode);
}
System.out.printf("<<Packed index blocks\n");
return pairs.iterator();
}
use of org.apache.jena.dboe.trans.bplustree.BPTreeNode in project jena by apache.
the class BPlusTreeRewriterUtils method summarizeIndexBlocks.
static Iterator<Pair<Integer, Record>> summarizeIndexBlocks(Iterator<Pair<Integer, Record>> iter2, BPTreeNodeMgr bptNodeMgr) {
divider();
List<Pair<Integer, Record>> pairs = Iter.toList(iter2);
for (Pair<Integer, Record> pair : pairs) {
BPTreeNode bpNode = bptNodeMgr.getRead(pair.car(), BPlusTreeParams.RootParent);
String hr = "null";
if (!bpNode.getRecordBuffer().isEmpty())
hr = bpNode.getRecordBuffer().getHigh().toString();
System.out.printf("%s -- BPTreeNode: %d (%d) -> [%s]\n", pair, bpNode.getId(), bpNode.getCount(), hr);
bptNodeMgr.release(bpNode);
}
return pairs.iterator();
}
Aggregations