diff options
| author | s-ol <s+removethis@s-ol.nu> | 2024-03-26 18:23:18 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2024-03-26 18:23:58 +0000 |
| commit | dea3f32edf7ea11e7e47bbb14d9b64e856af18a5 (patch) | |
| tree | 2b52e71812c4afffe5e31c9e6570fcaad5680cdf /web/utils.js | |
| parent | web: selectable, hideable plots (diff) | |
| download | t937-serial-dea3f32edf7ea11e7e47bbb14d9b64e856af18a5.tar.gz t937-serial-dea3f32edf7ea11e7e47bbb14d9b64e856af18a5.zip | |
web: load/save/delete plots
Diffstat (limited to 'web/utils.js')
| -rw-r--r-- | web/utils.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/web/utils.js b/web/utils.js index d7cf657..53f49ab 100644 --- a/web/utils.js +++ b/web/utils.js @@ -32,3 +32,21 @@ export const range = (a, b=null) => { // return a Promise that resolves in n seconds export const sleep = (n) => new Promise(res => setTimeout(res, n*1000)); + +// hash an ArrayBuffer +export const hash = (data, seed = 0) => { + let h1 = 0xdeadbeef ^ seed; + let h2 = 0x41c6ce57 ^ seed; + + data = new Uint8Array(data); + for (const byte of data) { + h1 = Math.imul(h1 ^ byte, 2654435761); + h2 = Math.imul(h2 ^ byte, 1597334677); + } + + h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507); + h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909); + h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507); + h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909); + return 4294967296 * (2097151 & h2) + (h1 >>> 0); +}; |
