some more performance hacks

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7533 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent b2f147d28e
commit b1781d7aae

@ -75,7 +75,7 @@ public class imagetest {
img.setColor(RasterPlotter.BLUE); img.setColor(RasterPlotter.BLUE);
img.dot(620, 200, 90, true, 100); img.dot(620, 200, 90, true, 100);
img.setColor(RasterPlotter.RED); img.setColor(RasterPlotter.RED);
img.arc(300, 270, 30, 70, 0, 360); img.arc(300, 270, 30, 70, 100);
img.setColor("330000"); img.setColor("330000");
img.arc(220, 110, 50, 90, 30, 110); img.arc(220, 110, 50, 90, 30, 110);
img.arc(210, 120, 50, 90, 30, 110); img.arc(210, 120, 50, 90, 30, 110);
@ -99,7 +99,7 @@ public class imagetest {
} }
}*/ }*/
img.setColor("0000A0"); img.setColor("0000A0");
img.arc(550, 400, 40, 81, 0, 360); img.arc(550, 400, 40, 81, 100);
img.setColor("010100"); img.setColor("010100");
for (int i = 0; i <= 360; i++) { for (int i = 0; i <= 360; i++) {
img.arc(550, 400, 40, 41 + i/9, 0, i); img.arc(550, 400, 40, 41 + i/9, 0, i);

@ -186,7 +186,7 @@ public class NetworkGraph {
// draw network circle // draw network circle
networkPicture.setColor(COL_DHTCIRCLE); networkPicture.setColor(COL_DHTCIRCLE);
networkPicture.arc(width / 2, height / 2, innerradius - 20, innerradius + 20, 0, 360); networkPicture.arc(width / 2, height / 2, innerradius - 20, innerradius + 20, 100);
//System.out.println("Seed Maximum distance is " + yacySeed.maxDHTDistance); //System.out.println("Seed Maximum distance is " + yacySeed.maxDHTDistance);
//System.out.println("Seed Minimum distance is " + yacySeed.minDHTNumber); //System.out.println("Seed Minimum distance is " + yacySeed.minDHTNumber);
@ -343,7 +343,7 @@ public class NetworkGraph {
img.arcArc(centerX, centerY, innerradius, angle, dotsize + radius, dotsize + radius, a, a + 180/segments); img.arcArc(centerX, centerY, innerradius, angle, dotsize + radius, dotsize + radius, a, a + 180/segments);
} }
} else { } else {
img.arcArc(centerX, centerY, innerradius, angle, dotsize + radius, dotsize + radius, 0, 360); img.arcArc(centerX, centerY, innerradius, angle, dotsize + radius, dotsize + radius, 100);
} }
} }
} }

@ -137,7 +137,7 @@ public class OSMTile {
// see http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames // see http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
this.zoom = zoom; this.zoom = zoom;
this.xtile = (int) Math.floor((lon + 180) / 360 * (1 << zoom)); this.xtile = (int) Math.floor((lon + 180) / 360 * (1 << zoom));
this.ytile = (int) Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * (1 << zoom)); this.ytile = (int) Math.floor((1 - Math.log(Math.tan(lat * RasterPlotter.PI180) + 1 / Math.cos(lat * RasterPlotter.PI180)) / Math.PI) / 2 * (1 << zoom));
} }
public tileCoordinates(final int xtile, final int ytile, final int zoom) { public tileCoordinates(final int xtile, final int ytile, final int zoom) {

@ -86,7 +86,12 @@ public class Gap extends TreeMap<Long, Integer> {
public int dump(File file) throws IOException { public int dump(File file) throws IOException {
File tmp = new File(file.getParentFile(), file.getName() + ".prt"); File tmp = new File(file.getParentFile(), file.getName() + ".prt");
Iterator<Map.Entry<Long, Integer>> i = this.entrySet().iterator(); Iterator<Map.Entry<Long, Integer>> i = this.entrySet().iterator();
DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(tmp), 4 * 1024 * 1024)); DataOutputStream os;
try {
os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(tmp), 4 * 1024 * 1024));
} catch (OutOfMemoryError e) {
os = new DataOutputStream(new FileOutputStream(tmp));
}
int c = 0; int c = 0;
Map.Entry<Long, Integer> e; Map.Entry<Long, Integer> e;
while (i.hasNext()) { while (i.hasNext()) {

@ -80,7 +80,12 @@ public final class HeapWriter {
this.heapFileREADY = readyHeapFile; this.heapFileREADY = readyHeapFile;
this.keylength = keylength; this.keylength = keylength;
this.index = new HandleMap(keylength, ordering, 8, 100000, readyHeapFile.getAbsolutePath()); this.index = new HandleMap(keylength, ordering, 8, 100000, readyHeapFile.getAbsolutePath());
try {
this.os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(temporaryHeapFile), outBuffer)); this.os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(temporaryHeapFile), outBuffer));
} catch (OutOfMemoryError e) {
// try this again without buffer
this.os = new DataOutputStream(new FileOutputStream(temporaryHeapFile));
}
this.seek = 0; this.seek = 0;
} }

