This commit is contained in:
zzz
2011-09-24 21:45:52 +00:00
parent fd1c8c45a8
commit a2c867c224
2 changed files with 6 additions and 16 deletions

View File

@@ -55,16 +55,8 @@ import net.i2p.util.Translate;
* @author jrandom * @author jrandom
*/ */
public class DataHelper { public class DataHelper {
private static final byte EQUAL_BYTES[]; private static final byte[] EQUAL_BYTES = getUTF8("=");
private static final byte SEMICOLON_BYTES[]; private static final byte[] SEMICOLON_BYTES = getUTF8(";");
static {
try {
EQUAL_BYTES = "=".getBytes("UTF-8");
SEMICOLON_BYTES = ";".getBytes("UTF-8");
} catch (UnsupportedEncodingException uee) {
throw new RuntimeException("no utf8!?");
}
}
/** Read a mapping from the stream, as defined by the I2P data structure spec, /** Read a mapping from the stream, as defined by the I2P data structure spec,
* and store it into a Properties object. * and store it into a Properties object.

View File

@@ -10,20 +10,18 @@ import net.i2p.data.Hash;
* *
*/ */
class XORComparator implements Comparator<Hash> { class XORComparator implements Comparator<Hash> {
private final Hash _base; private final byte[] _base;
/** /**
* @param target key to compare distances with * @param target key to compare distances with
*/ */
public XORComparator(Hash target) { public XORComparator(Hash target) {
_base = target; _base = target.getData();
} }
public int compare(Hash lhs, Hash rhs) { public int compare(Hash lhs, Hash rhs) {
if (lhs == null) throw new NullPointerException("LHS is null"); byte lhsDelta[] = DataHelper.xor(lhs.getData(), _base);
if (rhs == null) throw new NullPointerException("RHS is null"); byte rhsDelta[] = DataHelper.xor(rhs.getData(), _base);
byte lhsDelta[] = DataHelper.xor(lhs.getData(), _base.getData());
byte rhsDelta[] = DataHelper.xor(rhs.getData(), _base.getData());
return DataHelper.compareTo(lhsDelta, rhsDelta); return DataHelper.compareTo(lhsDelta, rhsDelta);
} }
} }