You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2013/02/26 02:56:39 UTC
svn commit: r1449996 -
/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/ByteBloomFilter.java
Author: tedyu
Date: Tue Feb 26 01:56:38 2013
New Revision: 1449996
URL: http://svn.apache.org/r1449996
Log:
HBASE-7884 ByteBloomFilter's performance can be improved by avoiding multiplication when generating hash (clockfly)
Modified:
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/ByteBloomFilter.java
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/ByteBloomFilter.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/ByteBloomFilter.java?rev=1449996&r1=1449995&r2=1449996&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/ByteBloomFilter.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/ByteBloomFilter.java Tue Feb 26 01:56:38 2013
@@ -418,24 +418,27 @@ public class ByteBloomFilter implements
int hash1 = hash.hash(buf, offset, length, 0);
int hash2 = hash.hash(buf, offset, length, hash1);
- int bloomBitSize = bloomSize * 8;
-
+ int bloomBitSize = bloomSize << 3;
+
if (randomGeneratorForTest == null) {
// Production mode.
+ int compositeHash = hash1;
for (int i = 0; i < hashCount; i++) {
- long hashLoc = Math.abs((hash1 + i * hash2) % bloomBitSize);
- if (!get(hashLoc, bloomArray, bloomOffset))
+ int hashLoc = Math.abs(compositeHash % bloomBitSize);
+ compositeHash += hash2;
+ if (!get(hashLoc, bloomArray, bloomOffset)) {
return false;
+ }
}
} else {
// Test mode with "fake lookups" to estimate "ideal false positive rate".
for (int i = 0; i < hashCount; i++) {
- long hashLoc = randomGeneratorForTest.nextInt(bloomBitSize);
- if (!get(hashLoc, bloomArray, bloomOffset))
+ int hashLoc = randomGeneratorForTest.nextInt(bloomBitSize);
+ if (!get(hashLoc, bloomArray, bloomOffset)){
return false;
+ }
}
}
-
return true;
}
@@ -461,9 +464,9 @@ public class ByteBloomFilter implements
* @param pos index of bit
* @return true if bit at specified index is 1, false if 0.
*/
- static boolean get(long pos, byte[] bloomArray, int bloomOffset) {
- int bytePos = (int)(pos / 8);
- int bitPos = (int)(pos % 8);
+ static boolean get(int pos, byte[] bloomArray, int bloomOffset) {
+ int bytePos = pos >> 3; //pos / 8
+ int bitPos = pos & 0x7; //pos % 8
byte curByte = bloomArray[bloomOffset + bytePos];
curByte &= bitvals[bitPos];
return (curByte != 0);