better implementation of event.hash()
This commit is contained in:
parent
825f2d166e
commit
c58d707f49
1 changed files with 4 additions and 6 deletions
|
@ -18,13 +18,11 @@ export default class Event {
|
||||||
public get hash(): string {
|
public get hash(): string {
|
||||||
const str = JSON.stringify(this);
|
const str = JSON.stringify(this);
|
||||||
|
|
||||||
// from https://gist.github.com/jlevy/c246006675becc446360a798e2b2d781
|
// source: https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0?permalink_comment_id=2775538#gistcomment-2775538
|
||||||
let hash = 0;
|
let hash = 0;
|
||||||
for (let i = 0; i < str.length; i++) {
|
for (let i = 0; i < str.length; i++)
|
||||||
const char = str.charCodeAt(i);
|
hash = Math.imul(31, hash) + str.charCodeAt(i) | 0;
|
||||||
hash = (hash << 5) - hash + char;
|
|
||||||
hash &= hash; // Convert to 32bit integer
|
|
||||||
}
|
|
||||||
return new Uint32Array([hash])[0].toString(36);
|
return new Uint32Array([hash])[0].toString(36);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue