use of org.apache.jena.dboe.base.record.Record in project jena by apache.
the class TestBPTreeRecordsNonTxn method check.
protected static void check(BPTreeRecords bpr) {
assertTrue(bpr.getCount() >= 0);
assertTrue(bpr.getCount() <= bpr.getMaxSize());
assertEquals(bpr.getRecordBuffer().getLow(), bpr.getLowRecord());
assertEquals(bpr.getRecordBuffer().getHigh(), bpr.getHighRecord());
for (int i = 1; i < bpr.getCount(); i++) {
Record r1 = bpr.getRecordBuffer().get(i - 1);
Record r2 = bpr.getRecordBuffer().get(i);
assertTrue(Record.keyLE(r1, r2));
}
}
use of org.apache.jena.dboe.base.record.Record in project jena by apache.
the class TestBPTreeRecordsNonTxn method bpt_shift_2.
@Test
public void bpt_shift_2() {
BPTreeRecords bpr1 = make();
BPTreeRecords bpr2 = make();
insert(bpr1, 10);
Record r = bpr2.shiftLeft(bpr1, null);
assertTrue(Record.keyEQ(r, RecordLib.intToRecord(10)));
contains(bpr1);
contains(bpr2, 10);
bpr1.release();
bpr2.release();
}
use of org.apache.jena.dboe.base.record.Record in project jena by apache.
the class TestBPTreeRecordsNonTxn method bpt_records_6.
@Test
public void bpt_records_6() {
BPTreeRecords bpr = make();
fill(bpr);
// No match.
assertNull(search(bpr, RecordLib.intToRecord(0x20)));
Record r = RecordLib.intToRecord(0x32);
Record r2 = search(bpr, r);
assertTrue(Record.keyEQ(r, r2));
r = bpr.getLowRecord();
r2 = search(bpr, r);
assertTrue(Record.keyEQ(r, r2));
r = bpr.getHighRecord();
r2 = search(bpr, r);
assertTrue(Record.keyEQ(r, r2));
bpr.release();
}
use of org.apache.jena.dboe.base.record.Record in project jena by apache.
the class TestBPTreeRecordsNonTxn method bpt_shift_1.
@Test
public void bpt_shift_1() {
BPTreeRecords bpr1 = make();
BPTreeRecords bpr2 = make();
insert(bpr1, 10);
Record r = bpr1.shiftRight(bpr2, null);
assertNull(r);
// assertTrue(Record.keyEQ(r, RecordTestLib.intToRecord(10)));
contains(bpr1);
contains(bpr2, 10);
bpr1.release();
bpr2.release();
}
use of org.apache.jena.dboe.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();
// 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;
}
Aggregations