summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/compress/Hasher.java
blob: d991a98a5d01e2bc5cc5c67d4797fdafeb36e298 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.compress;

import net.openhft.hashing.LongHashFunction;

/**
 * Utility for hashing providing multiple hashing methods
 * @author baldersheim
 */
public class Hasher {
    private final LongHashFunction hasher;
    /** Uses net.openhft.hashing.LongHashFunction.xx3() */
    public static long xxh3(byte [] data) {
        return LongHashFunction.xx3().hashBytes(data);
    }
    public static long xxh3(byte [] data, long seed) {
        return LongHashFunction.xx3(seed).hashBytes(data);
    }

    private Hasher(LongHashFunction hasher) {
        this.hasher = hasher;
    }
    public static Hasher of(long seed) {
        return new Hasher(LongHashFunction.xx3(seed));
    }
    public long hash(long v) {
        return hasher.hashLong(v);
    }
    public long hash(String s) {
        return hasher.hashChars(s);
    }
}