private static <T> boolean contains(ByteBuff bloomBuf, int bloomOffset, int bloomSize, Hash hash, int hashCount, HashKey<T> hashKey) { int hash1 = hash.hash(hashKey, 0); int bloomBitSize = bloomSize << 3; int hash2 = 0; int compositeHash = 0; if (randomGeneratorForTest == null) { // Production mode compositeHash = hash1; hash2 = hash.hash(hashKey, hash1); } for (int i = 0; i < hashCount; i++) { int hashLoc = (randomGeneratorForTest == null // Production mode ? Math.abs(compositeHash % bloomBitSize) // Test mode with "fake look-ups" to estimate "ideal false positive rate" : randomGeneratorForTest.nextInt(bloomBitSize)); compositeHash += hash2; if (!checkBit(hashLoc, bloomBuf, bloomOffset)) { return false; } } return true; }
public void add(Cell cell) { /* * For faster hashing, use combinatorial generation * http://www.eecs.harvard.edu/~kirsch/pubs/bbbf/esa06.pdf */ int hash1; int hash2; HashKey<Cell> hashKey; if (this.bloomType == BloomType.ROWCOL) { hashKey = new RowColBloomHashKey(cell); hash1 = this.hash.hash(hashKey, 0); hash2 = this.hash.hash(hashKey, hash1); } else { hashKey = new RowBloomHashKey(cell); hash1 = this.hash.hash(hashKey, 0); hash2 = this.hash.hash(hashKey, hash1); } setHashLoc(hash1, hash2); }
/** * @return the encodedName */ @InterfaceAudience.Private static String encodeRegionName(final byte [] regionName) { String encodedName; if (hasEncodedName(regionName)) { // region is in new format: // <tableName>,<startKey>,<regionIdTimeStamp>/encodedName/ encodedName = Bytes.toString(regionName, regionName.length - MD5_HEX_LENGTH - 1, MD5_HEX_LENGTH); } else { // old format region name. First hbase:meta region also // use this format.EncodedName is the JenkinsHash value. HashKey<byte[]> key = new ByteArrayHashKey(regionName, 0, regionName.length); int hashVal = Math.abs(JenkinsHash.getInstance().hash(key, 0)); encodedName = String.valueOf(hashVal); } return encodedName; }
LOG.info("Client=" + j + ", input=" + s); byte[] b = Bytes.toBytes(s); int hash = h.hash(new ByteArrayHashKey(b, 0, b.length), -1); m.put(hash, s);
", noOfTags=" + this.noOfTags; byte[] b = Bytes.toBytes(s); int hash = h.hash(new ByteArrayHashKey(b, 0, b.length), -1); m.put(hash, s);
/** * @return the encodedName */ @InterfaceAudience.Private static String encodeRegionName(final byte [] regionName) { String encodedName; if (hasEncodedName(regionName)) { // region is in new format: // <tableName>,<startKey>,<regionIdTimeStamp>/encodedName/ encodedName = Bytes.toString(regionName, regionName.length - MD5_HEX_LENGTH - 1, MD5_HEX_LENGTH); } else { // old format region name. First hbase:meta region also // use this format.EncodedName is the JenkinsHash value. HashKey<byte[]> key = new ByteArrayHashKey(regionName, 0, regionName.length); int hashVal = Math.abs(JenkinsHash.getInstance().hash(key, 0)); encodedName = String.valueOf(hashVal); } return encodedName; }
/** * Calculate a hash using bytes from 0 to <code>length</code>, and * the provided seed value * @param bytes input bytes * @param length length of the valid bytes after offset to consider * @param initval seed value * @return hash value */ public int hash(byte[] bytes, int length, int initval) { return hash(bytes, 0, length, initval); }
/** * Calculate a hash using all bytes from the input argument, * and a provided seed value. * @param bytes input bytes * @param initval seed value * @return hash value */ public int hash(byte[] bytes, int initval) { return hash(bytes, 0, bytes.length, initval); }
/** * Calculate a hash using all bytes from the input argument, and * a seed of -1. * @param bytes input bytes * @return hash value */ public int hash(byte[] bytes) { return hash(bytes, bytes.length, -1); }
/** * Calculate a hash using all bytes from the input argument, * and a provided seed value. * @param bytes input bytes * @param initval seed value * @return hash value */ public int hash(byte[] bytes, int initval) { return hash(bytes, 0, bytes.length, initval); }
/** * Calculate a hash using all bytes from the input argument, and * a seed of -1. * @param bytes input bytes * @return hash value */ public int hash(byte[] bytes) { return hash(bytes, bytes.length, -1); }
/** * Calculate a hash using bytes from 0 to <code>length</code>, and * the provided seed value * @param bytes input bytes * @param length length of the valid bytes after offset to consider * @param initval seed value * @return hash value */ public int hash(byte[] bytes, int length, int initval) { return hash(bytes, 0, length, initval); }
public static void main(String[] args) throws IOException Hash hasher = new Hash(); ... if (file.toString().endsWith(".raw")) { hasher.hash(file); } ... }
@Override public void add(byte [] buf, int offset, int len) { /* * For faster hashing, use combinatorial generation * http://www.eecs.harvard.edu/~kirsch/pubs/bbbf/esa06.pdf */ int hash1 = this.hash.hash(buf, offset, len, 0); int hash2 = this.hash.hash(buf, offset, len, hash1); for (int i = 0; i < this.hashCount; i++) { long hashLoc = Math.abs((hash1 + i * hash2) % (this.byteSize * 8)); set(hashLoc); } ++this.keyCount; }
@Override public void add(byte [] buf, int offset, int len) { /* * For faster hashing, use combinatorial generation * http://www.eecs.harvard.edu/~kirsch/pubs/bbbf/esa06.pdf */ int hash1 = this.hash.hash(buf, offset, len, 0); int hash2 = this.hash.hash(buf, offset, len, hash1); for (int i = 0; i < this.hashCount; i++) { long hashLoc = Math.abs((hash1 + i * hash2) % (this.byteSize * 8)); set(hashLoc); } ++this.keyCount; }
/** * @param entityGroupName * @return the encodedName */ public static String encodeEntityGroupName(final byte[] entityGroupName) { String encodedName; if (hasEncodedName(entityGroupName)) { // entityGroup is in new format: // <tableName>,<startKey>,<entityGroupIdTimeStamp>/encodedName/ encodedName = Bytes.toString(entityGroupName, entityGroupName.length - MD5_HEX_LENGTH - 1, MD5_HEX_LENGTH); } else { // old format entityGroup name. first META entityGroup also // use this format.EncodedName is the JenkinsHash value. int hashVal = Math.abs(JenkinsHash.getInstance().hash(entityGroupName, entityGroupName.length, 0)); encodedName = String.valueOf(hashVal); } return encodedName; }
/** * @param regionName * @return the encodedName */ public static String encodeRegionName(final byte [] regionName) { String encodedName; if (hasEncodedName(regionName)) { // region is in new format: // <tableName>,<startKey>,<regionIdTimeStamp>/encodedName/ encodedName = Bytes.toString(regionName, regionName.length - MD5_HEX_LENGTH - 1, MD5_HEX_LENGTH); } else { // old format region name. ROOT and first META region also // use this format.EncodedName is the JenkinsHash value. int hashVal = Math.abs(JenkinsHash.getInstance().hash(regionName, regionName.length, 0)); encodedName = String.valueOf(hashVal); } return encodedName; }
/** * @param regionName * @return the encodedName */ public static String encodeRegionName(final byte [] regionName) { String encodedName; if (hasEncodedName(regionName)) { // region is in new format: // <tableName>,<startKey>,<regionIdTimeStamp>/encodedName/ encodedName = Bytes.toString(regionName, regionName.length - MD5_HEX_LENGTH - 1, MD5_HEX_LENGTH); } else { // old format region name. ROOT and first META region also // use this format.EncodedName is the JenkinsHash value. int hashVal = Math.abs(JenkinsHash.getInstance().hash(regionName, regionName.length, 0)); encodedName = String.valueOf(hashVal); } return encodedName; }
/** * @param regionName * @return the encodedName */ public static String encodeRegionName(final byte [] regionName) { String encodedName; if (hasEncodedName(regionName)) { // region is in new format: // <tableName>,<startKey>,<regionIdTimeStamp>/encodedName/ encodedName = Bytes.toString(regionName, regionName.length - MD5_HEX_LENGTH - 1, MD5_HEX_LENGTH); } else { // old format region name. First hbase:meta region also // use this format.EncodedName is the JenkinsHash value. int hashVal = Math.abs(JenkinsHash.getInstance().hash(regionName, regionName.length, 0)); encodedName = String.valueOf(hashVal); } return encodedName; }
/** * @return the encodedName */ @InterfaceAudience.Private static String encodeRegionName(final byte [] regionName) { String encodedName; if (hasEncodedName(regionName)) { // region is in new format: // <tableName>,<startKey>,<regionIdTimeStamp>/encodedName/ encodedName = Bytes.toString(regionName, regionName.length - MD5_HEX_LENGTH - 1, MD5_HEX_LENGTH); } else { // old format region name. First hbase:meta region also // use this format.EncodedName is the JenkinsHash value. HashKey<byte[]> key = new ByteArrayHashKey(regionName, 0, regionName.length); int hashVal = Math.abs(JenkinsHash.getInstance().hash(key, 0)); encodedName = String.valueOf(hashVal); } return encodedName; }