@ -146,12 +146,17 @@ public class MapHeap implements Map<byte[], Map<String, String>> {
String s = map2string(newMap, "W" + my_SHORT_SECOND_FORMATTER.format() + " "); String s = map2string(newMap, "W" + my_SHORT_SECOND_FORMATTER.format() + " ");
assert s != null; assert s != null;
byte[] sb = s.getBytes(); byte[] sb = s.getBytes();
if (cache == null) {
// write entry
if (blob != null) blob.insert(key, sb);
} else {
synchronized (this) { synchronized (this) {
// write entry // write entry
if (blob != null) blob.insert(key, sb); if (blob != null) blob.insert(key, sb);
// write map to cache // write map to cache
if (cache != null) cache.put(key, newMap); cache.put(key, newMap);
}
} }
} }

@ -151,7 +151,12 @@ public final class HandleMap implements Iterable<Row.Entry> {
// everything much faster, but this is not an option here. // everything much faster, but this is not an option here.
final File tmp = new File(file.getParentFile(), file.getName() + ".prt"); final File tmp = new File(file.getParentFile(), file.getName() + ".prt");
final Iterator<Row.Entry> i = this.index.rows(true, null); final Iterator<Row.Entry> i = this.index.rows(true, null);
OutputStream os = new BufferedOutputStream(new FileOutputStream(tmp), 4 * 1024 * 1024); OutputStream os;
try {
os = new BufferedOutputStream(new FileOutputStream(tmp), 4 * 1024 * 1024);
} catch (OutOfMemoryError e) {
os = new FileOutputStream(tmp);
}
if (file.getName().endsWith(".gz")) os = new GZIPOutputStream(os); if (file.getName().endsWith(".gz")) os = new GZIPOutputStream(os);
int c = 0; int c = 0;
while (i.hasNext()) { while (i.hasNext()) {

@ -112,7 +112,12 @@ public final class HandleSet implements Iterable<byte[]>, Cloneable {
// otherwise we could just write the byte[] from the in kelondroRowSet which would make // otherwise we could just write the byte[] from the in kelondroRowSet which would make
// everything much faster, but this is not an option here. // everything much faster, but this is not an option here.
final Iterator<Row.Entry> i = this.index.rows(true, null); final Iterator<Row.Entry> i = this.index.rows(true, null);
final OutputStream os = new BufferedOutputStream(new FileOutputStream(file), 1024 * 1024); OutputStream os;
try {
os = new BufferedOutputStream(new FileOutputStream(file), 1024 * 1024);
} catch (OutOfMemoryError e) {
os = new FileOutputStream(file);
}
int c = 0; int c = 0;
while (i.hasNext()) { while (i.hasNext()) {
os.write(i.next().bytes()); os.write(i.next().bytes());

@ -101,7 +101,7 @@ public class CircleTool {
return circles[radius - 1]; return circles[radius - 1];
} }
public static void circle(final RasterPlotter matrix, final int xc, final int yc, final int radius, int intensity) { public static void circle(final RasterPlotter matrix, final int xc, final int yc, final int radius, final int intensity) {
if (radius == 0) { if (radius == 0) {
//matrix.plot(xc, yc, 100); //matrix.plot(xc, yc, 100);
} else { } else {

@ -111,8 +111,8 @@ public class PrintTool {
private static final int arcDist = 8; private static final int arcDist = 8;
public static void arcPrint(final RasterPlotter matrix, final int cx, final int cy, final int radius, final int angle, final String message) { public static void arcPrint(final RasterPlotter matrix, final int cx, final int cy, final int radius, final int angle, final String message) {
final int x = cx + (int) ((radius + 1) * Math.cos(Math.PI * angle / 180)); final int x = cx + (int) ((radius + 1) * Math.cos(RasterPlotter.PI180 * angle));
final int y = cy - (int) ((radius + 1) * Math.sin(Math.PI * angle / 180)); final int y = cy - (int) ((radius + 1) * Math.sin(RasterPlotter.PI180 * angle));
int yp = y + 3; int yp = y + 3;
if ((angle > arcDist) && (angle < 180 - arcDist)) yp = y; if ((angle > arcDist) && (angle < 180 - arcDist)) yp = y;
if ((angle > 180 + arcDist) && (angle < 360 - arcDist)) yp = y + 6; if ((angle > 180 + arcDist) && (angle < 360 - arcDist)) yp = y + 6;

@ -50,6 +50,8 @@ import net.yacy.kelondro.util.MemoryControl;
public class RasterPlotter { public class RasterPlotter {
public static final double PI180 = Math.PI / 180.0d;
// colors regarding RGB Color Model // colors regarding RGB Color Model
public static final long RED = 0xFF0000; public static final long RED = 0xFF0000;
public static final long GREEN = 0x00FF00; public static final long GREEN = 0x00FF00;
@ -211,8 +213,8 @@ public class RasterPlotter {
public void line( public void line(
int Ax, int Ay, final int Bx, final int By, int Ax, int Ay, final int Bx, final int By,
String colorLine, final int intensityLine, final String colorLine, final int intensityLine,
String colorDot, final int intensityDot, int dotDist, int dotPos, int dotRadius, boolean dotFilled final String colorDot, final int intensityDot, final int dotDist, final int dotPos, final int dotRadius, final boolean dotFilled
) { ) {
// Bresenham's line drawing algorithm // Bresenham's line drawing algorithm
int dX = Math.abs(Bx-Ax); int dX = Math.abs(Bx-Ax);
@ -301,7 +303,7 @@ public class RasterPlotter {
return grid.getPixel(x, y, c); return grid.getPixel(x, y, c);
} }
public void dot(final int x, final int y, final int radius, final boolean filled, int intensity) { public void dot(final int x, final int y, final int radius, final boolean filled, final int intensity) {
if (filled) { if (filled) {
for (int r = radius; r >= 0; r--) { for (int r = radius; r >= 0; r--) {
CircleTool.circle(this, x, y, r, intensity); CircleTool.circle(this, x, y, r, intensity);
@ -311,16 +313,21 @@ public class RasterPlotter {
} }
} }
public void arc(final int x, final int y, final int innerRadius, final int outerRadius, final int intensity) {
for (int r = innerRadius; r <= outerRadius; r++) {
CircleTool.circle(this, x, y, r, intensity);
}
}
public void arc(final int x, final int y, final int innerRadius, final int outerRadius, final int fromArc, final int toArc) { public void arc(final int x, final int y, final int innerRadius, final int outerRadius, final int fromArc, final int toArc) {
for (int r = innerRadius; r <= outerRadius; r++) { for (int r = innerRadius; r <= outerRadius; r++) {
CircleTool.circle(this, x, y, r, fromArc, toArc); CircleTool.circle(this, x, y, r, fromArc, toArc);
} }
} }
public void arcLine(final int cx, final int cy, final int innerRadius, final int outerRadius, final int angle, public void arcLine(final int cx, final int cy, final int innerRadius, final int outerRadius, final int angle, final boolean in,
boolean in, final String colorLine, final String colorDot, final int dotDist, final int dotPos, final int dotRadius, final boolean dotFilled) {
String colorLine, String colorDot, int dotDist, int dotPos, int dotRadius, boolean dotFilled) { final double a = PI180 * ((double) angle);
final double a = Math.PI * ((double) angle) / 180.0;
final double cosa = Math.cos(a); final double cosa = Math.cos(a);
final double sina = Math.sin(a); final double sina = Math.sin(a);
final int xi = cx + (int) (innerRadius * cosa); final int xi = cx + (int) (innerRadius * cosa);
@ -344,18 +351,17 @@ public class RasterPlotter {
} }
public void arcDot(final int cx, final int cy, final int arcRadius, final int angle, final int dotRadius) { public void arcDot(final int cx, final int cy, final int arcRadius, final int angle, final int dotRadius) {
final double a = Math.PI * ((double) angle) / 180.0; final double a = PI180 * ((double) angle);
final int x = cx + (int) (arcRadius * Math.cos(a)); final int x = cx + (int) (arcRadius * Math.cos(a));
final int y = cy - (int) (arcRadius * Math.sin(a)); final int y = cy - (int) (arcRadius * Math.sin(a));
dot(x, y, dotRadius, true, 100); dot(x, y, dotRadius, true, 100);
} }
public void arcConnect(final int cx, final int cy, final int arcRadius, final int angle1, final int angle2, public void arcConnect(final int cx, final int cy, final int arcRadius, final int angle1, final int angle2, final boolean in,
boolean in, final String colorLine, final int intensityLine,
String colorLine, final int intensityLine, final String colorDot, final int intensityDot, final int dotDist, final int dotPos, final int dotRadius, final boolean dotFilled) {
String colorDot, final int intensityDot, int dotDist, int dotPos, int dotRadius, boolean dotFilled) { final double a1 = PI180 * ((double) angle1);
final double a1 = Math.PI * ((double) angle1) / 180.0; final double a2 = PI180 * ((double) angle2);
final double a2 = Math.PI * ((double) angle2) / 180.0;
final int x1 = cx + (int) (arcRadius * Math.cos(a1)); final int x1 = cx + (int) (arcRadius * Math.cos(a1));
final int y1 = cy - (int) (arcRadius * Math.sin(a1)); final int y1 = cy - (int) (arcRadius * Math.sin(a1));
final int x2 = cx + (int) (arcRadius * Math.cos(a2)); final int x2 = cx + (int) (arcRadius * Math.cos(a2));
@ -371,8 +377,17 @@ public class RasterPlotter {
} }
} }
public void arcArc(final int cx, final int cy, final int arcRadius, final int angle, final int innerRadius, final int outerRadius, final int fromArc, final int toArc) { public void arcArc(final int cx, final int cy, final int arcRadius, final int angle,
final double a = Math.PI * ((double) angle) / 180.0; final int innerRadius, final int outerRadius, final int intensity) {
final double a = PI180 * ((double) angle);
final int x = cx + (int) (arcRadius * Math.cos(a));
final int y = cy - (int) (arcRadius * Math.sin(a));
arc(x, y, innerRadius, outerRadius, intensity);
}
public void arcArc(final int cx, final int cy, final int arcRadius, final int angle,
final int innerRadius, final int outerRadius, final int fromArc, final int toArc) {
final double a = PI180 * ((double) angle);
final int x = cx + (int) (arcRadius * Math.cos(a)); final int x = cx + (int) (arcRadius * Math.cos(a));
final int y = cy - (int) (arcRadius * Math.sin(a)); final int y = cy - (int) (arcRadius * Math.sin(a));
arc(x, y, innerRadius, outerRadius, fromArc, toArc); arc(x, y, innerRadius, outerRadius, fromArc, toArc);

Loading…
Cancel
Save