Skip to content

Commit

Permalink
- fix for termination problem with uniq()
Browse files Browse the repository at this point in the history
- addition to seed dna interpretation

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4208 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Nov 12, 2007
1 parent 0abf33e commit 64b3b79
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
25 changes: 19 additions & 6 deletions source/de/anomic/kelondro/kelondroRowCollection.java
Expand Up @@ -526,15 +526,28 @@ public synchronized void uniq() {
// this works only if the collection was ordered with sort before
// if the collection is large and the number of deletions is also large,
// then this method may run a long time with 100% CPU load which is caused
// by the large number of memory movements. Therefore it is possible
// to assign a runtime limitation
// by the large number of memory movements.
if (chunkcount < 2) return;
int i = chunkcount - 2;
while (i >= 0) {
if (compare(i, i + 1) == 0) {
removeRow(i, true);
long t = System.currentTimeMillis(); // for time-out
int d = 0;
boolean u = true;
try {
while (i >= 0) {
if (compare(i, i + 1) == 0) {
removeRow(i, false);
d++;
if (i < chunkcount - 2) u = false;
}
i--;
if (System.currentTimeMillis() - t > 10000) {
throw new RuntimeException("uniq() time-out at " + i + " (backwards) from " + chunkcount + " elements after " + (System.currentTimeMillis() - t) + " milliseconds; " + d + " deletions so far");
}
}
i--;
} catch (RuntimeException e) {
serverLog.logWarning("kelondroRowCollection", e.getMessage(), e);
} finally {
if (!u) this.sort();
}
}

Expand Down
8 changes: 6 additions & 2 deletions source/de/anomic/yacy/yacySeed.java
Expand Up @@ -333,11 +333,15 @@ public final String get(String key, String dflt) {
public final long getLong(String key, long dflt) {
final Object o = this.dna.get(key);
if (o == null) { return dflt; }
try {
if (o instanceof String) try {
return Long.parseLong((String) o);
} catch (NumberFormatException e) {
return dflt;
}
} else if (o instanceof Long) {
return ((Long) o).longValue();
} else if (o instanceof Integer) {
return (long) ((Integer) o).intValue();
} else return dflt;
}

public final void setIP() { dna.put(yacySeed.IP, ""); }
Expand Down

0 comments on commit 64b3b79

Please sign in to comment.