diff --git storage-api/src/java/org/apache/hive/common/util/BloomKFilter.java storage-api/src/java/org/apache/hive/common/util/BloomKFilter.java index 3b44d2b..28a283a 100644 --- storage-api/src/java/org/apache/hive/common/util/BloomKFilter.java +++ storage-api/src/java/org/apache/hive/common/util/BloomKFilter.java @@ -41,7 +41,6 @@ private static final int DEFAULT_BLOCK_SIZE_BITS = (int) (Math.log(DEFAULT_BLOCK_SIZE) / Math.log(2)); private static final int DEFAULT_BLOCK_OFFSET_MASK = DEFAULT_BLOCK_SIZE - 1; private static final int DEFAULT_BIT_OFFSET_MASK = Long.SIZE - 1; - private final long[] masks = new long[DEFAULT_BLOCK_SIZE]; private final BitSet bitSet; private final int m; private final int k; @@ -205,23 +204,16 @@ private boolean testHash(long hash64) { } // LSB 3 bits is used to locate offset within the block final int wordOffset = combinedHash & DEFAULT_BLOCK_OFFSET_MASK; + final int absOffset = blockBaseOffset + wordOffset; // Next 6 bits are used to locate offset within a long/word final int bitPos = (combinedHash >>> DEFAULT_BLOCK_SIZE_BITS) & DEFAULT_BIT_OFFSET_MASK; - masks[wordOffset] |= (1L << bitPos); - } - - // traverse data and masks array together, check for set bits - long expected = 0; - for (int i = 0; i < DEFAULT_BLOCK_SIZE; i++) { - final long mask = masks[i]; - expected |= (bits[blockBaseOffset + i] & mask) ^ mask; + final long bloomWord = bits[absOffset]; + if (0 == (bloomWord & (1L << bitPos))) { + return false; + } } - // clear the mask for array reuse (this is to avoid masks array allocation in inner loop) - Arrays.fill(masks, 0); - - // if all bits are set, expected should be 0 - return expected == 0; + return true; } public boolean testString(String val) {