Author: j16sdiz
Date: 2008-05-04 13:14:19 +0000 (Sun, 04 May 2008)
New Revision: 19740
Modified:
branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java
Log:
no BigInteger for offset calcuation
Modified:
branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java
2008-05-04 13:13:58 UTC (rev 19739)
+++
branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java
2008-05-04 13:14:19 UTC (rev 19740)
@@ -7,7 +7,6 @@
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
-import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.text.DecimalFormat;
@@ -312,8 +311,10 @@
}
public long getOffset() {
- BigInteger bi = new BigInteger(isEncrypted ? routingKey
: getDigestedRoutingKey(routingKey));
- return
bi.mod(BigInteger.valueOf(storeSize)).longValue();
+ if (isEncrypted)
+ return getOffsetFromDigestedKey(routingKey,
storeSize);
+ else
+ return getOffsetFromPlainKey(routingKey,
storeSize);
}
/**
@@ -841,16 +842,33 @@
/**
* Get offset in the hash table, given a plain routing key.
*
- * @param routingKey
+ * @param plainKey
* @param storeSize
* @return
*/
- public long getOffsetFromPlainKey(byte[] routingKey, long storeSize) {
- // Don't use NativeBigInteger, {@link
net.i2p.util.NativeBigInteger#mod()} don't use native routine.
- BigInteger bi = new
BigInteger(getDigestedRoutingKey(routingKey));
- return bi.mod(BigInteger.valueOf(storeSize)).longValue();
+ public long getOffsetFromPlainKey(byte[] plainKey, long storeSize) {
+ return getOffsetFromPlainKey(getDigestedRoutingKey(plainKey),
storeSize);
}
+ /**
+ * Get offset in the hash table, given a digested routing key.
+ *
+ * @param digestedKey
+ * @param storeSize
+ * @return
+ */
+ public long getOffsetFromDigestedKey(byte[] digestedKey, long
storeSize) {
+ long keyValue = (((long) (digestedKey[0]) << 0) + //
+ (((long) digestedKey[1]) << 8) + //
+ (((long) digestedKey[3]) << 16) + //
+ (((long) digestedKey[4]) << 24) + //
+ (((long) digestedKey[5]) << 32) + //
+ (((long) digestedKey[6]) << 40) + //
+ (((long) digestedKey[7]) << 48))
+ & Long.MAX_VALUE;
+ return keyValue % storeSize;
+ }
+
// ------------- Statistics (a.k.a. lies)
private final Object statLock = new Object();
private long hits;