Merge branch 'master' of git://github.com/f1ori/yacy

This commit is contained in:
admin 2011-12-01 00:01:03 +01:00
commit 63edf4025d
2 changed files with 35 additions and 10 deletions

View File

@ -63,6 +63,8 @@ import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.ASCII;
import net.yacy.cora.document.UTF8;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.ranking.ClusteredScoreMap;
import net.yacy.cora.ranking.ScoreMap;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.order.Base64Order;
@ -689,7 +691,7 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed> {
private static byte[] bestGap(final SeedDB seedDB) {
final byte[] randomHash = randomHash();
if ((seedDB == null) || (seedDB.sizeConnected() <= 2)) {
if (seedDB == null || seedDB.sizeConnected() <= 2) {
// use random hash
return randomHash;
}
@ -718,6 +720,10 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed> {
byte[] combined = new byte[12];
System.arraycopy(computedHash, 0, combined, 0, 2);
System.arraycopy(randomHash, 2, combined, 2, 10);
// patch for the 'first sector' problem
if (combined[0] == 'A' || combined[1] == 'D') { // for some strange reason there are too many of them
combined[1] = randomHash[1];
}
// finally check if the hash is already known
while (seedDB.hasConnected(combined) || seedDB.hasDisconnected(combined) || seedDB.hasPotential(combined)) {
// if we are lucky then this loop will never run
@ -932,4 +938,17 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed> {
return o1.compareTo(o2);
}
public static void main(final String[] args) {
final ScoreMap<Integer> s = new ClusteredScoreMap<Integer>();
for (int i = 0; i < 10000; i++) {
final byte[] b = randomHash();
s.inc(0xff & Base64Order.enhancedCoder.decodeByte(b[0]));
//System.out.println(ASCII.String(b));
}
final Iterator<Integer> i = s.keys(false);
while (i.hasNext()) {
System.out.println(i.next());
}
}
}

View File

@ -52,6 +52,8 @@ import net.yacy.visualization.RasterPlotter;
public class NetworkGraph {
private final static double DOUBLE_LONG_MAX_VALUE = Long.MAX_VALUE;
private static int shortestName = 10;
private static int longestName = 30;
@ -88,8 +90,8 @@ public class NetworkGraph {
this.color = color;
}
public int getAngle() { return Math.round(360f*this.fraction); }
public int getFractionPercent() { return Math.round(100f*this.fraction); }
public int getAngle() { return Math.round(360.0f * this.fraction); }
public int getFractionPercent() { return Math.round(100.0f * this.fraction); }
public Color getColor() { return this.color; }
public long getExecTime() { return this.execTime; }
public String getPieceName() { return this.pieceName; }
@ -137,7 +139,7 @@ public class NetworkGraph {
for (final RemoteSearch primarySearche : primarySearches) {
if (primarySearche == null) continue;
eventPicture.setColor((primarySearche.isAlive()) ? RasterPlotter.RED : RasterPlotter.GREEN);
angle = cyc + (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(UTF8.getBytes(primarySearche.target().hash), null)) / ((double) Long.MAX_VALUE)));
angle = cyc + (360.0d * ((FlatWordPartitionScheme.std.dhtPosition(UTF8.getBytes(primarySearche.target().hash), null)) / DOUBLE_LONG_MAX_VALUE));
eventPicture.arcLine(cx, cy, cr - 20, cr, angle, true, null, null, -1, -1, -1, false);
}
@ -146,7 +148,7 @@ public class NetworkGraph {
for (final RemoteSearch secondarySearche : secondarySearches) {
if (secondarySearche == null) continue;
eventPicture.setColor((secondarySearche.isAlive()) ? RasterPlotter.RED : RasterPlotter.GREEN);
angle = cyc + (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(UTF8.getBytes(secondarySearche.target().hash), null)) / ((double) Long.MAX_VALUE)));
angle = cyc + (360.0d * ((FlatWordPartitionScheme.std.dhtPosition(UTF8.getBytes(secondarySearche.target().hash), null)) / DOUBLE_LONG_MAX_VALUE));
eventPicture.arcLine(cx, cy, cr - 10, cr, angle - 1.0, true, null, null, -1, -1, -1, false);
eventPicture.arcLine(cx, cy, cr - 10, cr, angle + 1.0, true, null, null, -1, -1, -1, false);
}
@ -159,7 +161,7 @@ public class NetworkGraph {
while (i.hasNext()) {
final long[] positions = seedDB.scheme.dhtPositions(i.next());
for (final long position : positions) {
angle = cyc + (360.0 * (((double) position) / ((double) Long.MAX_VALUE)));
angle = cyc + (360.0d * ((position) / DOUBLE_LONG_MAX_VALUE));
eventPicture.arcLine(cx, cy, cr - 20, cr, angle, true, null, null, -1, -1, -1, false);
}
}
@ -207,6 +209,9 @@ public class NetworkGraph {
Log.logWarning("NetworkGraph", "connected seed == null");
continue;
}
if (seed.hash.startsWith("AD")) {//temporary patch
continue;
}
//Log.logInfo("NetworkGraph", "drawing peer " + seed.getName());
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, COL_ACTIVE_DOT, COL_ACTIVE_LINE, COL_ACTIVE_TEXT, coronaangle, cyc);
count++;
@ -282,8 +287,8 @@ public class NetworkGraph {
}
private static void drawNetworkPictureDHT(final RasterPlotter img, final int centerX, final int centerY, final int innerradius, final Seed mySeed, final Seed otherSeed, final String colorLine, final int coronaangle, final boolean out, final int cyc) {
final int angleMy = cyc + (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(mySeed.hash), null)) / ((double) Long.MAX_VALUE)));
final int angleOther = cyc + (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(otherSeed.hash), null)) / ((double) Long.MAX_VALUE)));
final int angleMy = cyc + (int) (360.0d * FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(mySeed.hash), null) / DOUBLE_LONG_MAX_VALUE);
final int angleOther = cyc + (int) (360.0d * FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(otherSeed.hash), null) / DOUBLE_LONG_MAX_VALUE);
// draw line
img.arcLine(centerX, centerY, innerradius, innerradius - 20, angleMy, !out,
colorLine, null, 12, (coronaangle < 0) ? -1 : coronaangle / 30, 2, true);
@ -303,11 +308,12 @@ public class NetworkGraph {
final String name = seed.getName().toUpperCase() /*+ ":" + seed.hash + ":" + (((double) ((int) (100 * (((double) yacySeed.dhtPosition(seed.hash)) / ((double) yacySeed.maxDHTDistance))))) / 100.0)*/;
if (name.length() < shortestName) shortestName = name.length();
if (name.length() > longestName) longestName = name.length();
final double angle = cyc + (360.0d * (((double) FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(seed.hash), null)) / ((double) Long.MAX_VALUE)));
final double angle = cyc + (360.0d * FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(seed.hash), null) / DOUBLE_LONG_MAX_VALUE);
//System.out.println("Seed " + seed.hash + " has distance " + seed.dhtDistance() + ", angle = " + angle);
int linelength = 20 + outerradius * (20 * (name.length() - shortestName) / (longestName - shortestName) + Math.abs(seed.hash.hashCode() % 20)) / 80;
if (linelength > outerradius) linelength = outerradius;
int dotsize = 2 + (int) (seed.getLinkCount() / 2000000L);
if (colorDot.equals(COL_MYPEER_DOT)) dotsize = dotsize + 4;
if (dotsize > 18) dotsize = 18;
// draw dot
img.setColor(colorDot);
@ -332,7 +338,7 @@ public class NetworkGraph {
}
private static void drawCorona(final RasterPlotter img, final int centerX, final int centerY, final int innerradius, final double angle, final int dotsize, int strength, final int coronaangle, final boolean inside, final boolean split, final int r, final int g, final int b) {
final double ca = Math.PI * 2.0 * (coronaangle) / 360.0;
final double ca = Math.PI * 2.0d * coronaangle / 360.0d;
if (strength > 4) strength = 4;
// draw a wave around crawling peers
double wave;