Example usage for com.google.common.hash Hashing murmur3_128

List of usage examples for com.google.common.hash Hashing murmur3_128

Introduction

In this page you can find the example usage for com.google.common.hash Hashing murmur3_128.

Prototype

public static HashFunction murmur3_128() 

Source Link

Document

Returns a hash function implementing the <a href="http://smhasher.googlecode.com/svn/trunk/MurmurHash3.cpp"> 128-bit murmur3 algorithm, x64 variant</a> (little-endian variant), using a seed value of zero.

Usage

From source file:edu.harvard.hms.dbmi.bd2k.irct.join.HashJoinImpl.java

public HashJoinImpl(ResultSet leftResultSet, ResultSet rightResultSet, int[] leftColumns, int[] rightColumns,
        HashJoinImplType joinType, long blockSize) throws ResultSetException {
    this.joinType = joinType;
    this.blockSize = blockSize;

    this.ignoreOuterColumns = new ArrayList<Integer>();
    this.ignoreInnerColumns = new ArrayList<Integer>();

    // If the left result set is smaller or equal to the right result set it
    // becomes the outer result set, and the right result set becomes the
    // inner one. Otherwise the outer result set is set to the right result
    // set and the inner result set is set to the left result set.
    if (leftResultSet.getSize() <= rightResultSet.getSize()) {
        this.outerResultSet = leftResultSet;
        this.outerColumns = leftColumns;
        this.innerResultSet = rightResultSet;
        this.innerColumns = rightColumns;
        this.isLeftOuterResultSet = true;
    } else {// w  ww. j a  v  a 2 s  . com
        this.outerResultSet = rightResultSet;
        this.outerColumns = rightColumns;
        this.innerResultSet = leftResultSet;
        this.innerColumns = leftColumns;
        this.isLeftOuterResultSet = false;
    }

    this.innerDataTypes = new PrimitiveDataType[this.innerColumns.length];
    this.outerDataTypes = new PrimitiveDataType[this.outerColumns.length];

    int counter = 0;
    for (int column : innerColumns) {
        this.innerDataTypes[counter] = this.innerResultSet.getColumn(column).getDataType();
        counter++;
    }
    counter = 0;
    for (int column : outerColumns) {
        this.outerDataTypes[counter] = this.outerResultSet.getColumn(column).getDataType();
        counter++;
    }

    hashFunction = Hashing.murmur3_128();
    hashMultiMap = LinkedHashMultimap.<HashCode, Row>create();
}

From source file:com.google.devtools.build.lib.rules.config.ConfigFeatureFlagConfiguration.java

/** Converts the given flag values into a string hash for use as an output directory fragment. */
private static String hashFlags(SortedMap<Label, String> flagValues) {
    // This hash function is relatively fast and stable between JVM invocations.
    Hasher hasher = Hashing.murmur3_128().newHasher();

    for (Map.Entry<Label, String> flag : flagValues.entrySet()) {
        hasher.putUnencodedChars(flag.getKey().toString());
        hasher.putUnencodedChars(flag.getValue());
    }//  w  w  w .ja v  a 2s  . c  o  m
    return hasher.hash().toString();
}

From source file:org.mayocat.localization.rest.resources.LocalizationResource.java

