本文整理匯總了Java中com.google.common.hash.HashFunction.newHasher方法的典型用法代碼示例。如果您正苦於以下問題:Java HashFunction.newHasher方法的具體用法?Java HashFunction.newHasher怎麽用?Java HashFunction.newHasher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.hash.HashFunction
的用法示例。
在下文中一共展示了HashFunction.newHasher方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: putRowKeyToHLLNew
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
private void putRowKeyToHLLNew(List<String> row, long[] hashValuesLong, HLLCounter[] cuboidCounters, HashFunction hashFunction) {
int x = 0;
for (String field : row) {
Hasher hc = hashFunction.newHasher();
byte[] bytes = hc.putString(x + field).hash().asBytes();
hashValuesLong[x++] = Bytes.toLong(bytes);
}
for (int i = 0, n = allCuboidsBitSet.length; i < n; i++) {
long value = 0;
for (int position = 0; position < allCuboidsBitSet[i].length; position++) {
value += hashValuesLong[allCuboidsBitSet[i][position]];
}
cuboidCounters[i].addHashDirectly(value);
}
}
示例2: computeHashes
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
public static long[] computeHashes(String item, int numWords, int seed)
{
long[] hashes = new long[numWords];
for (int word = 0; word < numWords; word += 2)
{
HashFunction hashFunc = Hashing.murmur3_128(seed + word);
Hasher hasher = hashFunc.newHasher();
hasher.putUnencodedChars(item);
// get the two longs out
HashCode hc = hasher.hash();
ByteBuffer bb = ByteBuffer.wrap(hc.asBytes());
hashes[word] = bb.getLong(0);
if (word + 1 < numWords)
hashes[word + 1] = bb.getLong(8);
}
return hashes;
}
示例3: build
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
public CacheEntry build() {
Path baseDir = cacheDir.resolve(name);
if (!keys.isEmpty()) {
HashFunction hf = Hashing.md5();
Hasher h = hf.newHasher();
for (String key : keys) {
h.putString(key, Charsets.UTF_8);
}
HashCode hc = h.hash();
baseDir = baseDir.resolve(hc.toString());
}
cacheEntriesLock.lock();
try {
CacheEntry cacheEntry = cacheEntries.get(baseDir.toString());
if (cacheEntry != null) {
if (!cacheEntry.getKeys().equals(keys)) {
throw new PowsyblException("Inconsistent hash");
}
} else {
cacheEntry = new CacheEntry(baseDir, keys);
cacheEntries.put(baseDir.toString(), cacheEntry);
}
return cacheEntry;
} finally {
cacheEntriesLock.unlock();
}
}
示例4: getHardwareProperties
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
/**
* Returns the hardware properties defined in
* {@link AvdManager#HARDWARE_INI} as a {@link Map}.
*
* This is intended to be dumped in the config.ini and already contains
* the device name, manufacturer and device hash.
*
* @param d The {@link Device} from which to derive the hardware properties.
* @return A {@link Map} of hardware properties.
*/
@NonNull
public static Map<String, String> getHardwareProperties(@NonNull Device d) {
Map<String, String> props = getHardwareProperties(d.getDefaultState());
for (State s : d.getAllStates()) {
if (s.getKeyState().equals(KeyboardState.HIDDEN)) {
props.put("hw.keyboard.lid", getBooleanVal(true));
}
}
HashFunction md5 = Hashing.md5();
Hasher hasher = md5.newHasher();
ArrayList<String> keys = new ArrayList<String>(props.keySet());
Collections.sort(keys);
for (String key : keys) {
if (key != null) {
hasher.putString(key, Charsets.UTF_8);
String value = props.get(key);
hasher.putString(value == null ? "null" : value, Charsets.UTF_8);
}
}
// store the hash method for potential future compatibility
String hash = "MD5:" + hasher.hash().toString();
props.put(AvdManager.AVD_INI_DEVICE_HASH_V2, hash);
props.remove(AvdManager.AVD_INI_DEVICE_HASH_V1);
props.put(AvdManager.AVD_INI_DEVICE_NAME, d.getId());
props.put(AvdManager.AVD_INI_DEVICE_MANUFACTURER, d.getManufacturer());
return props;
}
示例5: putLabelsShouldUpdateHashesConsistently
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
@Test
public void putLabelsShouldUpdateHashesConsistently() {
HashMap<String, String> copy1 = Maps.newHashMap(TEST_LABELS);
HashMap<String, String> copy2 = Maps.newHashMap(TEST_LABELS);
HashFunction hf = Hashing.md5();
Hasher hasher1 = hf.newHasher();
Hasher hasher2 = hf.newHasher();
assertEquals(Signing.putLabels(hasher1, copy1).hash(),
Signing.putLabels(hasher2, copy2).hash());
}
示例6: putLabelsShouldVaryHashesWithValues
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
@Test
public void putLabelsShouldVaryHashesWithValues() {
HashMap<String, String> copy1 = Maps.newHashMap(TEST_LABELS);
HashMap<String, String> copy2 = Maps.newHashMap(TEST_LABELS);
copy2.put("key1", "changed!");
HashFunction hf = Hashing.md5();
Hasher hasher1 = hf.newHasher();
Hasher hasher2 = hf.newHasher();
assertNotEquals(Signing.putLabels(hasher1, copy1).hash(),
Signing.putLabels(hasher2, copy2).hash());
}
示例7: putMetricValueShouldUpdateHashesConsistently
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
@Test
public void putMetricValueShouldUpdateHashesConsistently() {
HashFunction hf = Hashing.md5();
Hasher hasher1 = hf.newHasher();
Hasher hasher2 = hf.newHasher();
HashCode hash1 = MetricValues.putMetricValue(hasher1, testValue).hash();
HashCode hash2 = MetricValues.putMetricValue(hasher2, otherValue).hash();
assertEquals(hash1, hash2);
}
示例8: hash
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
/**
* Hashes the contents of this byte source using the given hash function.
*
* @throws IOException if an I/O error occurs in the process of reading from this source
*/
public HashCode hash(HashFunction hashFunction) throws IOException {
Hasher hasher = hashFunction.newHasher();
copyTo(Funnels.asOutputStream(hasher));
return hasher.hash();
}
示例9: hash
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
/**
* Computes the hash of the given stream using the given function.
*/
public static HashCode hash(final HashFunction function, final InputStream input) throws IOException {
Hasher hasher = function.newHasher();
OutputStream output = Funnels.asOutputStream(hasher);
ByteStreams.copy(input, output);
return hasher.hash();
}
示例10: computeId
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
public static String computeId(HashFunction hashFunction, Collection<String> modIds) {
final Hasher hasher = hashFunction.newHasher();
modIds.stream()
.sorted()
.forEachOrdered(id -> hasher.putString(id, StandardCharsets.UTF_8));
return hasher.hash().toString();
}
示例11: hashState
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
public String hashState() {
HashFunction hashFunction = Hashing.sha512();
Hasher hasher = hashFunction.newHasher(Constants._10_MB);
hashObject(hasher);
HashCode hash = hasher.hash();
return Ascii85Util.encode(hash.asBytes());
}
示例12: longHashCode
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
/**
* Returns a long hash code value for the object.
* A long is used to avoid hashCode collisions when we have a huge number of FileStates.
*/
public long longHashCode() {
HashFunction hashFunction = Hashing.sha512();
Hasher hasher = hashFunction.newHasher(Constants._4_KB);
hashObject(hasher, true);
HashCode hash = hasher.hash();
return hash.asLong();
}
示例13: uploadMediaFile
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
private String uploadMediaFile(byte[] content, String url) throws IOException {
HashFunction hf = Hashing.sha256();
Hasher hasher = hf.newHasher();
hasher.putBytes(content);
String host = new URL(url).getHost();
String hs = reverseDomain(host) + "/" + hasher.hash().toString();
if (skipUpload == false) {
this.s3Uploader.upload(hs, content);
System.out.println("Uploaded object: " + hs);
} else {
System.out.println("Created object: " + hs);
}
return hs;
}
示例14: hashCode
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
@Override
public int hashCode() {
if (this.hashCode == null) {
HashFunction hashFunction = Hashing.sha512();
Hasher hasher = hashFunction.newHasher();
hasher = hasher.putLong(testId).putString(customerName)
.putString(serviceName);
for (Number number : parameters) {
hasher = hasher.putString(number.toString());
}
this.hashCode = hasher.hash().asInt();
}
return this.hashCode;
}
示例15: hashCode
import com.google.common.hash.HashFunction; //導入方法依賴的package包/類
@Override
public int hashCode() {
if (this.hashCode == null) {
HashFunction hashFunction = Hashing.sha512();
Hasher hasher = hashFunction.newHasher();
// TODO Relaxed the id constraint and use only the others
hasher = hasher.putString(testFile).putString(manifestFile)
.putString(traceFile);
for (Number number : parameters) {
hasher = hasher.putString(number.toString());
}
this.hashCode = hasher.hash().asInt();
}
return this.hashCode;
}