本文整理汇总了Java中com.google.common.hash.Hasher.putLong方法的典型用法代码示例。如果您正苦于以下问题:Java Hasher.putLong方法的具体用法?Java Hasher.putLong怎么用?Java Hasher.putLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.hash.Hasher
的用法示例。
在下文中一共展示了Hasher.putLong方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCacheKey
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
public String getCacheKey() {
Hasher hasher = hf.newHasher();
hasher.putUnencodedChars(queryKey);
for (Number id : ids) {
if (id instanceof Integer) {
hasher.putInt(id.intValue());
} else if (id instanceof Long) {
hasher.putLong(id.longValue());
} else if (id instanceof Short) {
hasher.putLong(id.shortValue());
} else if (id instanceof Double) {
hasher.putDouble(id.doubleValue());
} else if (id instanceof Float) {
hasher.putFloat(id.floatValue());
} else if (id instanceof Byte) {
hasher.putFloat(id.byteValue());
}
}
HashCode hashcode = hasher.hash();
return hashcode.toString();
}
示例2: testBasics
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Test
public void testBasics() {
Hasher hasher = NullHasher.INSTANCE;
assertEquals(0, hasher.hash().asInt());
hasher.putBoolean(false);
hasher.putByte((byte) 3);
hasher.putBytes(new byte[0]);
hasher.putBytes(null, 3, 3);
hasher.putChar('c');
hasher.putDouble(3.3);
hasher.putFloat(3.4f);
hasher.putInt(7);
hasher.putLong(3);
hasher.putObject(null, null);
hasher.putShort((short) 7);
hasher.putString(null, null);
hasher.putUnencodedChars(null);
}
示例3: hashObjWithSalt
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* hashes the object with an additional salt. For purpose of the cuckoo
* filter, this is used when the hash generated for an item is all zeros.
* All zeros is the same as an empty bucket, so obviously it's not a valid
* tag.
*/
HashCode hashObjWithSalt(T object, int moreSalt) {
Hasher hashInst = hasher.newHasher();
hashInst.putObject(object, funnel);
hashInst.putLong(seedNSalt);
hashInst.putInt(moreSalt);
return hashInst.hash();
}
示例4: hashCode
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public int hashCode() {
Hasher hasher = Hashing.goodFastHash(MIN_BITS).newHasher();
hasher.putBytes(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
hasher.putBytes(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
int qualifierLength = cell.getQualifierLength();
if (isShadowCell()) { // Update qualifier length when qualifier is shadow cell
qualifierLength = qualifierLengthFromShadowCellQualifier(cell.getQualifierArray(),
cell.getQualifierOffset(),
cell.getQualifierLength());
}
hasher.putBytes(cell.getQualifierArray(), cell.getQualifierOffset(), qualifierLength);
hasher.putLong(cell.getTimestamp());
return hasher.hash().asInt();
}
示例5: determineClientToken
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* Determines the idempotency client token for the specified virtual instance ID.
*
* @param virtualInstanceId the virtual instance ID
* @param discriminator a discriminator to further identify this request
* @return the idempotency token
*/
private String determineClientToken(String virtualInstanceId, Long discriminator) {
// Using MD5 because clientToken should be less than 64 characters long
Hasher hasher = Hashing.md5().newHasher(virtualInstanceIds.size());
hasher.putString(virtualInstanceId, Charsets.UTF_8);
hasher.putLong(discriminator);
return hasher.hash().toString();
}
示例6: hash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public void hash(final Hasher hasher) {
hasher.putInt(MetricType.SPREAD.ordinal());
hasher.putLong(timestamp);
hasher.putLong(count);
hasher.putDouble(sum);
hasher.putDouble(sum2);
hasher.putDouble(min);
hasher.putDouble(max);
}
示例7: getETag
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public String getETag(RevisionResource resource) {
Hasher h = Hashing.murmur3_128().newHasher();
resource.prepareETag(h, resource.getUser());
// File list comes from the PatchListCache, so any change to the key or value should
// invalidate ETag.
h.putLong(PatchListKey.serialVersionUID);
return h.hash().toString();
}
示例8: computeZipCheckSum
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* Compute the checksum of a ZIP file.
* @param in input stream
* @return the checksum as a string
* @throws IOException if an error occurs while creating the checksum
*/
private static String computeZipCheckSum(final InputStream in)
throws IOException {
ZipArchiveInputStream zais = new ZipArchiveInputStream(in);
// Create Hash function
final Hasher hs = Hashing.md5().newHasher();
// Store entries in a map
final Map<String, long[]> map = new HashMap<>();
ZipArchiveEntry e;
while ((e = zais.getNextZipEntry()) != null) {
map.put(e.getName(), new long[] {e.getSize(), e.getCrc()});
}
zais.close();
// Add values to hash function in an ordered manner
for (String filename : new TreeSet<>(map.keySet())) {
hs.putString(filename, StandardCharsets.UTF_8);
for (long l : map.get(filename)) {
hs.putLong(l);
}
}
return hs.hash().toString();
}
示例9: putLong
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public Hasher putLong(long l) {
for (Hasher hasher : hashers) {
hasher.putLong(l);
}
return this;
}
示例10: generateSessionId
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
private static long generateSessionId(long userId, int[] keys, int clientVersion, String secret) {
final Hasher hasher = SESSION_HASH_FUNCTION.newHasher();
hasher.putLong(userId);
hasher.putString(secret, StandardCharsets.UTF_8);
hasher.putInt(clientVersion);
for (int key : keys) {
hasher.putInt(key);
}
return hasher.hash().asLong();
}
示例11: update
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* Updates the specified {@link Hasher} by putting the 20 bytes of this SHA-1 to it in order.
*
* @return The specified {@link Hasher}.
*/
public Hasher update(Hasher hasher) {
hasher.putInt(firstFourBytes);
hasher.putLong(nextEightBytes);
hasher.putLong(lastEightBytes);
return hasher;
}
示例12: constructIV
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
private byte[] constructIV(long position) {
Preconditions.checkArgument((position % BLOCK_SIZE) == 0);
long s = position / BLOCK_SIZE;
Hasher hasher = Hashing.murmur3_128().newHasher();
hasher.putLong(s);
hasher.putBytes(keyHashBytes);
byte[] iv = hasher.hash().asBytes();
return iv;
}
示例13: hashObj
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
HashCode hashObj(T object) {
Hasher hashInst = hasher.newHasher();
hashInst.putObject(object, funnel);
hashInst.putLong(seedNSalt);
return hashInst.hash();
}
示例14: hash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* Utility method to compute an hash string from a vararg list of objects. The returned string
* is 16 characters long, starts with {@code A-Za-z} and contains only characters
* {@code A-Za-z0-9}.
*
* @param objects
* the objects to compute the hash from
* @return the computed hash string
*/
public static String hash(final Object... objects) {
final Hasher hasher = Hashing.md5().newHasher();
for (final Object object : objects) {
if (object instanceof CharSequence) {
hasher.putString((CharSequence) object, Charsets.UTF_16LE);
} else if (object instanceof byte[]) {
hasher.putBytes((byte[]) object);
} else if (object instanceof Character) {
hasher.putChar((Character) object);
} else if (object instanceof Boolean) {
hasher.putBoolean((Boolean) object);
} else if (object instanceof Integer) {
hasher.putInt(((Integer) object).intValue());
} else if (object instanceof Long) {
hasher.putLong(((Long) object).longValue());
} else if (object instanceof Double) {
hasher.putDouble(((Double) object).doubleValue());
} else if (object instanceof Float) {
hasher.putFloat(((Float) object).floatValue());
} else if (object instanceof Byte) {
hasher.putByte(((Byte) object).byteValue());
} else {
hasher.putString(object.toString(), Charsets.UTF_16LE);
}
}
final byte[] bytes = hasher.hash().asBytes();
final StringBuilder builder = new StringBuilder(16);
int max = 52;
for (int i = 0; i < bytes.length; ++i) {
final int n = (bytes[i] & 0x7F) % max;
if (n < 26) {
builder.append((char) (65 + n));
} else if (n < 52) {
builder.append((char) (71 + n));
} else {
builder.append((char) (n - 4));
}
max = 62;
}
return builder.toString();
}
示例15: hash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public void hash(final Hasher hasher) {
hasher.putInt(MetricType.CARDINALITY.ordinal());
hasher.putLong(timestamp);
hasher.putBytes(state);
}