Skip to content

Commit

Permalink
- more asserts
Browse files Browse the repository at this point in the history
- better memory usage during remove in kelondroRowSet

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3022 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Nov 30, 2006
1 parent 7dbcd35 commit 4ce5906
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion htroot/IndexControl_p.java
Expand Up @@ -396,7 +396,7 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
seed = (yacySeed) e.nextElement();
if (seed != null) {
prop.put("hosts_" + hc + "_hosthash", seed.hash);
prop.put("hosts_" + hc + "_hostname", /*seed.hash + " " +*/ seed.get(yacySeed.NAME, "nameless"));
prop.put("hosts_" + hc + "_hostname", seed.hash + " " + seed.get(yacySeed.NAME, "nameless"));
hc++;
}
}
Expand Down
30 changes: 23 additions & 7 deletions source/de/anomic/kelondro/kelondroRowCollection.java
Expand Up @@ -269,17 +269,33 @@ public final void addAll(kelondroRowCollection c) {
}

protected final void removeShift(int pos, int dist, int upBound) {
assert ((pos + dist) * rowdef.objectsize() >= 0) : "pos = " + pos + ", dist = " + dist + ", rowdef.objectsize() = " + rowdef.objectsize;
assert (pos * rowdef.objectsize() >= 0) : "pos = " + pos + ", rowdef.objectsize() = " + rowdef.objectsize;
assert ((pos + dist) * rowdef.objectsize() + (upBound - pos - dist) * rowdef.objectsize() <= chunkcache.length) : "pos = " + pos + ", dist = " + dist + ", rowdef.objectsize() = " + rowdef.objectsize + ", upBound = " + upBound + ", chunkcache.length = " + chunkcache.length;
assert (pos * rowdef.objectsize() + (upBound - pos - dist) * rowdef.objectsize() <= chunkcache.length) : "pos = " + pos + ", dist = " + dist + ", rowdef.objectsize() = " + rowdef.objectsize + ", upBound = " + upBound + ", chunkcache.length = " + chunkcache.length;
System.arraycopy(chunkcache, (pos + dist) * rowdef.objectsize(),
chunkcache, pos * rowdef.objectsize(),
(upBound - pos - dist) * rowdef.objectsize());
}

public final void removeShift(int p) {
assert ((p >= 0) && (p < chunkcount) && (chunkcount > 0));
//System.out.println("REMOVE at pos " + p + ", chunkcount=" + chunkcount + ", sortBound=" + sortBound);
protected final void copytop(int i) {
// copies the topmost row element to given position
if (i == chunkcount - 1) return;
System.arraycopy(chunkcache, this.rowdef.objectsize() * (chunkcount - 1), chunkcache, this.rowdef.objectsize() * i, this.rowdef.objectsize());
}

protected final void removeRow(int p) {
assert ((p >= 0) && (p < chunkcount) && (chunkcount > 0)) : "p = " + p + ", chunkcount = " + chunkcount;
synchronized (chunkcache) {
if (p < sortBound) sortBound--;
removeShift(p, 1, chunkcount--);
if (p < sortBound) {
sortBound--;
removeShift(p, 1, chunkcount);
chunkcount--;
} else {
copytop(p);
chunkcount--;
}

}
this.lastTimeWrote = System.currentTimeMillis();
}
Expand Down Expand Up @@ -328,7 +344,7 @@ public Object next() {

public void remove() {
p--;
removeShift(p);
removeRow(p);
}
}

Expand Down Expand Up @@ -466,7 +482,7 @@ public void uniq() {
while (i < chunkcount - 1) {
if (compare(i, i + 1) == 0) {
//System.out.println("DOUBLE: " + new String(this.chunkcache, this.chunksize * i, this.chunksize));
removeShift(i);
removeRow(i);
} else {
i++;
}
Expand Down
4 changes: 2 additions & 2 deletions source/de/anomic/kelondro/kelondroRowSet.java
Expand Up @@ -154,8 +154,8 @@ private kelondroRow.Entry removeMarked(byte[] a, int astart, int alength) {
if (removeMarker.size() > removeMaxSize) resolveMarkedRemoved();
} else {
// remove directly by swap
if (chunkcount == sortBound) sortBound--;
super.swap(p, --chunkcount, 0);
super.copytop(p);
chunkcount--;
}

profile.stopDelete(handle);
Expand Down

0 comments on commit 4ce5906

Please sign in to comment.