GP-691: Fixed R*-Tree implementation (closes #2760)

This commit is contained in:
Dan 2021-02-16 10:09:30 -05:00
parent 56f3f5c656
commit 8db624109a
7 changed files with 131 additions and 20 deletions

View file

@ -23,6 +23,7 @@ import java.util.function.Predicate;
import com.google.common.collect.Range;
import ghidra.lifecycle.Internal;
import ghidra.program.model.address.*;
import ghidra.trace.database.map.DBTraceAddressSnapRangePropertyMap.DBTraceAddressSnapRangePropertyMapDataFactory;
import ghidra.trace.database.map.DBTraceAddressSnapRangePropertyMapTree.AbstractDBTraceAddressSnapRangePropertyMapData;
@ -200,4 +201,12 @@ public class DBTraceAddressSnapRangePropertyMapSpace<T, DR extends AbstractDBTra
public DR getDataByKey(long key) {
return tree.getDataByKey(key);
}
/**
* For developers and testers.
*/
@Internal
public void checkIntegrity() {
tree.checkIntegrity();
}
}

View file

@ -599,7 +599,7 @@ public class DBTraceAddressSnapRangePropertyMapTree<T, DR extends AbstractDBTrac
}
protected void doInsertDataEntry(DR entry) {
super.doInsert(entry, leafLevel, new BitSet());
super.doInsert(entry, new LevelInfo(leafLevel));
}
public DBTraceAddressSnapRangePropertyMapSpace<T, DR> getMapSpace() {

View file

@ -61,7 +61,12 @@ public class TraceAddressSnapSpace implements EuclideanSpace2D<Address, Long> {
@Override
public double distX(Address x1, Address x2) {
return UnsignedUtils.unsignedLongToDouble(x2.subtract(x1));
if (x2.compareTo(x1) > 0) {
return UnsignedUtils.unsignedLongToDouble(x2.subtract(x1));
}
else {
return UnsignedUtils.unsignedLongToDouble(x1.subtract(x2));
}
}
@Override
@ -72,7 +77,12 @@ public class TraceAddressSnapSpace implements EuclideanSpace2D<Address, Long> {
if (y1 == null) {
return Double.NEGATIVE_INFINITY;
}
return y2 - y1;
if (y2 > y1) {
return y2 - y1;
}
else {
return y1 - y2;
}
}
@Override

View file

@ -964,4 +964,23 @@ public abstract class AbstractDBTraceMemoryManagerTest
frame.getValue(0, r0).getUnsignedValue());
}
}
/**
* This test is based on the MWE submitted in GitHub issue #2760.
*/
@Test
public void testManyStateEntries() throws Exception {
Register pc = toyLanguage.getRegister("pc");
DBTraceThread thread;
try (UndoableTransaction tid = UndoableTransaction.start(trace, "Testing", true)) {
thread = trace.getThreadManager().addThread("Thread1", Range.atLeast(0L));
DBTraceMemoryRegisterSpace regs = memory.getMemoryRegisterSpace(thread, true);
for (int i = 1; i < 2000; i++) {
//System.err.println("Snap " + i);
regs.setState(i, pc, TraceMemoryState.KNOWN);
//regs.stateMapSpace.checkIntegrity();
}
}
}
}