UNPKG

2.02 kBTypeScriptView Raw
1/**
2 * An incremental implementation of MurmurHash3 for JavaScript
3 */
4interface MurmurHash3 {
5 /**
6 * Get the result of the hash as a 32-bit positive integer.
7 * This performs the tail and finalizer portions of the algorithm, but does not store the result in the state object.
8 * This means that it is perfectly safe to get results and then continue adding strings via hash.
9 */
10 result(): number;
11
12 /**
13 * Reset the state object for reuse, optionally using the given seed (defaults to 0 like the constructor). Returns this so calls can be chained.
14 * @default 0
15 */
16 reset(seed?: number): this;
17
18 /**
19 * Incrementally add string to the hash.
20 * This can be called as many times as you want for the hash state object, including after a call to result()
21 */
22 hash(value: string): this;
23}
24declare var MurmurHash3: {
25 /**
26 * Get a hash state object, optionally initialized with the given string and seed.
27 * Seed must be a positive integer if provided.
28 * Calling this function without the new keyword will return a cached state object that has been reset.
29 * This is safe to use as long as the object is only used from a single thread and no other hashes are created while operating on this one.
30 * If this constraint cannot be met, you can use new to create a new state object
31 */
32 (text?: string, seed?: number): MurmurHash3;
33 /**
34 * Get a hash state object, optionally initialized with the given string and seed.
35 * Seed must be a positive integer if provided.
36 * Calling this function without the new keyword will return a cached state object that has been reset.
37 * This is safe to use as long as the object is only used from a single thread and no other hashes are created while operating on this one.
38 * If this constraint cannot be met, you can use new to create a new state object
39 */
40 new(text?: string, seed?: number): MurmurHash3;
41};
42
43export as namespace MurmurHash3;
44export = MurmurHash3;