當前位置: 首頁>>代碼示例>>Java>>正文


Java HashFunction.newHasher方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:apache,項目名稱:kylin,代碼行數:17,代碼來源:NewCubeSamplingMethodTest.java

示例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;
}
 
開發者ID:marbl,項目名稱:MHAP,代碼行數:21,代碼來源:HashUtils.java

示例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();
    }
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:28,代碼來源:CacheManager.java

示例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;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:41,代碼來源:DeviceManager.java

示例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());
}
 
開發者ID:cloudendpoints,項目名稱:endpoints-management-java,代碼行數:11,代碼來源:SigningTest.java

示例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());
}
 
開發者ID:cloudendpoints,項目名稱:endpoints-management-java,代碼行數:12,代碼來源:SigningTest.java

示例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);
}
 
開發者ID:cloudendpoints,項目名稱:endpoints-management-java,代碼行數:10,代碼來源:MetricValuesTests.java

示例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();
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:13,代碼來源:ByteSource.java

示例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();
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:10,代碼來源:Hashes.java

示例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();
}
 
開發者ID:moorkop,項目名稱:mccy-engine,代碼行數:10,代碼來源:ModPack.java

示例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());
}
 
開發者ID:evrignaud,項目名稱:fim,代碼行數:8,代碼來源:State.java

示例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();
}
 
開發者ID:evrignaud,項目名稱:fim,代碼行數:12,代碼來源:FileState.java

示例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;
}
 
開發者ID:ViDA-NYU,項目名稱:ache,代碼行數:15,代碼來源:AcheToCdrExporter.java

示例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;
}
 
開發者ID:alessiogambi,項目名稱:iter,代碼行數:15,代碼來源:TestResult.java

示例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;
}
 
開發者ID:alessiogambi,項目名稱:iter,代碼行數:16,代碼來源:Test.java


注:本文中的com.google.common.hash.HashFunction.newHasher方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。