use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.
the class InnerCanvas method getChosenAnchor.
private long getChosenAnchor() {
m_ptBuff[0] = m_lastXMousePos;
m_ptBuff[1] = m_lastYMousePos;
m_view.xformComponentToNodeCoords(m_ptBuff);
final LongEnumerator hits = m_view.m_spacialA.queryOverlap((float) m_ptBuff[0], (float) m_ptBuff[1], (float) m_ptBuff[0], (float) m_ptBuff[1], null, 0, false);
long chosenAnchor = (hits.numRemaining() > 0) ? hits.nextLong() : (-1);
return chosenAnchor;
}
use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.
the class InnerCanvas method getChosenNode.
private long getChosenNode() {
m_ptBuff[0] = m_lastXMousePos;
m_ptBuff[1] = m_lastYMousePos;
m_view.xformComponentToNodeCoords(m_ptBuff);
m_stack.empty();
m_view.getNodesIntersectingRectangle((float) m_ptBuff[0], (float) m_ptBuff[1], (float) m_ptBuff[0], (float) m_ptBuff[1], (m_lastRenderDetail & GraphRenderer.LOD_HIGH_DETAIL) == 0, m_stack);
// Need to Z-sort this
long chosenNode = -1;
if (m_stack.size() > 0) {
LongEnumerator le = m_stack.elements();
DNodeView nv = null;
while (le.numRemaining() > 0) {
long thisNode = le.nextLong();
DNodeView dnv = m_view.getDNodeView(thisNode);
if (nv == null || dnv.getZPosition() > nv.getZPosition()) {
nv = dnv;
chosenNode = thisNode;
}
}
}
return chosenNode;
}
use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.
the class BasicQuietRTreeTestX method main.
/**
* DOCUMENT ME!
*
* @param args DOCUMENT ME!
*
* @throws Exception DOCUMENT ME!
* @throws IllegalStateException DOCUMENT ME!
*/
public static void main(String[] args) throws Exception {
RTree tree = new RTree(3);
for (int a = 0; ; a++) {
// BEGIN EMPTY TREE TESTS: We run our first tests when this tree empty.
float[] extentsArr = new float[4];
LongEnumerator iter = tree.queryOverlap(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, extentsArr, 0, false);
if (iter.numRemaining() != 0)
throw new IllegalStateException("did not expect query to generate results");
if ((extentsArr[0] != Float.POSITIVE_INFINITY) || (extentsArr[1] != Float.POSITIVE_INFINITY) || (extentsArr[2] != Float.NEGATIVE_INFINITY) || (extentsArr[3] != Float.NEGATIVE_INFINITY))
throw new IllegalStateException("expected query to return inverted infinite extents");
if (tree.exists(0, extentsArr, 0))
throw new IllegalStateException("did not expect there to be an entry");
if (tree.size() != 0)
throw new IllegalStateException("tree's size() is not 0");
if (a == 1)
break;
for (int j = 0; j < 1000; j++) {
final int stop = (j + 1) * 1000;
for (int k = j * 1000; k < stop; k++) tree.insert(k, k, k, k + 1, k + 1, 0.0);
for (int k = j * 1000; k < stop; k++) tree.delete(k);
}
}
// END EMPTY TREE TESTS.
tree.insert(0, 0.0f, 0.0f, 1.0f, 1.0f, 0.0);
tree.insert(1, 2.0f, 2.0f, 3.0f, 3.0f, 0.0);
tree.insert(2, 0.5f, 1.0f, 1.5f, 2.0f, 0.0);
for (int a = 0; ; a++) {
// BEGIN ROOT LEAF TEST: Still before any split.
float[] extentsArr = new float[5];
for (int i = 0; i < 3; i++) if (!tree.exists(i, extentsArr, 0))
throw new IllegalStateException("entry " + i + " does not exist");
if (tree.exists(3, extentsArr, 0))
throw new IllegalStateException("entry 3 exits");
if ((extentsArr[0] != 0.5) || (extentsArr[1] != 1.0) || (extentsArr[2] != 1.5) || (extentsArr[3] != 2.0))
throw new IllegalStateException("entry's extents don't match");
if (tree.size() != 3)
throw new IllegalStateException("tree's size() is not 3");
LongEnumerator iter = tree.queryOverlap(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, extentsArr, 0, false);
if (iter.numRemaining() != 3)
throw new IllegalStateException("expected query to generate 3 hits");
LongBTree cache = new LongBTree();
for (long i = 0; i < 3; i++) cache.insert(i);
int foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 3)
throw new IllegalStateException("iter claimed it had 3 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != 0.0) || (extentsArr[1] != 0.0) || (extentsArr[2] != 3.0) || (extentsArr[3] != 3.0))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(1.25f, 2.0f, 2.1f, 3.3f, extentsArr, 1, false);
if (iter.numRemaining() != 2)
throw new IllegalStateException("exptected query to return 2 hits");
cache.insert(1);
cache.insert(2);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 2)
throw new IllegalStateException("iter claimed it had 2 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[1] != 0.5) || (extentsArr[2] != 1.0) || (extentsArr[3] != 3.0) || (extentsArr[4] != 3.0))
throw new IllegalStateException("extents from query wrong");
if (a == 1)
break;
for (int j = 0; j < 1000; j++) {
final int stop = ((j + 1) * 1000) + 3;
for (int k = (j * 1000) + 3; k < stop; k++) tree.insert(k, -(k + 1), -(k + 1), -k, -k, 0.0);
for (int k = (j * 1000) + 3; k < stop; k++) tree.delete(k);
}
}
// END ROOT LEAF TEST.
tree.insert(3, 2.5f, 0.5f, 3.5f, 1.5f, 0.0);
for (int a = 0; ; a++) {
// BEGIN SIMPLE ROOT SPLIT TEST: Minimum # entries with a split.
float[] extentsArr = new float[4];
for (int i = 0; i < 4; i++) if (!tree.exists(i, extentsArr, 0))
throw new IllegalStateException("entry " + i + " does not exist");
if (tree.exists(4, extentsArr, 0))
throw new IllegalStateException("entry 4 exists");
if ((extentsArr[0] != 2.5) || (extentsArr[1] != 0.5) || (extentsArr[2] != 3.5) || (extentsArr[3] != 1.5))
throw new IllegalStateException("entry's extents incorrect");
if (tree.size() != 4)
throw new IllegalStateException("tree's size() is not 4");
LongEnumerator iter = tree.queryOverlap(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, extentsArr, 0, false);
if (iter.numRemaining() != 4)
throw new IllegalStateException("expected query to generate 4 hits");
LongBTree cache = new LongBTree();
for (int i = 0; i < 4; i++) cache.insert(i);
int foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 4)
throw new IllegalStateException("iter claimed it had 3 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != 0.0) || (extentsArr[1] != 0.0) || (extentsArr[2] != 3.5) || (extentsArr[3] != 3.0))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(2.0f, 0.5f, 2.2f, 1.9f, extentsArr, 0, false);
if (iter.numRemaining() != 0)
throw new IllegalStateException("expected query to generate 0 hits");
if ((extentsArr[0] != Float.POSITIVE_INFINITY) || (extentsArr[1] != Float.POSITIVE_INFINITY) || (extentsArr[2] != Float.NEGATIVE_INFINITY) || (extentsArr[3] != Float.NEGATIVE_INFINITY))
throw new IllegalStateException("query extents - expected inverted infinite");
iter = tree.queryOverlap(Float.NEGATIVE_INFINITY, 1.1f, Float.POSITIVE_INFINITY, 1.2f, extentsArr, 0, false);
if (iter.numRemaining() != 2)
throw new IllegalStateException("expected query to generate 2 hits");
cache.insert(2);
cache.insert(3);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 2)
throw new IllegalStateException("iter claimed it had 2 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("query returned wrong objKeys");
if ((extentsArr[0] != 0.5) || (extentsArr[1] != 0.5) || (extentsArr[2] != 3.5) || (extentsArr[3] != 2.0))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(1.0f, 1.0f, 1.0f, 1.0f, extentsArr, 0, false);
if (iter.numRemaining() != 2)
throw new IllegalStateException("expected query to generate 2 hits");
cache.insert(0);
cache.insert(2);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 2)
throw new IllegalStateException("iter claimed it had 2 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("query returned wrong objKeys");
if ((extentsArr[0] != 0.0) || (extentsArr[1] != 0.0) || (extentsArr[2] != 1.5) || (extentsArr[3] != 2.0))
throw new IllegalStateException("extents from query wrong");
if (a == 1)
break;
for (int j = 0; j < 1000; j++) {
final int stop = ((j + 1) * 1000) + 4;
for (int k = (j * 1000) + 4; k < stop; k++) tree.insert(k, k, -(k + 1), k + 3, -(k - 2), 0.0);
for (int k = (j * 1000) + 4; k < stop; k++) tree.delete(k);
}
}
// END SIMPLE ROOT SPLIT TEST.
{
// BEGIN EXCEPTION HANDLING TEST.
boolean exceptionCaught = false;
try {
tree.insert(0, 0.0f, 0.0f, 1.0f, 1.0f, 0.0);
} catch (IllegalStateException e) {
exceptionCaught = true;
}
if (!exceptionCaught)
throw new IllegalStateException("expected exception for duplicate objKey");
exceptionCaught = false;
try {
tree.insert(-1, 0.0f, 0.0f, 1.0f, 1.0f, 0.0);
} catch (IllegalArgumentException e) {
exceptionCaught = true;
}
if (!exceptionCaught)
throw new IllegalStateException("expected exception for negative objKey");
exceptionCaught = false;
try {
tree.insert(5, 1.0f, 1.0f, 0.0f, 0.0f, 0.0);
} catch (IllegalArgumentException e) {
exceptionCaught = true;
}
if (!exceptionCaught)
throw new IllegalStateException("expected exception for min > max");
}
// END EXCEPTION HANDLING TEST.
tree.insert(4, 3.0f, -0.25f, 4.0f, 0.75f, 0.0);
tree.insert(5, -0.5f, 2.5f, 0.5f, 3.5f, 0.0);
tree.insert(6, 2.75f, 2.25f, 3.75f, 3.25f, 0.0);
tree.insert(7, 1.25f, 1.75f, 2.25f, 2.75f, 0.0);
tree.insert(8, 1.0f, 6.0f, 2.0f, 7.0f, 0.0);
tree.insert(9, -2.0f, 1.0f, -1.0f, 2.0f, 0.0);
for (int a = 0; ; a++) {
// BEGIN DEPTH THREE TEST.
float[] extentsArr = new float[4];
for (int i = 9; i >= 0; i--) if (!tree.exists(i, extentsArr, 0))
throw new IllegalStateException("entry " + i + " does not exist");
if (tree.exists(-1, extentsArr, 0) || tree.exists(10, extentsArr, 0))
throw new IllegalStateException("bad entry exists");
if ((extentsArr[0] != 0.0) || (extentsArr[1] != 0.0) || (extentsArr[2] != 1.0) || (extentsArr[3] != 1.0))
throw new IllegalStateException("objKey 0 extents incorrect");
if (tree.size() != 10)
throw new IllegalStateException("tree's size() is not 10");
LongEnumerator iter = tree.queryOverlap(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, extentsArr, 0, false);
if (iter.numRemaining() != 10)
throw new IllegalStateException("expected query to generate 10 hits");
LongBTree cache = new LongBTree();
for (int i = 0; i < 10; i++) cache.insert(i);
int foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 10)
throw new IllegalStateException("iter claimed it had 10 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != -2.0) || (extentsArr[1] != -0.25) || (extentsArr[2] != 4.0) || (extentsArr[3] != 7.0))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(1.0f, 1.25f, 3.0f, 5.0f, extentsArr, 0, false);
if (iter.numRemaining() != 5)
throw new IllegalStateException("expected query to generate 5 hits");
cache.insert(1);
cache.insert(2);
cache.insert(3);
cache.insert(6);
cache.insert(7);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 5)
throw new IllegalStateException("iter claimed it had 5 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("query returned wrong objKeys");
if ((extentsArr[0] != 0.5) || (extentsArr[1] != 0.5) || (extentsArr[2] != 3.75) || (extentsArr[3] != 3.25))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(-1.5f, 0.25f, 0.25f, 3.0f, extentsArr, 0, false);
if (iter.numRemaining() != 3)
throw new IllegalStateException("expected query to generate 3 hits");
cache.insert(0);
cache.insert(5);
cache.insert(9);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 3)
throw new IllegalStateException("query claimed it had 3 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("query returned wrong objKeys");
if ((extentsArr[0] != -2.0) || (extentsArr[1] != 0.0) || (extentsArr[2] != 1.0) || (extentsArr[3] != 3.5))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(1.5f, 6.5f, 1.5f, 6.5f, extentsArr, 0, false);
if (iter.numRemaining() != 1)
throw new IllegalStateException("expected query to generate 1 hit");
cache.insert(8);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 1)
throw new IllegalStateException("query claimed it had 1 element but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("query returned wrong objKey");
if ((extentsArr[0] != 1.0) || (extentsArr[1] != 6.0) || (extentsArr[2] != 2.0) || (extentsArr[3] != 7.0))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(3.0f, 5.0f, 8.0f, 9.0f, extentsArr, 0, false);
if (iter.numRemaining() != 0)
throw new IllegalStateException("did not expect any query hits");
iter = tree.queryOverlap(-100.0f, -100.0f, -99.0f, -99.0f, extentsArr, 0, false);
if (iter.numRemaining() != 0)
throw new IllegalStateException("did not expect any query hits");
iter = tree.queryOverlap(-1.0f, 0.75f, 3.0f, 6.0f, extentsArr, 0, false);
if (iter.numRemaining() != 10)
throw new IllegalStateException("expected 10 query hits");
if (a == 1)
break;
for (int j = 0; j < 1000; j++) {
final int stop = ((j + 1) * 1000) + 10;
for (int k = (j * 1000) + 10; k < stop; k++) tree.insert(k, k, k, k + 2, k + 2, 0.0);
for (int k = (j * 1000) + 10; k < stop; k++) tree.delete(k);
}
}
for (int a = 0; ; a++) {
tree.insert(10, 2.0f, 4.0f, 3.0f, 5.0f, 0.0);
tree.insert(11, 1.5f, 3.75f, 3.5f, 4.25f, 0.0);
tree.insert(12, 2.5f, 3.5f, 3.0f, 5.5f, 0.0);
tree.insert(13, -4.0f, 6.0f, -2.0f, 8.0f, 0.0);
tree.insert(14, -4.25f, 5.75f, 2.25f, 8.25f, 0.0);
tree.insert(15, 2.0f, -1.0f, 2.0f, -1.0f, 0.0);
tree.insert(16, -1.25f, 0.5f, -1.25f, 3.0f, 0.0);
tree.insert(17, -0.5f, -0.5f, 1.5f, 0.5f, 0.0);
tree.insert(18, 0.25f, 4.0f, 1.25f, 5.0f, 0.0);
tree.insert(19, 4.0f, 1.0f, 5.0f, 2.0f, 0.0);
tree.insert(20, 4.0f, 3.0f, 5.0f, 4.0f, 0.0);
tree.insert(21, 4.25f, -1.5f, 4.75f, 5.0f, 0.0);
tree.insert(22, 3.0f, -1.75f, 5.0f, -1.0f, 0.0);
tree.insert(23, 1.25f, 0.25f, 2.25f, 1.25f, 0.0);
tree.insert(24, -2.0f, 9.0f, -1.0f, 10.0f, 0.0);
tree.insert(25, 1.0f, 9.0f, 2.0f, 10.0f, 0.0);
tree.insert(26, -2.0f, 5.0f, -1.0f, 6.0f, 0.0);
tree.insert(27, -2.5f, 5.25f, -1.75f, 9.25f, 0.0);
if (a == 1)
break;
for (int k = 10; k < 28; k++) tree.delete(k);
}
// There are now 28 entries in the R-tree. Depth must be at least 4.
{
// BEGIN SERIALIZATION TEST.
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(byteOut);
objOut.writeObject(tree);
objOut.flush();
objOut.close();
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
ObjectInputStream objIn = new ObjectInputStream(byteIn);
tree = (RTree) objIn.readObject();
objIn.close();
}
for (int a = 0; ; a++) {
// BEGIN DEPTH FOUR TEST.
float[] extentsArr = new float[4];
for (int i = 27; i >= 0; i--) if (!tree.exists(i, extentsArr, 0))
throw new IllegalStateException("entry " + i + " does not exist");
if (tree.exists(28, extentsArr, 0) || tree.exists(Integer.MAX_VALUE, extentsArr, 0) || tree.exists(Integer.MIN_VALUE, extentsArr, 0))
throw new IllegalStateException("bad entry exists");
if ((extentsArr[0] != 0.0) || (extentsArr[1] != 0.0) || (extentsArr[2] != 1.0) || (extentsArr[3] != 1.0))
throw new IllegalStateException("objKey 0 extents incorrect");
if (tree.size() != 28)
throw new IllegalStateException("tree's size() is not 28");
LongEnumerator iter = tree.queryOverlap(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, extentsArr, 0, false);
if (iter.numRemaining() != 28)
throw new IllegalStateException("expected query to give 28 hits");
LongBTree cache = new LongBTree();
for (int i = 0; i < 28; i++) cache.insert(i);
int foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 28)
throw new IllegalStateException("iter claimed it had 28 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != -4.25) || (extentsArr[1] != -1.75) || (extentsArr[2] != 5.0) || (extentsArr[3] != 10.0))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(-2.0f, 6.0f, -2.0f, 6.0f, extentsArr, 0, false);
if (iter.numRemaining() != 4)
throw new IllegalStateException("expected query to generate 4 hits");
cache.insert(13);
cache.insert(14);
cache.insert(26);
cache.insert(27);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 4)
throw new IllegalStateException("iter claimed it had 4 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != -4.25) || (extentsArr[1] != 5.0) || (extentsArr[2] != 2.25) || (extentsArr[3] != 9.25))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(2.5f, 3.75f, 6.0f, 6.0f, extentsArr, 0, false);
if (iter.numRemaining() != 5)
throw new IllegalStateException("expected query to generate 5 hits");
cache.insert(10);
cache.insert(11);
cache.insert(12);
cache.insert(20);
cache.insert(21);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 5)
throw new IllegalStateException("iter claimed it had 5 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != 1.5) || (extentsArr[1] != -1.5) || (extentsArr[2] != 5.0) || (extentsArr[3] != 5.5))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(1.75f, -1.5f, 3.25f, -0.5f, extentsArr, 0, false);
if (iter.numRemaining() != 2)
throw new IllegalStateException("expected query to generate 2 hits");
cache.insert(15);
cache.insert(22);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 2)
throw new IllegalStateException("iter claimed it had 2 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != 2.0) || (extentsArr[1] != -1.75) || (extentsArr[2] != 5.0) || (extentsArr[3] != -1.0))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(-3.0f, -5.0f, 7.0f, 2.75f, extentsArr, 0, false);
if (iter.numRemaining() != 16)
throw new IllegalStateException("expected query to generate 16 hits");
cache.insert(0);
cache.insert(1);
cache.insert(2);
cache.insert(3);
cache.insert(4);
cache.insert(5);
cache.insert(6);
cache.insert(7);
cache.insert(9);
cache.insert(15);
cache.insert(16);
cache.insert(17);
cache.insert(19);
cache.insert(21);
cache.insert(22);
cache.insert(23);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 16)
throw new IllegalStateException("iter claimed it had 16 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != -2.0) || (extentsArr[1] != -1.75) || (extentsArr[2] != 5.0) || (extentsArr[3] != 5.0))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(1.0f, 4.5f, 3.0f, 6.25f, extentsArr, 0, false);
if (iter.numRemaining() != 5)
throw new IllegalStateException("expected query to generate 5 hits");
cache.insert(8);
cache.insert(10);
cache.insert(12);
cache.insert(14);
cache.insert(18);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 5)
throw new IllegalStateException("iter claimed it had 5 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != -4.25) || (extentsArr[1] != 3.5) || (extentsArr[2] != 3.0) || (extentsArr[3] != 8.25))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(0.75f, 0.25f, 1.5f, 0.75f, extentsArr, 0, false);
if (iter.numRemaining() != 3)
throw new IllegalStateException("expected query to generate 3 hits");
cache.insert(0);
cache.insert(17);
cache.insert(23);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 3)
throw new IllegalStateException("iter claimed it had 3 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != -0.5) || (extentsArr[1] != -0.5) || (extentsArr[2] != 2.25) || (extentsArr[3] != 1.25))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(1.75f, -10.0f, 1.75f, 30.0f, extentsArr, 0, false);
if (iter.numRemaining() != 6)
throw new IllegalStateException("expected query to generate 6 hits");
cache.insert(7);
cache.insert(8);
cache.insert(11);
cache.insert(14);
cache.insert(23);
cache.insert(25);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 6)
throw new IllegalStateException("iter claimed it had 6 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != -4.25) || (extentsArr[1] != 0.25) || (extentsArr[2] != 3.5) || (extentsArr[3] != 10.0))
throw new IllegalStateException("extents from query wrong");
iter = tree.queryOverlap(0.75f, 3.0f, 1.75f, 3.5f, extentsArr, 0, false);
if (iter.numRemaining() != 0)
throw new IllegalStateException("did not expect query results");
iter = tree.queryOverlap(2.5f, 1.75f, 3.75f, 1.75f, null, -1, false);
if (iter.numRemaining() != 0)
throw new IllegalStateException("did not expect query results");
iter = tree.queryOverlap(-2.0f, -1.0f, 4.25f, 9.0f, extentsArr, 0, false);
if (iter.numRemaining() != 28)
throw new IllegalStateException("expected 28 (all) query hits");
for (int i = 0; i < 28; i++) cache.insert(i);
foo = 0;
while (iter.numRemaining() > 0) {
cache.delete(iter.nextLong());
foo++;
}
if (foo != 28)
throw new IllegalStateException("iter claimed it had 28 elements but really didn't");
if (cache.size() != 0)
throw new IllegalStateException("iter returned wrong objKeys");
if ((extentsArr[0] != -4.25) || (extentsArr[1] != -1.75) || (extentsArr[2] != 5.0) || (extentsArr[3] != 10.0))
throw new IllegalStateException("extents from query wrong");
if (a == 1)
break;
for (int j = 0; j < 1000; j++) {
final int stop = ((j + 1) * 1000) + 28;
for (int k = (j * 1000) + 28; k < stop; k++) tree.insert(k, k, k, k + 5, k + 5, 0.0);
for (int k = (j * 1000) + 28; k < stop; k++) tree.delete(k);
}
}
// END DEPTH FOUR TEST.
{
if (tree.size() != 28)
throw new IllegalStateException("expected 28 elements in tree");
final long[] allOrdered = new long[28];
LongEnumerator iter = tree.queryOverlap(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, null, 0, false);
if (iter.numRemaining() != 28)
throw new IllegalStateException("expected 28 elements in iteration");
for (int i = 0; i < 28; i++) allOrdered[i] = iter.nextLong();
iter = tree.queryOverlap(0.0f, 0.0f, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, null, 0, false);
if (iter.numRemaining() != 20)
throw new IllegalStateException("expected 20 elements in iteration");
int prevInx = -1;
for (int i = 0; i < 20; i++) {
final long element = iter.nextLong();
int foundInx = -2;
for (int j = 0; ; j++) {
if (allOrdered[j] == element) {
foundInx = j;
break;
}
}
if (!(foundInx > prevInx)) {
throw new IllegalStateException("order in subquery not preserved");
}
prevInx = foundInx;
}
if (iter.numRemaining() != 0)
throw new IllegalStateException("more elements remain in iteration");
iter = tree.queryOverlap(-10.0f, -5.0f, 1.0f, 4.0f, null, 0, false);
if (iter.numRemaining() != 7)
throw new IllegalStateException("expected 7 elements in iteration");
prevInx = -1;
for (int i = 0; i < 7; i++) {
final long element = iter.nextLong();
int foundInx = -2;
for (int j = 0; ; j++) {
if (allOrdered[j] == element) {
foundInx = j;
break;
}
}
if (!(foundInx > prevInx)) {
throw new IllegalStateException("order in subquery not preserved");
}
prevInx = foundInx;
}
if (iter.numRemaining() != 0)
throw new IllegalStateException("more elements remain in iteration");
iter = tree.queryOverlap(-99.0f, -5.0f, 1.0f, 30.0f, null, 0, false);
if (iter.numRemaining() != 14)
throw new IllegalStateException("expected 14 elements in iteration");
prevInx = -1;
for (int i = 0; i < 14; i++) {
final long element = iter.nextLong();
int foundInx = -2;
for (int j = 0; ; j++) {
if (allOrdered[j] == element) {
foundInx = j;
break;
}
}
if (!(foundInx > prevInx)) {
throw new IllegalStateException("order in subquery not preserved");
}
prevInx = foundInx;
}
if (iter.numRemaining() != 0)
throw new IllegalStateException("more elements remain in iteration");
iter = tree.queryOverlap(-3.0f, 4.0f, 10.0f, 20.0f, null, 0, false);
if (iter.numRemaining() != 13)
throw new IllegalStateException("expected 13 elements in iteration");
prevInx = -1;
for (int i = 0; i < 13; i++) {
final long element = iter.nextLong();
int foundInx = -2;
for (int j = 0; ; j++) {
if (allOrdered[j] == element) {
foundInx = j;
break;
}
}
if (!(foundInx > prevInx)) {
throw new IllegalStateException("order in subquery not preserved");
}
prevInx = foundInx;
}
if (iter.numRemaining() != 0)
throw new IllegalStateException("more elements remain in iteration");
}
// END ORDER-PRESERVING SUBQUERY TEST.
{
if (tree.size() != 28)
throw new IllegalStateException("expected 28 elements in tree");
final long[] allOrdered = new long[28];
LongEnumerator iter = tree.queryOverlap(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, null, 0, false);
if (iter.numRemaining() != 28)
throw new IllegalStateException("expected 28 elements in iteration");
for (int i = 0; i < 28; i++) allOrdered[i] = iter.nextLong();
iter = tree.queryOverlap(0.0f, 0.0f, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, null, 0, true);
if (iter.numRemaining() != 20)
throw new IllegalStateException("expected 20 elements in iteration");
int prevInx = Integer.MAX_VALUE - 1;
for (int i = 0; i < 20; i++) {
final long element = iter.nextLong();
int foundInx = Integer.MAX_VALUE;
for (int j = 0; ; j++) {
if (allOrdered[j] == element) {
foundInx = j;
break;
}
}
if (!(foundInx < prevInx)) {
throw new IllegalStateException("not reverse order");
}
prevInx = foundInx;
}
if (iter.numRemaining() != 0)
throw new IllegalStateException("more elements remain in iteration");
iter = tree.queryOverlap(-10.0f, -5.0f, 1.0f, 4.0f, null, 0, true);
if (iter.numRemaining() != 7)
throw new IllegalStateException("expected 7 elements in iteration");
prevInx = Integer.MAX_VALUE - 1;
for (int i = 0; i < 7; i++) {
final long element = iter.nextLong();
int foundInx = Integer.MAX_VALUE;
for (int j = 0; ; j++) {
if (allOrdered[j] == element) {
foundInx = j;
break;
}
}
if (!(foundInx < prevInx)) {
throw new IllegalStateException("not reverse order");
}
prevInx = foundInx;
}
if (iter.numRemaining() != 0)
throw new IllegalStateException("more elements remain in iteration");
iter = tree.queryOverlap(-99.0f, -5.0f, 1.0f, 30.0f, null, 0, true);
if (iter.numRemaining() != 14)
throw new IllegalStateException("expected 14 elements in iteration");
prevInx = Integer.MAX_VALUE - 1;
for (int i = 0; i < 14; i++) {
final long element = iter.nextLong();
int foundInx = Integer.MAX_VALUE;
for (int j = 0; ; j++) {
if (allOrdered[j] == element) {
foundInx = j;
break;
}
}
if (!(foundInx < prevInx)) {
throw new IllegalStateException("not reverse order");
}
prevInx = foundInx;
}
if (iter.numRemaining() != 0)
throw new IllegalStateException("more elements remain in iteration");
iter = tree.queryOverlap(-3.0f, 4.0f, 10.0f, 20.0f, null, 0, true);
if (iter.numRemaining() != 13)
throw new IllegalStateException("expected 13 elements in iteration");
prevInx = Integer.MAX_VALUE - 1;
for (int i = 0; i < 13; i++) {
final long element = iter.nextLong();
int foundInx = Integer.MAX_VALUE;
for (int j = 0; ; j++) {
if (allOrdered[j] == element) {
foundInx = j;
break;
}
}
if (!(foundInx < prevInx)) {
throw new IllegalStateException("not reverse order");
}
prevInx = foundInx;
}
if (iter.numRemaining() != 0)
throw new IllegalStateException("more elements remain in iteration");
}
// END REVERSE QUERY TEST.
}
use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.
the class RTreeQueryPerformance method main.
/**
* For given N, creates N rectangles whose centers are in the space
* [0,1] X [0,1]. Each rectangle has width and height no greater
* than 1/sqrt(N). The location of the centers of the rectangles
* and the choice of width and height for each rectangle is determined
* by the input stream, which in most cases will be a randomly generated
* stream of bytes. Please see the actual code for an explanation of
* how the input stream of bytes is converted into the rectangle
* information.
*/
public static void main(String[] args) throws Exception {
final RTree tree;
// Populate the tree with entries.
{
int branches = Integer.parseInt(args[0]);
int N = Integer.parseInt(args[1]);
tree = new RTree(branches);
double sqrtN = Math.sqrt((double) N);
InputStream in = System.in;
byte[] buff = new byte[16];
int inx = 0;
int off = 0;
int read;
while ((inx < N) && ((read = in.read(buff, off, buff.length - off)) > 0)) {
off += read;
if (off < buff.length)
continue;
else
off = 0;
int nonnegative = 0x7fffffff & assembleInt(buff, 0);
double centerX = ((double) nonnegative) / ((double) 0x7fffffff);
nonnegative = 0x7fffffff & assembleInt(buff, 4);
double centerY = ((double) nonnegative) / ((double) 0x7fffffff);
nonnegative = 0x7fffffff & assembleInt(buff, 8);
double width = (((double) nonnegative) / ((double) 0x7fffffff)) / sqrtN;
nonnegative = 0x7fffffff & assembleInt(buff, 12);
double height = (((double) nonnegative) / ((double) 0x7fffffff)) / sqrtN;
tree.insert(inx, (float) (centerX - (width / 2.0d)), (float) (centerY - (height / 2.0d)), (float) (centerX + (width / 2.0d)), (float) (centerY + (height / 2.0d)), 0.0);
inx++;
}
if (inx < N)
throw new IOException("premature end of input");
}
final MinLongHeap[] pointQueries;
// Test 121 Point queries.
{
pointQueries = new MinLongHeap[121];
for (int i = 0; i < pointQueries.length; i++) pointQueries[i] = new MinLongHeap();
for (int i = 0; i < 3; i++) {
System.gc();
Thread.sleep(1000);
}
final long millisBegin = System.currentTimeMillis();
int inx = 0;
float currX = -0.1f;
for (int i = 0; i < 11; i++) {
currX += 0.1f;
float currY = -0.1f;
for (int j = 0; j < 11; j++) {
currY += 0.1f;
final LongEnumerator iter = tree.queryOverlap(currX, currY, currX, currY, null, 0, false);
final MinLongHeap heap = pointQueries[inx++];
while (iter.numRemaining() > 0) heap.toss(iter.nextLong());
}
}
final long millisEnd = System.currentTimeMillis();
System.err.println("point queries took " + (millisEnd - millisBegin) + " milliseconds");
}
final MinLongHeap[] areaQueries;
// Test 5 area queries - each area is 0.1 X 0.1.
{
areaQueries = new MinLongHeap[5];
for (int i = 0; i < areaQueries.length; i++) areaQueries[i] = new MinLongHeap();
for (int i = 0; i < 3; i++) {
System.gc();
Thread.sleep(1000);
}
final long millisBegin = System.currentTimeMillis();
for (int i = 0; i < 5; i++) {
final LongEnumerator iter = tree.queryOverlap(((float) i) * 0.1f, ((float) i) * 0.1f, ((float) (i + 1)) * 0.1f, ((float) (i + 1)) * 0.1f, null, 0, false);
final MinLongHeap heap = areaQueries[i];
while (iter.numRemaining() > 0) heap.toss(iter.nextLong());
}
final long millisEnd = System.currentTimeMillis();
System.err.println("area queries took " + (millisEnd - millisBegin) + " milliseconds");
}
final int[] countQueries;
// Test 5 count queries - each area is 0.6 X 0.6.
{
countQueries = new int[5];
for (int i = 0; i < 3; i++) {
System.gc();
Thread.sleep(1000);
}
final long millisBegin = System.currentTimeMillis();
for (int i = 0; i < 5; i++) {
final LongEnumerator iter = tree.queryOverlap(((float) i) * 0.1f, ((float) i) * 0.1f, ((float) (i + 6)) * 0.1f, ((float) (i + 6)) * 0.1f, null, 0, false);
countQueries[i] = iter.numRemaining();
}
final long millisEnd = System.currentTimeMillis();
System.err.println("count queries took " + (millisEnd - millisBegin) + " milliseconds");
}
for (int i = 0; i < pointQueries.length; i++) {
final MinLongHeap heap = pointQueries[i];
while (heap.size() > 0) System.out.print(" " + heap.deleteMin());
System.out.println();
}
for (int i = 0; i < areaQueries.length; i++) {
final MinLongHeap heap = areaQueries[i];
while (heap.size() > 0) System.out.print(" " + heap.deleteMin());
System.out.println();
}
for (int i = 0; i < countQueries.length; i++) {
System.out.println(countQueries[i]);
}
}
Aggregations