@GET
@Path("{languageTag}")
public Response getMessages(@PathParam("languageTag") String languageTag, @Context Request request) {
    try {/*from   w w w  .  j  a  va 2 s.c o m*/
        Optional<File> file = getForLanguageTag(languageTag);
        if (!file.isPresent()) {
            Locale languageAsLocale = Locale.forLanguageTag(languageTag);
            if (!languageAsLocale.getCountry().equals("")) {
                // Try without the country variant
                file = getForLanguageTag(languageAsLocale.getLanguage());
            }

            if (!file.isPresent()) {
                // Try for the shop's default locale
                Locale defaultLocale = context.getSettings(GeneralSettings.class).getLocales().getMainLocale()
                        .getValue();
                file = getForLanguageTag(defaultLocale.toLanguageTag());
                if (!file.isPresent() && !defaultLocale.getCountry().equals("")) {
                    file = getForLanguageTag(defaultLocale.getLanguage());
                }
            }

            if (!file.isPresent()) {
                // Try english at last
                file = getForLanguageTag(Locale.ENGLISH.toLanguageTag());

                // Then surrender
            }
        }

        if (!file.isPresent()) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }

        String tag = Files.hash(file.get(), Hashing.murmur3_128()).toString();
        EntityTag eTag = new EntityTag(tag);

        URL url = file.get().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);

        if (builder == null) {
            Properties properties = Properties.Factory.getInstance(file.get(), Charsets.UTF_8);
            builder = Response.ok(properties.getPropertyMap());
        }

        return builder.cacheControl(cacheControl).lastModified(new Date(lastModified)).build();
    } catch (FileNotFoundException e) {
        return Response.status(Response.Status.NOT_FOUND).build();
    } catch (IOException e) {
        return Response.serverError().build();
    }
}

From source file:com.facebook.buck.jvm.java.JarDumper.java

private Stream<String> dumpBinaryFile(String name, InputStream inputStream) throws IOException {
    try (HashingInputStream is = new HashingInputStream(Hashing.murmur3_128(), inputStream)) {
        ByteStreams.exhaust(is);/*from w ww.  j  a  va 2 s.  co m*/
        return Stream.of(String.format("Murmur3-128 of %s: %s", name, is.hash().toString()));
    }
}

From source file:dk.dma.ais.store.AisStoreSchema.java

/**
 * Calculates a message digest for the given messages (AisPackets).
 *///from  w ww  .jav  a2 s.  c  o  m
public static final byte[] digest(AisPacket packet) {
    return Hashing.murmur3_128().hashUnencodedChars(packet.getStringMessage()).asBytes();
}

From source file:com.mapr.synth.NestedRandom.java

private long hash(long seed) {
    Hasher h = Hashing.murmur3_128().newHasher();
    h.putLong(seed);
    hash(h);
    return h.hash().asLong();
}

From source file:org.apache.james.jmap.methods.integration.cucumber.UserStepdefs.java

private String generatePassword(String username) {
    return Hashing.murmur3_128().hashString(username, Charsets.UTF_8).toString();
}

From source file:org.apache.kylin.engine.mr.steps.CalculateStatsFromBaseCuboidMapper.java

@Override
protected void doSetup(Context context) throws IOException {
    Configuration conf = context.getConfiguration();
    HadoopUtil.setCurrentConfiguration(conf);
    KylinConfig config = AbstractHadoopJob.loadKylinPropsAndMetadata();

    String cubeName = conf.get(BatchConstants.CFG_CUBE_NAME);
    CubeInstance cube = CubeManager.getInstance(config).getCube(cubeName);
    CubeDesc cubeDesc = cube.getDescriptor();
    CubeSegment cubeSegment = cube.getSegmentById(conf.get(BatchConstants.CFG_CUBE_SEGMENT_ID));

    baseCuboidId = cube.getCuboidScheduler().getBaseCuboidId();
    nRowKey = cubeDesc.getRowkey().getRowKeyColumns().length;

    String cuboidModeName = conf.get(BatchConstants.CFG_CUBOID_MODE);
    Set<Long> cuboidIdSet = cube.getCuboidsByMode(cuboidModeName);

    cuboidIds = cuboidIdSet.toArray(new Long[cuboidIdSet.size()]);
    allCuboidsBitSet = CuboidUtil.getCuboidBitSet(cuboidIds, nRowKey);

    samplingPercentage = Integer/*from  w w w . j a  va2 s  . c  o  m*/
            .parseInt(context.getConfiguration().get(BatchConstants.CFG_STATISTICS_SAMPLING_PERCENT));

    allCuboidsHLL = new HLLCounter[cuboidIds.length];
    for (int i = 0; i < cuboidIds.length; i++) {
        allCuboidsHLL[i] = new HLLCounter(cubeDesc.getConfig().getCubeStatsHLLPrecision());
    }

    //for KYLIN-2518 backward compatibility
    if (KylinVersion.isBefore200(cubeDesc.getVersion())) {
        isUsePutRowKeyToHllNewAlgorithm = false;
        hf = Hashing.murmur3_32();
        logger.info("Found KylinVersion : {}. Use old algorithm for cuboid sampling.", cubeDesc.getVersion());
    } else {
        isUsePutRowKeyToHllNewAlgorithm = true;
        rowHashCodesLong = new long[nRowKey];
        hf = Hashing.murmur3_128();
        logger.info(
                "Found KylinVersion : {}. Use new algorithm for cuboid sampling. About the details of the new algorithm, please refer to KYLIN-2518",
                cubeDesc.getVersion());
    }

    rowKeyDecoder = new RowKeyDecoder(cubeSegment);
}

