forked from I2P_Developers/i2p.i2p
2006-02-15 jrandom
* Merged in the i2p_0_6_1_10_PRE branch to the trunk, so CVS HEAD is no
longer backwards compatible (and should not be used until 0.6.1.1 is
out)
This commit is contained in:
@@ -80,14 +80,17 @@ public class DecayingBloomFilter {
|
||||
*
|
||||
*/
|
||||
public boolean add(byte entry[]) {
|
||||
return add(entry, 0, entry.length);
|
||||
}
|
||||
public boolean add(byte entry[], int off, int len) {
|
||||
if (ALWAYS_MISS) return false;
|
||||
if (entry == null)
|
||||
throw new IllegalArgumentException("Null entry");
|
||||
if (entry.length != _entryBytes)
|
||||
throw new IllegalArgumentException("Bad entry [" + entry.length + ", expected "
|
||||
if (len != _entryBytes)
|
||||
throw new IllegalArgumentException("Bad entry [" + len + ", expected "
|
||||
+ _entryBytes + "]");
|
||||
synchronized (this) {
|
||||
return locked_add(entry);
|
||||
return locked_add(entry, off, len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,14 +104,15 @@ public class DecayingBloomFilter {
|
||||
if (ALWAYS_MISS) return false;
|
||||
synchronized (this) {
|
||||
if (_entryBytes <= 7)
|
||||
entry &= _longToEntryMask;
|
||||
entry = ((entry ^ _longToEntryMask) & ((1 << 31)-1)) | (entry ^ _longToEntryMask);
|
||||
//entry &= _longToEntryMask;
|
||||
if (entry < 0) {
|
||||
DataHelper.toLong(_longToEntry, 0, _entryBytes, 0-entry);
|
||||
_longToEntry[0] |= (1 << 7);
|
||||
} else {
|
||||
DataHelper.toLong(_longToEntry, 0, _entryBytes, entry);
|
||||
}
|
||||
return locked_add(_longToEntry);
|
||||
return locked_add(_longToEntry, 0, _longToEntry.length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,26 +125,26 @@ public class DecayingBloomFilter {
|
||||
if (ALWAYS_MISS) return false;
|
||||
synchronized (this) {
|
||||
if (_entryBytes <= 7)
|
||||
entry &= _longToEntryMask;
|
||||
entry = ((entry ^ _longToEntryMask) & ((1 << 31)-1)) | (entry ^ _longToEntryMask);
|
||||
if (entry < 0) {
|
||||
DataHelper.toLong(_longToEntry, 0, _entryBytes, 0-entry);
|
||||
_longToEntry[0] |= (1 << 7);
|
||||
} else {
|
||||
DataHelper.toLong(_longToEntry, 0, _entryBytes, entry);
|
||||
}
|
||||
return locked_add(_longToEntry, false);
|
||||
return locked_add(_longToEntry, 0, _longToEntry.length, false);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean locked_add(byte entry[]) {
|
||||
return locked_add(entry, true);
|
||||
private boolean locked_add(byte entry[], int offset, int len) {
|
||||
return locked_add(entry, offset, len, true);
|
||||
}
|
||||
private boolean locked_add(byte entry[], boolean addIfNew) {
|
||||
private boolean locked_add(byte entry[], int offset, int len, boolean addIfNew) {
|
||||
if (_extended != null) {
|
||||
// extend the entry to 32 bytes
|
||||
System.arraycopy(entry, 0, _extended, 0, entry.length);
|
||||
System.arraycopy(entry, offset, _extended, 0, len);
|
||||
for (int i = 0; i < _extenders.length; i++)
|
||||
DataHelper.xor(entry, 0, _extenders[i], 0, _extended, _entryBytes * (i+1), _entryBytes);
|
||||
DataHelper.xor(entry, offset, _extenders[i], 0, _extended, _entryBytes * (i+1), _entryBytes);
|
||||
|
||||
boolean seen = _current.member(_extended);
|
||||
seen = seen || _previous.member(_extended);
|
||||
@@ -155,15 +159,15 @@ public class DecayingBloomFilter {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
boolean seen = _current.locked_member(entry);
|
||||
seen = seen || _previous.locked_member(entry);
|
||||
boolean seen = _current.locked_member(entry, offset, len);
|
||||
seen = seen || _previous.locked_member(entry, offset, len);
|
||||
if (seen) {
|
||||
_currentDuplicates++;
|
||||
return true;
|
||||
} else {
|
||||
if (addIfNew) {
|
||||
_current.locked_insert(entry);
|
||||
_previous.locked_insert(entry);
|
||||
_current.locked_insert(entry, offset, len);
|
||||
_previous.locked_insert(entry, offset, len);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ public class NativeBigInteger extends BigInteger {
|
||||
private final static String JBIGI_OPTIMIZATION_PENTIUM2 = "pentium2";
|
||||
private final static String JBIGI_OPTIMIZATION_PENTIUM3 = "pentium3";
|
||||
private final static String JBIGI_OPTIMIZATION_PENTIUM4 = "pentium4";
|
||||
private final static String JBIGI_OPTIMIZATION_VIAC3 = "viac3";
|
||||
|
||||
private static final boolean _isWin = System.getProperty("os.name").startsWith("Win");
|
||||
private static final boolean _isOS2 = System.getProperty("os.name").startsWith("OS/2");
|
||||
@@ -134,6 +135,8 @@ public class NativeBigInteger extends BigInteger {
|
||||
|
||||
try {
|
||||
CPUInfo c = CPUID.getInfo();
|
||||
if (c.IsC3Compatible())
|
||||
return JBIGI_OPTIMIZATION_VIAC3;
|
||||
if (c instanceof AMDCPUInfo) {
|
||||
AMDCPUInfo amdcpu = (AMDCPUInfo) c;
|
||||
if (amdcpu.IsAthlon64Compatible())
|
||||
@@ -146,20 +149,18 @@ public class NativeBigInteger extends BigInteger {
|
||||
return JBIGI_OPTIMIZATION_K6_2;
|
||||
if (amdcpu.IsK6Compatible())
|
||||
return JBIGI_OPTIMIZATION_K6;
|
||||
} else {
|
||||
if (c instanceof IntelCPUInfo) {
|
||||
IntelCPUInfo intelcpu = (IntelCPUInfo) c;
|
||||
if (intelcpu.IsPentium4Compatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUM4;
|
||||
if (intelcpu.IsPentium3Compatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUM3;
|
||||
if (intelcpu.IsPentium2Compatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUM2;
|
||||
if (intelcpu.IsPentiumMMXCompatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUMMMX;
|
||||
if (intelcpu.IsPentiumCompatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUM;
|
||||
}
|
||||
} else if (c instanceof IntelCPUInfo) {
|
||||
IntelCPUInfo intelcpu = (IntelCPUInfo) c;
|
||||
if (intelcpu.IsPentium4Compatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUM4;
|
||||
if (intelcpu.IsPentium3Compatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUM3;
|
||||
if (intelcpu.IsPentium2Compatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUM2;
|
||||
if (intelcpu.IsPentiumMMXCompatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUMMMX;
|
||||
if (intelcpu.IsPentiumCompatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUM;
|
||||
}
|
||||
return null;
|
||||
} catch (UnknownCPUException e) {
|
||||
@@ -287,7 +288,7 @@ public class NativeBigInteger extends BigInteger {
|
||||
|
||||
int runsProcessed = 0;
|
||||
for (runsProcessed = 0; runsProcessed < numRuns; runsProcessed++) {
|
||||
BigInteger bi = new BigInteger(2048, rand);
|
||||
BigInteger bi = new BigInteger(226, rand); // 2048, rand); //
|
||||
NativeBigInteger g = new NativeBigInteger(_sampleGenerator);
|
||||
NativeBigInteger p = new NativeBigInteger(_samplePrime);
|
||||
NativeBigInteger k = new NativeBigInteger(1, bi.toByteArray());
|
||||
|
||||
Reference in New Issue
Block a user