use of org.apache.jena.tdb.base.record.Record in project jena by apache.
the class BPTreeNodeBuilder method next.
@Override
public Pair<Integer, Record> next() {
if (!hasNext())
throw new NoSuchElementException();
Pair<Integer, Record> x = slot;
slot = null;
return x;
}
use of org.apache.jena.tdb.base.record.Record 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();
// [Issue: FREC]
// The record buffer size is wrong.
// Writes the whole record, only need to write the key part.
// **** r = recordFactory.createKeyOnly(r) ;
// [Issue: FREC]
// 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())
System.err.println("PtrBuffer is full");
// Add pointer.
ptrBuff.add(pair.car());
// .... test ptrBuff
if (ptrBuff.isFull()) {
// Internal consistency check.
if (!ptrBuff.isFull())
System.err.println("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.tdb.base.record.Record in project jena by apache.
the class TestRecordBufferPage method fill.
private static void fill(RecordBuffer rb, int... nums) {
for (int num : nums) {
Record rec = record(num);
rb.add(rec);
}
}
use of org.apache.jena.tdb.base.record.Record in project jena by apache.
the class TestRecordBuffer method recBufferIterate05.
@Test
public void recBufferIterate05() {
RecordBuffer rb = make(3, 5);
Iterator<Record> iter = rb.iterator(intToRecord(1), null);
same(iter, 2, 4, 6);
}
use of org.apache.jena.tdb.base.record.Record in project jena by apache.
the class TestRecordBuffer method make.
private static RecordBuffer make(int n, int len) {
RecordBuffer rb = new RecordBuffer(recordFactory, len);
for (int i = 0; i < n; i++) {
Record r = RecordLib.intToRecord(2 * i + 2);
rb.add(r);
}
return rb;
}
Aggregations