From source file:org.lightjason.agentspeak.action.builtin.crypto.CHash.java

/**
 * runs hashing function with difference between Google Guava hashing and Java default digest
 *
 * @param p_context execution context/*w w w.j a  v a  2s  .  c om*/
 * @param p_algorithm algorithm name
 * @param p_data byte data representation
 * @return hash value
 */
private static String hash(@Nonnull final IContext p_context, @Nonnull final String p_algorithm,
        @Nonnull final byte[] p_data) {
    switch (p_algorithm.trim().toLowerCase(Locale.ROOT)) {
    case "adler-32":
        return Hashing.adler32().newHasher().putBytes(p_data).hash().toString();

    case "crc-32":
        return Hashing.crc32().newHasher().putBytes(p_data).hash().toString();

    case "crc-32c":
        return Hashing.crc32c().newHasher().putBytes(p_data).hash().toString();

    case "murmur3-32":
        return Hashing.murmur3_32().newHasher().putBytes(p_data).hash().toString();

    case "murmur3-128":
        return Hashing.murmur3_128().newHasher().putBytes(p_data).hash().toString();

    case "siphash-2-4":
        return Hashing.sipHash24().newHasher().putBytes(p_data).hash().toString();

    default:
        try {
            return BaseEncoding.base16().encode(MessageDigest.getInstance(p_algorithm).digest(p_data))
                    .toLowerCase(Locale.ROOT);
        } catch (final NoSuchAlgorithmException l_exception) {
            throw new CRuntimeException(l_exception, p_context);
        }
    }
}

From source file:org.lightjason.agentspeak.action.buildin.crypto.CHash.java

/**
 * runs hashing function with difference between Google Guava hashing and Java default digest
 *
 * @param p_algorithm algorithm name//from w w  w  .jav a  2  s  . c  o  m
 * @param p_data byte data representation
 * @return hash value
 *
 * @throws NoSuchAlgorithmException on unknown hashing algorithm
 */
private String hash(final String p_algorithm, final byte[] p_data) throws NoSuchAlgorithmException {
    switch (p_algorithm.trim().toLowerCase(Locale.ROOT)) {
    case "adler-32":
        return Hashing.adler32().newHasher().putBytes(p_data).hash().toString();

    case "crc-32":
        return Hashing.crc32().newHasher().putBytes(p_data).hash().toString();

    case "crc-32c":
        return Hashing.crc32c().newHasher().putBytes(p_data).hash().toString();

    case "murmur3-32":
        return Hashing.murmur3_32().newHasher().putBytes(p_data).hash().toString();

    case "murmur3-128":
        return Hashing.murmur3_128().newHasher().putBytes(p_data).hash().toString();

    case "siphash-2-4":
        return Hashing.sipHash24().newHasher().putBytes(p_data).hash().toString();

    default:
        return String.format("%032x", new BigInteger(1, MessageDigest.getInstance(p_algorithm).digest(p_data)));
    }
}