Author: jm
Date: 2012-04-18 16:58:24 -0700 (Wed, 18 Apr 2012)
New Revision: 28883
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/LongTHash.java
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/internal/LongTHashTest.java
Log:
Fix for #853: Changed calcPrevInx() so it doesn't enter into an infinite loop.
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/LongTHash.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/LongTHash.java
2012-04-18 23:57:22 UTC (rev 28882)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/LongTHash.java
2012-04-18 23:58:24 UTC (rev 28883)
@@ -168,7 +168,9 @@
//System.err.println("get " + key );
if (key != m_prevKey) {
- calcPrevInx(key,REUSABLE);
+ if (!calcPrevInx(key,REUSABLE)) {
+ return null;
+ }
m_prevKey = key;
}
@@ -179,6 +181,10 @@
public final T remove(final long key) {
//System.err.println("remove " + key );
Object ret = get(key);
+ if (ret == null) {
+ return null;
+ }
+
put(key,null);
m_elements--;
//dump("remove");
@@ -195,17 +201,23 @@
// for putting new values into the hash). If the threshold is set to
-1,
// then it will search all available indices (used for getting values
from
// the hash).
- private void calcPrevInx(long key, int threshold) {
+ private boolean calcPrevInx(long key, int threshold) {
int incr = 0;
+ int initialIndex = m_prevInx;
+
for (m_prevInx = (int)(key % (long)m_keys.length);
(m_keys[m_prevInx] >= threshold) && (m_keys[m_prevInx] !=
key);
m_prevInx = (m_prevInx + incr) % m_keys.length) {
+ if (initialIndex == m_prevInx) {
+ return false;
+ }
//System.err.println(" m_prevInx: " + m_prevInx);
if (incr == 0) {
incr = 1 + (int)(key % ((long)m_keys.length -
1));
}
}
+ return true;
}
private final void incrSize() {
Modified:
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/internal/LongTHashTest.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/internal/LongTHashTest.java
2012-04-18 23:57:22 UTC (rev 28882)
+++
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/internal/LongTHashTest.java
2012-04-18 23:58:24 UTC (rev 28883)
@@ -110,7 +110,7 @@
hash.put(11L, "A");
}
-// @Test
+ @Test
public void testTicket853() throws InterruptedException {
Thread thread = new Thread(new Runnable() {
@Override
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.