Vydané zdroje
Stáhnout zdroje ZIP
CH-J Server Manager
Procházejte adresáře a soubory konkrétního vydání aplikace.
Zdroje jsou zveřejněny pod CH-J Proprietary Software License 1.14. Jejich dostupnost nemění licenční podmínky ani neposkytuje další oprávnění.
1
"use strict";3
// Ported from google/cityhash. See vendor/cityHash/LICENSE.txt.5
const fs = require("node:fs");7
const MASK64 = 0xffffffffffffffffn;8
const k0 = 0xc3a5c85c97cb3127n;9
const k1 = 0xb492b66fbe98f273n;10
const k2 = 0x9ae16a3b2f90404fn;11
const c1 = 0xcc9e2d51;12
const c2 = 0x1b873593;13
const u64 = (value) => BigInt.asUintN(64, value);14
const u32 = (value) => value >>> 0;16
class FileView {17
constructor(fd, length, cacheBytes = 1024 * 1024) {18
this.fd = fd;19
this.length = length;20
this.cacheBytes = cacheBytes;21
this.cache = Buffer.alloc(0);22
this.cacheStart = -1;23
}24
_ensure(offset, width) {25
if (!Number.isSafeInteger(offset) || offset < 0 || offset + width > this.length) throw new RangeError("Hash reader access is outside the selected file.");26
if (offset >= this.cacheStart && offset + width <= this.cacheStart + this.cache.length) return;27
const start = Math.floor(offset / this.cacheBytes) * this.cacheBytes;28
const bytes = Math.min(this.cacheBytes + 16, this.length - start);29
this.cache = Buffer.allocUnsafe(bytes);30
let read = 0;31
while (read < bytes) {32
const count = fs.readSync(this.fd, this.cache, read, bytes - read, start + read);33
if (!count) throw new Error("Selected file ended unexpectedly.");34
read += count;35
}36
this.cacheStart = start;37
}38
byte(offset) { this._ensure(offset, 1); return this.cache[offset - this.cacheStart]; }39
u32(offset) { this._ensure(offset, 4); return this.cache.readUInt32LE(offset - this.cacheStart); }40
u64(offset) { this._ensure(offset, 8); return this.cache.readBigUInt64LE(offset - this.cacheStart); }41
}43
function rotate32(value, shift) { return shift === 0 ? u32(value) : u32((value >>> shift) | (value << (32 - shift))); }44
function rotate64(value, shift) { return shift === 0 ? u64(value) : u64((value >> BigInt(shift)) | (value << BigInt(64 - shift))); }45
function bswap32(value) { return (((value & 0xff) << 24) | ((value & 0xff00) << 8) | ((value >>> 8) & 0xff00) | (value >>> 24)) >>> 0; }46
function bswap64(value) {47
let output = 0n;48
for (let index = 0n; index < 8n; index += 1n) output |= ((value >> (index * 8n)) & 0xffn) << ((7n - index) * 8n);49
return output;50
}51
function fmix(value) { value ^= value >>> 16; value = Math.imul(value, 0x85ebca6b); value ^= value >>> 13; value = Math.imul(value, 0xc2b2ae35); return u32(value ^ (value >>> 16)); }52
function mur(a, h) { a = Math.imul(a, c1); a = rotate32(a, 17); a = Math.imul(a, c2); h ^= a; h = rotate32(h, 19); return u32(Math.imul(h, 5) + 0xe6546b64); }53
function shiftMix(value) { return u64(value ^ (value >> 47n)); }54
function hashLen16(u, v, mul = 0x9ddfea08eb382d69n) {55
let a = u64((u ^ v) * mul); a ^= a >> 47n;56
let b = u64((v ^ a) * mul); b ^= b >> 47n;57
return u64(b * mul);58
}59
function weakHash(view, offset, a, b) {60
const w = view.u64(offset); const x = view.u64(offset + 8); const y = view.u64(offset + 16); const z = view.u64(offset + 24);61
a = u64(a + w); b = rotate64(u64(b + a + z), 21); const c = a;62
a = u64(a + x + y); b = u64(b + rotate64(a, 44));63
return [u64(a + z), u64(b + c)];64
}66
function cityHash32(view, base = 0, length = view.length - base) {67
const fetch = (offset) => view.u32(base + offset);68
if (length <= 4) {69
let b = 0; let c = 9;70
for (let index = 0; index < length; index += 1) { const byte = view.byte(base + index); const signed = byte > 127 ? byte - 256 : byte; b = u32(Math.imul(b, c1) + signed); c ^= b; }71
return fmix(mur(b, mur(length, c)));72
}73
if (length <= 12) {74
let a = length; let b = u32(length * 5); const c = u32(9 + fetch((length >>> 1) & 4)); const d = b;75
a = u32(a + fetch(0)); b = u32(b + fetch(length - 4));76
return fmix(mur(c, mur(b, mur(a, d))));77
}78
if (length <= 24) {79
const a = fetch(-4 + (length >>> 1)); const b = fetch(4); const c = fetch(length - 8);80
const d = fetch(length >>> 1); const e = fetch(0); const f = fetch(length - 4);81
return fmix(mur(f, mur(e, mur(d, mur(c, mur(b, mur(a, length)))))));82
}83
let h = u32(length); let g = Math.imul(c1, h) >>> 0; let f = g;84
const tail = [length - 4, length - 8, length - 16, length - 12, length - 20].map((offset) => Math.imul(rotate32(Math.imul(fetch(offset), c1), 17), c2) >>> 0);85
h ^= tail[0]; h = u32(Math.imul(rotate32(h, 19), 5) + 0xe6546b64);86
h ^= tail[2]; h = u32(Math.imul(rotate32(h, 19), 5) + 0xe6546b64);87
g ^= tail[1]; g = u32(Math.imul(rotate32(g, 19), 5) + 0xe6546b64);88
g ^= tail[3]; g = u32(Math.imul(rotate32(g, 19), 5) + 0xe6546b64);89
f = u32(f + tail[4]); f = u32(Math.imul(rotate32(f, 19), 5) + 0xe6546b64);90
let offset = 0; let iterations = Math.floor((length - 1) / 20);91
do {92
const a0 = Math.imul(rotate32(Math.imul(fetch(offset), c1), 17), c2) >>> 0;93
const a1 = fetch(offset + 4);94
const a2 = Math.imul(rotate32(Math.imul(fetch(offset + 8), c1), 17), c2) >>> 0;95
const a3 = Math.imul(rotate32(Math.imul(fetch(offset + 12), c1), 17), c2) >>> 0;96
const a4 = fetch(offset + 16);97
h ^= a0; h = u32(Math.imul(rotate32(h, 18), 5) + 0xe6546b64);98
f = u32(f + a1); f = Math.imul(rotate32(f, 19), c1) >>> 0;99
g = u32(g + a2); g = u32(Math.imul(rotate32(g, 18), 5) + 0xe6546b64);100
h ^= u32(a3 + a1); h = u32(Math.imul(rotate32(h, 19), 5) + 0xe6546b64);101
g ^= a4; g = Math.imul(bswap32(g), 5) >>> 0;102
h = bswap32(u32(h + Math.imul(a4, 5))); f = u32(f + a0);103
const oldF = f; f = g; g = h; h = oldF;104
offset += 20; iterations -= 1;105
} while (iterations);106
g = Math.imul(rotate32(Math.imul(rotate32(g, 11), c1), 17), c1) >>> 0;107
f = Math.imul(rotate32(Math.imul(rotate32(f, 11), c1), 17), c1) >>> 0;108
h = rotate32(u32(h + g), 19); h = u32(Math.imul(h, 5) + 0xe6546b64); h = Math.imul(rotate32(h, 17), c1) >>> 0;109
h = rotate32(u32(h + f), 19); h = u32(Math.imul(h, 5) + 0xe6546b64); return Math.imul(rotate32(h, 17), c1) >>> 0;110
}112
function hash0to16(view, offset, length) {113
if (length >= 8) { const mul = u64(k2 + BigInt(length * 2)); const a = u64(view.u64(offset) + k2); const b = view.u64(offset + length - 8); return hashLen16(u64(rotate64(b, 37) * mul + a), u64((rotate64(a, 25) + b) * mul), mul); }114
if (length >= 4) { const mul = u64(k2 + BigInt(length * 2)); const a = BigInt(view.u32(offset)); return hashLen16(BigInt(length) + (a << 3n), BigInt(view.u32(offset + length - 4)), mul); }115
if (length > 0) { const a = BigInt(view.byte(offset)); const b = BigInt(view.byte(offset + (length >>> 1))); const c = BigInt(view.byte(offset + length - 1)); const y = a + (b << 8n); const z = BigInt(length) + (c << 2n); return u64(shiftMix(u64(y * k2 ^ z * k0)) * k2); }116
return k2;117
}118
function hash17to32(view, offset, length) {119
const mul = u64(k2 + BigInt(length * 2)); const a = u64(view.u64(offset) * k1); const b = view.u64(offset + 8);120
const c = u64(view.u64(offset + length - 8) * mul); const d = u64(view.u64(offset + length - 16) * k2);121
return hashLen16(u64(rotate64(u64(a + b), 43) + rotate64(c, 30) + d), u64(a + rotate64(u64(b + k2), 18) + c), mul);122
}123
function hash33to64(view, offset, length) {124
const mul = u64(k2 + BigInt(length * 2)); let a = u64(view.u64(offset) * k2); let b = view.u64(offset + 8); const c = view.u64(offset + length - 24); const d = view.u64(offset + length - 32);125
const e = u64(view.u64(offset + 16) * k2); const f = u64(view.u64(offset + 24) * 9n); const g = view.u64(offset + length - 8); const h = u64(view.u64(offset + length - 16) * mul);126
const u = u64(rotate64(u64(a + g), 43) + u64((rotate64(b, 30) + c) * 9n)); const v = u64(((a + g) ^ d) + f + 1n);127
const w = u64(bswap64(u64((u + v) * mul)) + h); const x = u64(rotate64(u64(e + f), 42) + c); const y = u64((bswap64(u64((v + w) * mul)) + g) * mul); const z = u64(e + f + c);128
a = u64(bswap64(u64((x + z) * mul + y)) + b); b = u64(shiftMix(u64((z + a) * mul + d + h)) * mul); return u64(b + x);129
}131
function cityHash64(view, base = 0, length = view.length - base) {132
if (length <= 16) return hash0to16(view, base, length);133
if (length <= 32) return hash17to32(view, base, length);134
if (length <= 64) return hash33to64(view, base, length);135
let x = view.u64(base + length - 40); let y = u64(view.u64(base + length - 16) + view.u64(base + length - 56));136
let z = hashLen16(u64(view.u64(base + length - 48) + BigInt(length)), view.u64(base + length - 24));137
let v = weakHash(view, base + length - 64, BigInt(length), z); let w = weakHash(view, base + length - 32, u64(y + k1), x);138
x = u64(x * k1 + view.u64(base)); let remaining = (length - 1) & ~63; let offset = base;139
do {140
x = u64(rotate64(u64(x + y + v[0] + view.u64(offset + 8)), 37) * k1); y = u64(rotate64(u64(y + v[1] + view.u64(offset + 48)), 42) * k1);141
x ^= w[1]; y = u64(y + v[0] + view.u64(offset + 40)); z = u64(rotate64(u64(z + w[0]), 33) * k1);142
v = weakHash(view, offset, u64(v[1] * k1), u64(x + w[0])); w = weakHash(view, offset + 32, u64(z + w[1]), u64(y + view.u64(offset + 16)));143
[z, x] = [x, z]; offset += 64; remaining -= 64;144
} while (remaining);145
return hashLen16(u64(hashLen16(v[0], w[0]) + u64(shiftMix(y) * k1) + z), u64(hashLen16(v[1], w[1]) + x));146
}148
function cityMurmur(view, offset, length, seed) {149
let a = seed[0]; let b = seed[1]; let c = 0n; let d = 0n; let position = offset; let remaining = length;150
if (remaining <= 16) { a = u64(shiftMix(u64(a * k1)) * k1); c = u64(b * k1 + hash0to16(view, position, remaining)); d = shiftMix(u64(a + (remaining >= 8 ? view.u64(position) : c))); }151
else {152
c = hashLen16(u64(view.u64(position + remaining - 8) + k1), a); d = hashLen16(u64(b + BigInt(remaining)), u64(c + view.u64(position + remaining - 16))); a = u64(a + d);153
do { a ^= u64(shiftMix(u64(view.u64(position) * k1)) * k1); a = u64(a * k1); b ^= a; c ^= u64(shiftMix(u64(view.u64(position + 8) * k1)) * k1); c = u64(c * k1); d ^= c; position += 16; remaining -= 16; } while (remaining > 16);154
}155
a = hashLen16(a, c); b = hashLen16(d, b); return [u64(a ^ b), hashLen16(b, a)];156
}158
function cityHash128WithSeed(view, base, length, seed) {159
if (length < 128) return cityMurmur(view, base, length, seed);160
let x = seed[0]; let y = seed[1]; let z = u64(BigInt(length) * k1); let offset = base; let remaining = length;161
let v = [u64(rotate64(y ^ k1, 49) * k1 + view.u64(offset)), 0n]; v[1] = u64(rotate64(v[0], 42) * k1 + view.u64(offset + 8));162
let w = [u64(rotate64(u64(y + z), 35) * k1 + x), u64(rotate64(u64(x + view.u64(offset + 88)), 53) * k1)];163
do {164
for (let pass = 0; pass < 2; pass += 1) {165
x = u64(rotate64(u64(x + y + v[0] + view.u64(offset + 8)), 37) * k1); y = u64(rotate64(u64(y + v[1] + view.u64(offset + 48)), 42) * k1);166
x ^= w[1]; y = u64(y + v[0] + view.u64(offset + 40)); z = u64(rotate64(u64(z + w[0]), 33) * k1);167
v = weakHash(view, offset, u64(v[1] * k1), u64(x + w[0])); w = weakHash(view, offset + 32, u64(z + w[1]), u64(y + view.u64(offset + 16))); [z, x] = [x, z]; offset += 64;168
}169
remaining -= 128;170
} while (remaining >= 128);171
x = u64(x + rotate64(u64(v[0] + z), 49) * k0); y = u64(y * k0 + rotate64(w[1], 37)); z = u64(z * k0 + rotate64(w[0], 27)); w[0] = u64(w[0] * 9n); v[0] = u64(v[0] * k0);172
for (let done = 0; done < remaining;) {173
done += 32; y = u64(rotate64(u64(x + y), 42) * k0 + v[1]); w[0] = u64(w[0] + view.u64(offset + remaining - done + 16)); x = u64(x * k0 + w[0]);174
z = u64(z + w[1] + view.u64(offset + remaining - done)); w[1] = u64(w[1] + v[0]); v = weakHash(view, offset + remaining - done, u64(v[0] + z), v[1]); v[0] = u64(v[0] * k0);175
}176
x = hashLen16(x, v[0]); y = hashLen16(u64(y + z), w[0]); return [u64(hashLen16(u64(x + v[1]), w[1]) + y), u64(hashLen16(u64(x + w[1]), u64(y + v[1])))];177
}179
function cityHash128(view, base = 0, length = view.length - base) {180
return length >= 16 ? cityHash128WithSeed(view, base + 16, length - 16, [view.u64(base), u64(view.u64(base + 8) + k0)]) : cityHash128WithSeed(view, base, length, [k0, k1]);181
}183
function numericDigest(value, bytes) { const output = Buffer.alloc(bytes); if (bytes === 4) output.writeUInt32BE(value); else output.writeBigUInt64BE(value); return output; }184
function digest128(value) { const output = Buffer.alloc(16); output.writeBigUInt64BE(value[1], 0); output.writeBigUInt64BE(value[0], 8); return output; }186
module.exports = { FileView, cityHash32, cityHash64, cityHash128, digest128, numericDigest };SHA-256: 830bf473f541f5787afab725f4e12a27b19549f197e1228cd5f36eb2e859ffff
SHA-256 archivu: 5ac91caf4fa32a6fdb114f2430deed486fbe7489d5eea343d1f034169fafb5e0