use of org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint in project tracecompass by tracecompass.
the class BTreeTest method testAccept.
/**
* Tests that accepts find the correct checkpoint and ends with a perfect
* match
*/
@Test
public void testAccept() {
for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(i), new TmfLongLocation(i), 0);
fBTree.insert(checkpoint);
}
final TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(123), new TmfLongLocation(123L), 0);
class TestVisitor implements IBTreeVisitor {
public int fLastCompare = 0;
ITmfCheckpoint fFoundCheckpoint;
@Override
public int compare(ITmfCheckpoint checkRec) {
fLastCompare = checkRec.compareTo(checkpoint);
if (fLastCompare == 0) {
fFoundCheckpoint = checkRec;
}
return fLastCompare;
}
}
final TestVisitor t = new TestVisitor();
fBTree.accept(t);
assertEquals(checkpoint, t.fFoundCheckpoint);
assertEquals(0, t.fLastCompare);
}
use of org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint in project tracecompass by tracecompass.
the class FlatArrayTest method testBinarySearch.
/**
* Tests that binarySearch find the correct checkpoint and ends with a
* perfect match
*/
@Test
public void testBinarySearch() {
for (long i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(i), new TmfLongLocation(i), 0);
fFlatArray.insert(checkpoint);
}
TmfCheckpoint expectedCheckpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(122), new TmfLongLocation(122L), 0);
int expectedRank = 122;
long rank = fFlatArray.binarySearch(expectedCheckpoint);
ITmfCheckpoint found = fFlatArray.get(rank);
assertEquals(expectedRank, rank);
assertEquals(found, expectedCheckpoint);
}
use of org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint in project tracecompass by tracecompass.
the class BTreeCheckpointVisitor method compare.
@Override
public int compare(ITmfCheckpoint currentCheckpoint) {
int compareTo = currentCheckpoint.compareTo(search);
if (compareTo <= 0 && !exactFound) {
rank = currentCheckpoint.getCheckpointRank();
found = currentCheckpoint;
if (compareTo == 0) {
exactFound = true;
}
}
return compareTo;
}
use of org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint in project tracecompass by tracecompass.
the class BTreeNode method serializeOut.
/**
* Write the node data to disk
*/
void serializeOut() {
try {
fTree.getRandomAccessFile().seek(fFileOffset);
ByteBuffer bb = fTree.getNodeByteBuffer();
bb.clear();
for (int i = 0; i < fTree.getMaxNumChildren(); ++i) {
bb.putLong(fChildrenFileOffsets[i]);
}
bb.putInt(fNumEntries);
for (int i = 0; i < fNumEntries; ++i) {
ITmfCheckpoint key = fEntries[i];
key.serialize(bb);
}
fTree.getRandomAccessFile().write(bb.array());
fIsDirty = false;
} catch (IOException e) {
Activator.logError(MessageFormat.format(Messages.BTreeNode_IOErrorWriting, fFileOffset, fTree.getRandomAccessFile()), e);
}
}
use of org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint in project tracecompass by tracecompass.
the class FlatArray method get.
/**
* Get a checkpoint from a rank
*
* @param rank
* the rank to search
* @return the checkpoint that has been found or null if not found
*/
public ITmfCheckpoint get(long rank) {
ITmfCheckpoint checkpoint = null;
try {
long pos = getHeader().getSize() + fCheckpointSize * rank;
if (getRandomAccessFile() == null) {
return null;
}
getRandomAccessFile().seek(pos);
fByteBuffer.clear();
getRandomAccessFile().read(fByteBuffer.array());
ITmfLocation location = getTrace().restoreLocation(fByteBuffer);
ITmfTimestamp timeStamp = TmfTimestamp.create(fByteBuffer);
checkpoint = new TmfCheckpoint(timeStamp, location, fByteBuffer);
} catch (IOException e) {
Activator.logError(MessageFormat.format(Messages.FlatArray_IOErrorReading, getFile()), e);
}
return checkpoint;
}
Aggregations