Create immutable storage
This commit is contained in:
parent
72eaca7a3b
commit
ca0bf943f7
8 changed files with 229 additions and 8 deletions
|
|
@ -1,8 +1,13 @@
|
|||
export const hash = (text: string): number => {
|
||||
// Return number between 0 and 1.
|
||||
// Return number from [0, 1)
|
||||
if (!text) {
|
||||
return 0;
|
||||
}
|
||||
const hash = Array.prototype.reduce.call(text, (hash, char) => (hash << 5) - hash + char.charCodeAt(0), 7);
|
||||
return hash / (Math.pow(2, 32) - 1);
|
||||
const hashValue = Array.prototype.reduce.call(
|
||||
// tslint:disable-next-line:no-bitwise
|
||||
text,
|
||||
(value, char) => ((value << 5) - value + (char.charCodeAt(0) as number)) | 0,
|
||||
7
|
||||
);
|
||||
return hashValue / (Math.pow(2, 32) - 2) + 0.5;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue