List of usage examples for com.google.common.hash Hasher putInt
@Override
Hasher putInt(int i);
From source file:com.yahoo.yqlplus.api.types.YQLType.java
public void hashTo(Hasher digest) { digest.putInt(getCoreType().ordinal()); annotations.hashTo(digest); }
From source file:com.spotify.heroic.metric.Event.java
@Override public void hash(final Hasher hasher) { hasher.putInt(MetricType.EVENT.ordinal()); for (final String k : KEY_ORDER.sortedCopy(payload.keySet())) { hasher.putString(k, Charsets.UTF_8).putString(payload.get(k), Charsets.UTF_8); }/*from www . j a v a 2 s . c om*/ }
From source file:com.spotify.heroic.metric.Spread.java
@Override public void hash(final Hasher hasher) { hasher.putInt(MetricType.SPREAD.ordinal()); hasher.putLong(timestamp);//from w w w. ja va 2 s . co m hasher.putLong(count); hasher.putDouble(sum); hasher.putDouble(sum2); hasher.putDouble(min); hasher.putDouble(max); }
From source file:com.spotify.heroic.metric.MetricGroup.java
@Override public void hash(final Hasher hasher) { hasher.putInt(MetricType.GROUP.ordinal()); for (final MetricCollection c : groups) { for (final Metric m : c.getData()) { m.hash(hasher);// w w w .ja v a 2 s. c o m } } }
From source file:com.facebook.buck.json.JsonObjectHashing.java
/** * Given a {@link Hasher} and a parsed BUCK file object, updates the Hasher * with the contents of the JSON object. *//*from w w w . j a v a2s.co m*/ public static void hashJsonObject(Hasher hasher, @Nullable Object obj) { if (obj instanceof Map) { Map<?, ?> map = (Map<?, ?>) obj; ImmutableSortedMap.Builder<String, Optional<Object>> sortedMapBuilder = ImmutableSortedMap .naturalOrder(); for (Map.Entry<?, ?> entry : map.entrySet()) { Object key = entry.getKey(); if (!(key instanceof String)) { throw new RuntimeException(String.format( "Keys of JSON maps are expected to be strings. Actual type: %s, contents: %s", key.getClass().getName(), key)); } Object value = entry.getValue(); if (value != null) { sortedMapBuilder.put((String) key, Optional.of(value)); } } ImmutableSortedMap<String, Optional<Object>> sortedMap = sortedMapBuilder.build(); hasher.putInt(HashedObjectType.MAP.ordinal()); hasher.putInt(sortedMap.size()); for (Map.Entry<String, Optional<Object>> entry : sortedMap.entrySet()) { hashJsonObject(hasher, entry.getKey()); if (entry.getValue().isPresent()) { hashJsonObject(hasher, entry.getValue().get()); } else { hashJsonObject(hasher, null); } } } else if (obj instanceof Collection) { Collection<?> collection = (Collection<?>) obj; hasher.putInt(HashedObjectType.LIST.ordinal()); hasher.putInt(collection.size()); for (Object collectionEntry : collection) { hashJsonObject(hasher, collectionEntry); } } else if (obj instanceof String) { hasher.putInt(HashedObjectType.STRING.ordinal()); byte[] stringBytes = ((String) obj).getBytes(Charsets.UTF_8); hasher.putInt(stringBytes.length); hasher.putBytes(stringBytes); } else if (obj instanceof Boolean) { hasher.putInt(HashedObjectType.BOOLEAN.ordinal()); hasher.putBoolean((boolean) obj); } else if (obj instanceof Number) { // This is gross, but it mimics the logic originally in RawParser. Number number = (Number) obj; if (number.longValue() == number.doubleValue()) { hasher.putInt(HashedObjectType.LONG.ordinal()); hasher.putLong(number.longValue()); } else { hasher.putInt(HashedObjectType.DOUBLE.ordinal()); hasher.putDouble(number.doubleValue()); } } else if (obj instanceof Void || obj == null) { hasher.putInt(HashedObjectType.NULL.ordinal()); } else { throw new RuntimeException(String.format("Unsupported object %s (class %s)", obj, obj.getClass())); } }
From source file:org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl.java
/** * compute pseudorandom key unique for given seed and {@link #auxiliaryId} * @param seed random int but fixed per session */// w ww. j a v a 2 s . co m public void init(int seed) { if (auxiliaryId <= 0) { throw new IllegalStateException("auxiliaryId must be greater than 0"); } HashFunction mm32Hf = Hashing.murmur3_32(seed); Hasher hasher = mm32Hf.newHasher(8); hasher.putInt(auxiliaryId); long hash = 0xFFFFFFFFL & hasher.hash().asInt(); cookie = (auxiliaryId << 24) | (hash >> 8); }
From source file:com.facebook.buck.util.sha1.Sha1HashCode.java
/** * Updates the specified {@link Hasher} by putting the 20 bytes of this SHA-1 to it in order. * @return The specified {@link Hasher}. *///www .j av a 2s .co m public Hasher update(Hasher hasher) { hasher.putInt(firstFourBytes); hasher.putLong(nextEightBytes); hasher.putLong(lastEightBytes); return hasher; }
From source file:com.google.gerrit.server.change.ChangeResource.java
public void prepareETag(Hasher h, CurrentUser user) { h.putInt(JSON_FORMAT_VERSION).putLong(getChange().getLastUpdatedOn().getTime()) .putInt(getChange().getRowVersion()) .putInt(user.isIdentifiedUser() ? user.getAccountId().get() : 0); if (user.isIdentifiedUser()) { for (AccountGroup.UUID uuid : user.getEffectiveGroups().getKnownGroups()) { h.putBytes(uuid.get().getBytes(UTF_8)); }//from w ww. jav a 2 s . co m } byte[] buf = new byte[20]; ObjectId noteId; try { noteId = getNotes().loadRevision(); } catch (OrmException e) { noteId = null; // This ETag will be invalidated if it loads next time. } hashObjectId(h, noteId, buf); // TODO(dborowitz): Include more NoteDb and other related refs, e.g. drafts // and edits. for (ProjectState p : control.getProjectControl().getProjectState().tree()) { hashObjectId(h, p.getConfig().getRevision(), buf); } }
From source file:com.cloudera.oryx.app.classreg.example.Example.java
public Example(Feature target, Feature... features) { Preconditions.checkArgument(features != null); this.features = features; this.target = target; Hasher hasher = HASH.newHasher(); for (Feature feature : features) { if (feature != null) { hasher.putInt(feature.hashCode()); }//from w w w . j a v a 2 s . c o m } if (target != null) { hasher.putInt(target.hashCode()); } cachedHashCode = hasher.hashCode(); }
From source file:mx.itam.metodos.lshclustering.MinhashEmitMapper.java
@Override public void map(Text id, IntArrayWritable values, Context context) throws IOException, InterruptedException { for (int i = 0; i < functionsCount; i++) { hashValues[i] = Integer.MAX_VALUE; }//w w w .ja v a 2 s .c o m for (int i = 0; i < functionsCount; i++) { HashFunction hf = functions[i]; for (Writable wr : values.get()) { IntWritable value = (IntWritable) wr; int hash = hf.hashInt(value.get()).asInt(); if (hash < hashValues[i]) { hashValues[i] = hash; } } } Text sketch = new Text(); Hasher hasher = lsh.newHasher(); int band = 0; for (int i = 0; i < functionsCount; i++) { hasher.putInt(hashValues[i]); if (i > 0 && (i % rows) == 0) { sketch.set(band + "-" + hasher.hash().toString()); context.write(new SecondarySortKey(sketch, id), id); hasher = lsh.newHasher(); band++; } } sketch.set(band + "-" + hasher.hash().toString()); context.write(new SecondarySortKey(sketch, id), id); }