List of usage examples for com.google.common.hash Hashing murmur3_128
public static HashFunction murmur3_128()
From source file:io.druid.jackson.AggregatorsModule.java
public AggregatorsModule() { super("AggregatorFactories"); if (ComplexMetrics.getSerdeForType("hyperUnique") == null) { ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde(Hashing.murmur3_128())); }/* w w w . j ava 2 s . c om*/ setMixInAnnotation(AggregatorFactory.class, AggregatorFactoryMixin.class); setMixInAnnotation(PostAggregator.class, PostAggregatorMixin.class); }
From source file:fr.inria.eventcloud.api.Skolemizator.java
private static Node createSkolemUri(Node subjectOrObject, Map<Node, Node> assignedSkolems) { UUID randomId = UUID.randomUUID(); Hasher hasher = Hashing.murmur3_128().newHasher(); hasher.putString(subjectOrObject.toString(), Charsets.UTF_8); hasher.putLong(randomId.getMostSignificantBits()); hasher.putLong(randomId.getLeastSignificantBits()); Node skolem = NodeFactory//from w w w.ja va 2 s.c o m .createURI(SKOLEM_URI_SUFFIX + SKOLEM_URI_PATH_COMPONENT + hasher.hash().toString()); assignedSkolems.put(subjectOrObject, skolem); return skolem; }
From source file:example.MetadataStoreServer.java
private ByteString hashLine(String line) { return ByteString.copyFrom(Hashing.murmur3_128().hashBytes(line.getBytes()).asBytes()); }
From source file:org.mayocat.shop.front.resources.ResourceResource.java
@GET @Path("{path:.+}") public Response getResource(@PathParam("path") String resource, @Context Request request) throws Exception { ThemeResource themeResource = themeFileResolver.getResource(resource, context.getRequest().getBreakpoint()); if (themeResource == null) { logger.debug("Resource [{}] not found", resource); throw new WebApplicationException(404); }//from ww w . j a va 2 s . c om File file; switch (themeResource.getType()) { default: case FILE: file = themeResource.getPath().toFile(); break; case CLASSPATH_RESOURCE: URI uri = Resources.getResource(themeResource.getPath().toString()).toURI(); if (uri.getScheme().equals("jar")) { // Not supported for now return Response.status(Response.Status.NOT_FOUND).build(); } file = new File(uri); break; } String tag = Files.hash(file, Hashing.murmur3_128()).toString(); EntityTag eTag = new EntityTag(tag); URL url = file.toURI().toURL(); long lastModified = ResourceURL.getLastModified(url); if (lastModified < 1) { // Something went wrong trying to get the last modified time: just use the current time lastModified = System.currentTimeMillis(); } // zero out the millis since the date we get back from If-Modified-Since will not have them lastModified = (lastModified / 1000) * 1000; CacheControl cacheControl = new CacheControl(); cacheControl.setMaxAge(24 * 3600); Response.ResponseBuilder builder = request.evaluatePreconditions(new Date(lastModified), eTag); String mimeType = guessMimeType(file).or("application/octet-stream"); if (builder == null) { if (mimeType.equals("application/javascript")) { // Handle javascript files as a special case. Something (what ?) is serializing them as URIs instead // of file contents. // FIXME: find out what at in Jersey or Jackson or DW is doing that and disable that behavior builder = Response.ok(Files.toString(file, Charsets.UTF_8), mimeType); } else { builder = Response.ok(file, mimeType); } } return builder.cacheControl(cacheControl).lastModified(new Date(lastModified)).build(); }
From source file:io.blobkeeper.common.service.IdGeneratorService.java
public HashCode getHash(long id) { return Hashing.murmur3_128().hashLong(id); }
From source file:org.apache.beam.sdk.io.synthetic.delay.SyntheticDelay.java
/** Keep cpu busy for {@code delayMillis} by calculating lots of hashes. */ private static void cpuDelay(long delayMillis) { // Note that the delay is enforced in terms of walltime. That implies this thread may not // keep CPU busy if it gets preempted by other threads. There is more of chance of this // occurring in a streaming pipeline as there could be lots of threads running this. The loop // measures cpu time spent for each iteration, so that these effects are some what minimized. long cpuMicros = delayMillis * 1000; Stopwatch timer = Stopwatch.createUnstarted(); while (timer.elapsed(TimeUnit.MICROSECONDS) < cpuMicros) { // Find a long which hashes to HASH in lowest MASK bits. // Values chosen to roughly take 1ms on typical workstation. timer.start();//from ww w.j av a 2 s. c o m long p = INIT_PLAINTEXT; while (true) { long t = Hashing.murmur3_128().hashLong(p).asLong(); if ((t & MASK) == (HASH & MASK)) { break; } p++; } timer.stop(); } }
From source file:org.apache.rocketmq.filter.util.BloomFilter.java
/** * Calculate bit positions of {@code str}. * <p>/*from w w w .ja v a 2s .c o m*/ * See "Less Hashing, Same Performance: Building a Better Bloom Filter" by Adam Kirsch and Michael * Mitzenmacher. * </p> */ public int[] calcBitPositions(String str) { int[] bitPositions = new int[this.k]; long hash64 = Hashing.murmur3_128().hashString(str, UTF_8).asLong(); int hash1 = (int) hash64; int hash2 = (int) (hash64 >>> 32); for (int i = 1; i <= this.k; i++) { int combinedHash = hash1 + (i * hash2); // Flip all the bits if it's negative (guaranteed positive number) if (combinedHash < 0) { combinedHash = ~combinedHash; } bitPositions[i - 1] = combinedHash % this.m; } return bitPositions; }
From source file:io.druid.query.aggregation.HyperloglogAggregator.java
@Override public void aggregate() { final Object value = selector.get(); if (value == null) { return;/*from www . ja v a 2s . co m*/ } if (value instanceof TIntByteHashMap) { final TIntByteHashMap newIbMap = (TIntByteHashMap) value; final int[] indexes = newIbMap.keys(); for (int index : indexes) { if (ibMap.get(index) == ibMap.getNoEntryValue() || newIbMap.get(index) > ibMap.get(index)) { ibMap.put(index, newIbMap.get(index)); } } } else if (value instanceof String) { log.debug("value [%s]", selector.get()); final long id = Hashing.murmur3_128().hashString((String) (value)).asLong(); final int bucket = (int) (id >>> (Long.SIZE - log2m)); final int zerolength = Long.numberOfLeadingZeros((id << log2m) | (1 << (log2m - 1)) + 1) + 1; if (ibMap.get(bucket) == ibMap.getNoEntryValue() || ibMap.get(bucket) < (byte) zerolength) { ibMap.put(bucket, (byte) zerolength); } } else { throw new ISE("Aggregate does not support values of type[%s]", value.getClass().getName()); } }
From source file:org.apache.kylin.rest.security.KylinAuthenticationProvider.java
public KylinAuthenticationProvider(AuthenticationProvider authenticationProvider) { super();/*from w w w .j ava 2s . co m*/ Assert.notNull(authenticationProvider, "The embedded authenticationProvider should not be null."); this.authenticationProvider = authenticationProvider; hf = Hashing.murmur3_128(); }
From source file:org.fenixedu.academic.domain.reports.GepReportFile.java
public static String getWrittenEvaluationCode(WrittenEvaluation writtenEvaluation) { StringBuilder code = new StringBuilder().append(writtenEvaluation.getInterval().toString()) .append(writtenEvaluation.getFullName()).append(writtenEvaluation.getEvaluationType().toString()); writtenEvaluation.getAssociatedExecutionCoursesSet().stream() .forEach(ec -> code.append(getExecutionCourseCode(ec))); return Hashing.murmur3_128().hashBytes(code.toString().getBytes(StandardCharsets.UTF_8)).toString(); }