@topgunbuild/native 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +46 -0
- package/build/Makefile +352 -0
- package/build/Release/.deps/Release/node_modules/.pnpm/node-addon-api@8.5.0/node_modules/node-addon-api/nothing.o.d +4 -0
- package/build/Release/.deps/Release/nothing.a.d +1 -0
- package/build/Release/.deps/Release/obj.target/topgun_hash/src/hash.o.d +19 -0
- package/build/Release/.deps/Release/topgun_hash.node.d +1 -0
- package/build/Release/node_modules/.pnpm/node-addon-api@8.5.0/node_modules/node-addon-api/nothing.o +0 -0
- package/build/Release/nothing.a +0 -0
- package/build/Release/obj.target/topgun_hash/src/hash.o +0 -0
- package/build/Release/topgun_hash.node +0 -0
- package/build/binding.Makefile +6 -0
- package/build/gyp-mac-tool +772 -0
- package/build/topgun_hash.target.mk +198 -0
- package/deps/xxhash/LICENSE +26 -0
- package/deps/xxhash/xxhash.h +7489 -0
- package/dist/hash.d.ts +83 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +314 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
- package/src/hash.cc +310 -0
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native xxHash64 module with JS fallback
|
|
3
|
+
*
|
|
4
|
+
* Provides high-performance hashing for Merkle tree operations.
|
|
5
|
+
* Falls back to JS implementation if native module is unavailable.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Native hash module interface
|
|
9
|
+
*/
|
|
10
|
+
export interface NativeHashModule {
|
|
11
|
+
xxhash64(data: Buffer | Uint8Array, seed?: bigint | number): bigint;
|
|
12
|
+
xxhash64AsNumber(data: Buffer | Uint8Array, seed?: number): number;
|
|
13
|
+
xxhash64Batch(buffers: (Buffer | Uint8Array)[], seed?: bigint | number): bigint[];
|
|
14
|
+
xxhash64BatchAsNumbers(buffers: (Buffer | Uint8Array)[], seed?: number): number[];
|
|
15
|
+
XxHash64State: new (seed?: bigint | number) => XxHash64StateInstance;
|
|
16
|
+
}
|
|
17
|
+
export interface XxHash64StateInstance {
|
|
18
|
+
update(data: Buffer | Uint8Array): this;
|
|
19
|
+
digest(): bigint;
|
|
20
|
+
digestAsNumber(): number;
|
|
21
|
+
reset(): this;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Try to load native hash module.
|
|
25
|
+
* Returns null if native module is not available.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getNativeHash(): NativeHashModule | null;
|
|
28
|
+
/**
|
|
29
|
+
* Check if native module is available.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isNativeHashAvailable(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Get the load error if native module failed to load.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getNativeHashLoadError(): Error | null;
|
|
36
|
+
/**
|
|
37
|
+
* JS fallback for xxhash64.
|
|
38
|
+
*/
|
|
39
|
+
export declare function xxhash64Fallback(data: Buffer | Uint8Array, seed?: bigint): bigint;
|
|
40
|
+
/**
|
|
41
|
+
* JS fallback returning 32-bit number.
|
|
42
|
+
*/
|
|
43
|
+
export declare function xxhash64FallbackAsNumber(data: Buffer | Uint8Array, seed?: number): number;
|
|
44
|
+
/**
|
|
45
|
+
* JS fallback for batch hash.
|
|
46
|
+
*/
|
|
47
|
+
export declare function xxhash64BatchFallback(buffers: (Buffer | Uint8Array)[], seed?: bigint): bigint[];
|
|
48
|
+
/**
|
|
49
|
+
* JS fallback for batch hash returning numbers.
|
|
50
|
+
*/
|
|
51
|
+
export declare function xxhash64BatchFallbackAsNumbers(buffers: (Buffer | Uint8Array)[], seed?: number): number[];
|
|
52
|
+
/**
|
|
53
|
+
* Compute xxHash64 of data.
|
|
54
|
+
* Uses native module if available, otherwise falls back to JS.
|
|
55
|
+
*/
|
|
56
|
+
export declare function xxhash64(data: Buffer | Uint8Array, seed?: bigint | number): bigint;
|
|
57
|
+
/**
|
|
58
|
+
* Compute xxHash64 and return as 32-bit number.
|
|
59
|
+
* This is more efficient when BigInt precision is not needed.
|
|
60
|
+
*/
|
|
61
|
+
export declare function xxhash64AsNumber(data: Buffer | Uint8Array, seed?: number): number;
|
|
62
|
+
/**
|
|
63
|
+
* Compute xxHash64 for multiple buffers.
|
|
64
|
+
*/
|
|
65
|
+
export declare function xxhash64Batch(buffers: (Buffer | Uint8Array)[], seed?: bigint | number): bigint[];
|
|
66
|
+
/**
|
|
67
|
+
* Compute xxHash64 for multiple buffers, returning 32-bit numbers.
|
|
68
|
+
*/
|
|
69
|
+
export declare function xxhash64BatchAsNumbers(buffers: (Buffer | Uint8Array)[], seed?: number): number[];
|
|
70
|
+
/**
|
|
71
|
+
* Create streaming hash state.
|
|
72
|
+
*/
|
|
73
|
+
export declare function createXxHash64State(seed?: bigint | number): XxHash64StateInstance;
|
|
74
|
+
/**
|
|
75
|
+
* Hash a string using xxHash64.
|
|
76
|
+
* Returns 32-bit number for compatibility with existing hashString() usage.
|
|
77
|
+
*/
|
|
78
|
+
export declare function hashString(str: string): number;
|
|
79
|
+
/**
|
|
80
|
+
* Hash a string using xxHash64, returning full 64-bit BigInt.
|
|
81
|
+
*/
|
|
82
|
+
export declare function hashStringBigInt(str: string, seed?: bigint): bigint;
|
|
83
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACpE,gBAAgB,CAAC,IAAI,EAAE,MA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C,IAAI,GAAE,MAAU,GACf,MAAM,EAAE,CAEV;AAID;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,IAAI,GAAE,MAAM,GAAG,MAAU,GACxB,MAAM,CAMR;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,IAAI,GAAE,MAAU,GACf,MAAM,CAMR;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,EAChC,IAAI,GAAE,MAAM,GAAG,MAAU,GACxB,MAAM,EAAE,CAYV;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,EAChC,IAAI,GAAE,MAAU,GACf,MAAM,EAAE,CAMV;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,GAAE,MAAM,GAAG,MAAU,GACxB,qBAAqB,CAMvB;AAyCD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAAW,GAAG,MAAM,CAMvE"}
|
package/dist/hash.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Native xxHash64 module with JS fallback
|
|
4
|
+
*
|
|
5
|
+
* Provides high-performance hashing for Merkle tree operations.
|
|
6
|
+
* Falls back to JS implementation if native module is unavailable.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getNativeHash = getNativeHash;
|
|
10
|
+
exports.isNativeHashAvailable = isNativeHashAvailable;
|
|
11
|
+
exports.getNativeHashLoadError = getNativeHashLoadError;
|
|
12
|
+
exports.xxhash64Fallback = xxhash64Fallback;
|
|
13
|
+
exports.xxhash64FallbackAsNumber = xxhash64FallbackAsNumber;
|
|
14
|
+
exports.xxhash64BatchFallback = xxhash64BatchFallback;
|
|
15
|
+
exports.xxhash64BatchFallbackAsNumbers = xxhash64BatchFallbackAsNumbers;
|
|
16
|
+
exports.xxhash64 = xxhash64;
|
|
17
|
+
exports.xxhash64AsNumber = xxhash64AsNumber;
|
|
18
|
+
exports.xxhash64Batch = xxhash64Batch;
|
|
19
|
+
exports.xxhash64BatchAsNumbers = xxhash64BatchAsNumbers;
|
|
20
|
+
exports.createXxHash64State = createXxHash64State;
|
|
21
|
+
exports.hashString = hashString;
|
|
22
|
+
exports.hashStringBigInt = hashStringBigInt;
|
|
23
|
+
let nativeModule = null;
|
|
24
|
+
let loadAttempted = false;
|
|
25
|
+
let loadError = null;
|
|
26
|
+
/**
|
|
27
|
+
* Try to load native hash module.
|
|
28
|
+
* Returns null if native module is not available.
|
|
29
|
+
*/
|
|
30
|
+
function getNativeHash() {
|
|
31
|
+
if (loadAttempted)
|
|
32
|
+
return nativeModule;
|
|
33
|
+
loadAttempted = true;
|
|
34
|
+
try {
|
|
35
|
+
// Try release build first
|
|
36
|
+
nativeModule = require('../build/Release/topgun_hash.node');
|
|
37
|
+
return nativeModule;
|
|
38
|
+
}
|
|
39
|
+
catch (e1) {
|
|
40
|
+
try {
|
|
41
|
+
// Try debug build
|
|
42
|
+
nativeModule = require('../build/Debug/topgun_hash.node');
|
|
43
|
+
return nativeModule;
|
|
44
|
+
}
|
|
45
|
+
catch (e2) {
|
|
46
|
+
loadError = e1;
|
|
47
|
+
// Silent fallback - don't spam console
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if native module is available.
|
|
54
|
+
*/
|
|
55
|
+
function isNativeHashAvailable() {
|
|
56
|
+
return getNativeHash() !== null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the load error if native module failed to load.
|
|
60
|
+
*/
|
|
61
|
+
function getNativeHashLoadError() {
|
|
62
|
+
getNativeHash(); // Ensure load was attempted
|
|
63
|
+
return loadError;
|
|
64
|
+
}
|
|
65
|
+
// ============ JS Fallback Implementation ============
|
|
66
|
+
/**
|
|
67
|
+
* FNV-1a hash (current implementation in core).
|
|
68
|
+
* Used as fallback - produces 32-bit hash.
|
|
69
|
+
*/
|
|
70
|
+
function fnv1aHash(str) {
|
|
71
|
+
let hash = 0x811c9dc5;
|
|
72
|
+
for (let i = 0; i < str.length; i++) {
|
|
73
|
+
hash ^= str.charCodeAt(i);
|
|
74
|
+
hash = Math.imul(hash, 0x01000193);
|
|
75
|
+
}
|
|
76
|
+
return hash >>> 0;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* JS implementation of xxHash64.
|
|
80
|
+
* This is a simplified version that provides similar distribution.
|
|
81
|
+
* Note: Not bit-compatible with C xxHash64, use only as fallback.
|
|
82
|
+
*/
|
|
83
|
+
function xxhash64JS(data, seed = 0n) {
|
|
84
|
+
const PRIME64_1 = 0x9e3779b185ebca87n;
|
|
85
|
+
const PRIME64_2 = 0xc2b2ae3d27d4eb4fn;
|
|
86
|
+
const PRIME64_3 = 0x165667b19e3779f9n;
|
|
87
|
+
const PRIME64_4 = 0x85ebca77c2b2ae63n;
|
|
88
|
+
const PRIME64_5 = 0x27d4eb2f165667c5n;
|
|
89
|
+
const len = BigInt(data.length);
|
|
90
|
+
let h64;
|
|
91
|
+
if (data.length >= 32) {
|
|
92
|
+
// Process in 32-byte chunks
|
|
93
|
+
let v1 = seed + PRIME64_1 + PRIME64_2;
|
|
94
|
+
let v2 = seed + PRIME64_2;
|
|
95
|
+
let v3 = seed;
|
|
96
|
+
let v4 = seed - PRIME64_1;
|
|
97
|
+
let i = 0;
|
|
98
|
+
while (i + 32 <= data.length) {
|
|
99
|
+
v1 = xxh64Round(v1, readU64(data, i));
|
|
100
|
+
v2 = xxh64Round(v2, readU64(data, i + 8));
|
|
101
|
+
v3 = xxh64Round(v3, readU64(data, i + 16));
|
|
102
|
+
v4 = xxh64Round(v4, readU64(data, i + 24));
|
|
103
|
+
i += 32;
|
|
104
|
+
}
|
|
105
|
+
h64 = rotl64(v1, 1n) + rotl64(v2, 7n) + rotl64(v3, 12n) + rotl64(v4, 18n);
|
|
106
|
+
h64 = mergeRound(h64, v1);
|
|
107
|
+
h64 = mergeRound(h64, v2);
|
|
108
|
+
h64 = mergeRound(h64, v3);
|
|
109
|
+
h64 = mergeRound(h64, v4);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
h64 = seed + PRIME64_5;
|
|
113
|
+
}
|
|
114
|
+
h64 += len;
|
|
115
|
+
// Process remaining bytes
|
|
116
|
+
let remaining = data.length % 32;
|
|
117
|
+
let offset = data.length - remaining;
|
|
118
|
+
while (remaining >= 8) {
|
|
119
|
+
const k1 = xxh64Round(0n, readU64(data, offset));
|
|
120
|
+
h64 ^= k1;
|
|
121
|
+
h64 = rotl64(h64, 27n) * PRIME64_1 + PRIME64_4;
|
|
122
|
+
offset += 8;
|
|
123
|
+
remaining -= 8;
|
|
124
|
+
}
|
|
125
|
+
while (remaining >= 4) {
|
|
126
|
+
h64 ^= BigInt(readU32(data, offset)) * PRIME64_1;
|
|
127
|
+
h64 = rotl64(h64, 23n) * PRIME64_2 + PRIME64_3;
|
|
128
|
+
offset += 4;
|
|
129
|
+
remaining -= 4;
|
|
130
|
+
}
|
|
131
|
+
while (remaining > 0) {
|
|
132
|
+
h64 ^= BigInt(data[offset]) * PRIME64_5;
|
|
133
|
+
h64 = rotl64(h64, 11n) * PRIME64_1;
|
|
134
|
+
offset++;
|
|
135
|
+
remaining--;
|
|
136
|
+
}
|
|
137
|
+
// Final mix
|
|
138
|
+
h64 ^= h64 >> 33n;
|
|
139
|
+
h64 *= PRIME64_2;
|
|
140
|
+
h64 ^= h64 >> 29n;
|
|
141
|
+
h64 *= PRIME64_3;
|
|
142
|
+
h64 ^= h64 >> 32n;
|
|
143
|
+
return h64 & 0xffffffffffffffffn;
|
|
144
|
+
}
|
|
145
|
+
function readU64(data, offset) {
|
|
146
|
+
return (BigInt(data[offset]) |
|
|
147
|
+
(BigInt(data[offset + 1]) << 8n) |
|
|
148
|
+
(BigInt(data[offset + 2]) << 16n) |
|
|
149
|
+
(BigInt(data[offset + 3]) << 24n) |
|
|
150
|
+
(BigInt(data[offset + 4]) << 32n) |
|
|
151
|
+
(BigInt(data[offset + 5]) << 40n) |
|
|
152
|
+
(BigInt(data[offset + 6]) << 48n) |
|
|
153
|
+
(BigInt(data[offset + 7]) << 56n));
|
|
154
|
+
}
|
|
155
|
+
function readU32(data, offset) {
|
|
156
|
+
return (data[offset] |
|
|
157
|
+
(data[offset + 1] << 8) |
|
|
158
|
+
(data[offset + 2] << 16) |
|
|
159
|
+
(data[offset + 3] << 24));
|
|
160
|
+
}
|
|
161
|
+
function rotl64(x, r) {
|
|
162
|
+
return ((x << r) | (x >> (64n - r))) & 0xffffffffffffffffn;
|
|
163
|
+
}
|
|
164
|
+
function xxh64Round(acc, input) {
|
|
165
|
+
const PRIME64_1 = 0x9e3779b185ebca87n;
|
|
166
|
+
const PRIME64_2 = 0xc2b2ae3d27d4eb4fn;
|
|
167
|
+
acc += input * PRIME64_2;
|
|
168
|
+
acc &= 0xffffffffffffffffn;
|
|
169
|
+
acc = rotl64(acc, 31n);
|
|
170
|
+
acc *= PRIME64_1;
|
|
171
|
+
return acc & 0xffffffffffffffffn;
|
|
172
|
+
}
|
|
173
|
+
function mergeRound(acc, val) {
|
|
174
|
+
const PRIME64_1 = 0x9e3779b185ebca87n;
|
|
175
|
+
const PRIME64_4 = 0x85ebca77c2b2ae63n;
|
|
176
|
+
val = xxh64Round(0n, val);
|
|
177
|
+
acc ^= val;
|
|
178
|
+
acc = acc * PRIME64_1 + PRIME64_4;
|
|
179
|
+
return acc & 0xffffffffffffffffn;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* JS fallback for xxhash64.
|
|
183
|
+
*/
|
|
184
|
+
function xxhash64Fallback(data, seed = 0n) {
|
|
185
|
+
const uint8 = data instanceof Buffer ? new Uint8Array(data) : data;
|
|
186
|
+
return xxhash64JS(uint8, seed);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* JS fallback returning 32-bit number.
|
|
190
|
+
*/
|
|
191
|
+
function xxhash64FallbackAsNumber(data, seed = 0) {
|
|
192
|
+
const hash = xxhash64Fallback(data, BigInt(seed));
|
|
193
|
+
return Number(hash & 0xffffffffn);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* JS fallback for batch hash.
|
|
197
|
+
*/
|
|
198
|
+
function xxhash64BatchFallback(buffers, seed = 0n) {
|
|
199
|
+
return buffers.map((buf) => xxhash64Fallback(buf, seed));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* JS fallback for batch hash returning numbers.
|
|
203
|
+
*/
|
|
204
|
+
function xxhash64BatchFallbackAsNumbers(buffers, seed = 0) {
|
|
205
|
+
return buffers.map((buf) => xxhash64FallbackAsNumber(buf, seed));
|
|
206
|
+
}
|
|
207
|
+
// ============ Unified API ============
|
|
208
|
+
/**
|
|
209
|
+
* Compute xxHash64 of data.
|
|
210
|
+
* Uses native module if available, otherwise falls back to JS.
|
|
211
|
+
*/
|
|
212
|
+
function xxhash64(data, seed = 0) {
|
|
213
|
+
const native = getNativeHash();
|
|
214
|
+
if (native) {
|
|
215
|
+
return native.xxhash64(data, typeof seed === 'number' ? BigInt(seed) : seed);
|
|
216
|
+
}
|
|
217
|
+
return xxhash64Fallback(data, typeof seed === 'number' ? BigInt(seed) : seed);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Compute xxHash64 and return as 32-bit number.
|
|
221
|
+
* This is more efficient when BigInt precision is not needed.
|
|
222
|
+
*/
|
|
223
|
+
function xxhash64AsNumber(data, seed = 0) {
|
|
224
|
+
const native = getNativeHash();
|
|
225
|
+
if (native) {
|
|
226
|
+
return native.xxhash64AsNumber(data, seed);
|
|
227
|
+
}
|
|
228
|
+
return xxhash64FallbackAsNumber(data, seed);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Compute xxHash64 for multiple buffers.
|
|
232
|
+
*/
|
|
233
|
+
function xxhash64Batch(buffers, seed = 0) {
|
|
234
|
+
const native = getNativeHash();
|
|
235
|
+
if (native) {
|
|
236
|
+
return native.xxhash64Batch(buffers, typeof seed === 'number' ? BigInt(seed) : seed);
|
|
237
|
+
}
|
|
238
|
+
return xxhash64BatchFallback(buffers, typeof seed === 'number' ? BigInt(seed) : seed);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Compute xxHash64 for multiple buffers, returning 32-bit numbers.
|
|
242
|
+
*/
|
|
243
|
+
function xxhash64BatchAsNumbers(buffers, seed = 0) {
|
|
244
|
+
const native = getNativeHash();
|
|
245
|
+
if (native) {
|
|
246
|
+
return native.xxhash64BatchAsNumbers(buffers, seed);
|
|
247
|
+
}
|
|
248
|
+
return xxhash64BatchFallbackAsNumbers(buffers, seed);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Create streaming hash state.
|
|
252
|
+
*/
|
|
253
|
+
function createXxHash64State(seed = 0) {
|
|
254
|
+
const native = getNativeHash();
|
|
255
|
+
if (native) {
|
|
256
|
+
return new native.XxHash64State(seed);
|
|
257
|
+
}
|
|
258
|
+
return new JsXxHash64State(typeof seed === 'number' ? BigInt(seed) : seed);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* JS fallback streaming implementation
|
|
262
|
+
*/
|
|
263
|
+
class JsXxHash64State {
|
|
264
|
+
chunks = [];
|
|
265
|
+
seed;
|
|
266
|
+
constructor(seed) {
|
|
267
|
+
this.seed = seed;
|
|
268
|
+
}
|
|
269
|
+
update(data) {
|
|
270
|
+
this.chunks.push(new Uint8Array(data));
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
digest() {
|
|
274
|
+
const totalLength = this.chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
275
|
+
const combined = new Uint8Array(totalLength);
|
|
276
|
+
let offset = 0;
|
|
277
|
+
for (const chunk of this.chunks) {
|
|
278
|
+
combined.set(chunk, offset);
|
|
279
|
+
offset += chunk.length;
|
|
280
|
+
}
|
|
281
|
+
return xxhash64Fallback(combined, this.seed);
|
|
282
|
+
}
|
|
283
|
+
digestAsNumber() {
|
|
284
|
+
return Number(this.digest() & 0xffffffffn);
|
|
285
|
+
}
|
|
286
|
+
reset() {
|
|
287
|
+
this.chunks = [];
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// ============ String Hashing (for compatibility with current code) ============
|
|
292
|
+
/**
|
|
293
|
+
* Hash a string using xxHash64.
|
|
294
|
+
* Returns 32-bit number for compatibility with existing hashString() usage.
|
|
295
|
+
*/
|
|
296
|
+
function hashString(str) {
|
|
297
|
+
const native = getNativeHash();
|
|
298
|
+
if (native) {
|
|
299
|
+
return native.xxhash64AsNumber(Buffer.from(str));
|
|
300
|
+
}
|
|
301
|
+
// Use FNV-1a as fallback for string hashing (faster for short strings)
|
|
302
|
+
return fnv1aHash(str);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Hash a string using xxHash64, returning full 64-bit BigInt.
|
|
306
|
+
*/
|
|
307
|
+
function hashStringBigInt(str, seed = 0n) {
|
|
308
|
+
const native = getNativeHash();
|
|
309
|
+
if (native) {
|
|
310
|
+
return native.xxhash64(Buffer.from(str), seed);
|
|
311
|
+
}
|
|
312
|
+
return xxhash64Fallback(Buffer.from(str), seed);
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAkCH,sCAoBC;AAKD,sDAEC;AAK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;IACd,CAAC;CACF;AAED,iFAAiF;AAEjF;;;GAGG;AACH,SAAgB,UAAU,CAAC,GAAW;IACpC,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;IACD,uEAAuE;IACvE,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,GAAW,EAAE,OAAe,EAAE;IAC7D,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @topgunbuild/native
|
|
3
|
+
*
|
|
4
|
+
* Native performance modules for TopGun.
|
|
5
|
+
* Provides optimized implementations with JS fallbacks.
|
|
6
|
+
*/
|
|
7
|
+
export { xxhash64, xxhash64AsNumber, xxhash64Batch, xxhash64BatchAsNumbers, createXxHash64State, hashString, hashStringBigInt, isNativeHashAvailable, getNativeHash, getNativeHashLoadError, xxhash64Fallback, xxhash64FallbackAsNumber, xxhash64BatchFallback, xxhash64BatchFallbackAsNumbers, type NativeHashModule, type XxHash64StateInstance, } from './hash';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,sBAAsB,EACtB,mBAAmB,EAEnB,UAAU,EACV,gBAAgB,EAEhB,qBAAqB,EACrB,aAAa,EACb,sBAAsB,EAEtB,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,8BAA8B,EAE9B,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,GAC3B,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @topgunbuild/native
|
|
4
|
+
*
|
|
5
|
+
* Native performance modules for TopGun.
|
|
6
|
+
* Provides optimized implementations with JS fallbacks.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.xxhash64BatchFallbackAsNumbers = exports.xxhash64BatchFallback = exports.xxhash64FallbackAsNumber = exports.xxhash64Fallback = exports.getNativeHashLoadError = exports.getNativeHash = exports.isNativeHashAvailable = exports.hashStringBigInt = exports.hashString = exports.createXxHash64State = exports.xxhash64BatchAsNumbers = exports.xxhash64Batch = exports.xxhash64AsNumber = exports.xxhash64 = void 0;
|
|
10
|
+
var hash_1 = require("./hash");
|
|
11
|
+
// Core hash functions
|
|
12
|
+
Object.defineProperty(exports, "xxhash64", { enumerable: true, get: function () { return hash_1.xxhash64; } });
|
|
13
|
+
Object.defineProperty(exports, "xxhash64AsNumber", { enumerable: true, get: function () { return hash_1.xxhash64AsNumber; } });
|
|
14
|
+
Object.defineProperty(exports, "xxhash64Batch", { enumerable: true, get: function () { return hash_1.xxhash64Batch; } });
|
|
15
|
+
Object.defineProperty(exports, "xxhash64BatchAsNumbers", { enumerable: true, get: function () { return hash_1.xxhash64BatchAsNumbers; } });
|
|
16
|
+
Object.defineProperty(exports, "createXxHash64State", { enumerable: true, get: function () { return hash_1.createXxHash64State; } });
|
|
17
|
+
// String hashing (compatible with existing code)
|
|
18
|
+
Object.defineProperty(exports, "hashString", { enumerable: true, get: function () { return hash_1.hashString; } });
|
|
19
|
+
Object.defineProperty(exports, "hashStringBigInt", { enumerable: true, get: function () { return hash_1.hashStringBigInt; } });
|
|
20
|
+
// Availability checks
|
|
21
|
+
Object.defineProperty(exports, "isNativeHashAvailable", { enumerable: true, get: function () { return hash_1.isNativeHashAvailable; } });
|
|
22
|
+
Object.defineProperty(exports, "getNativeHash", { enumerable: true, get: function () { return hash_1.getNativeHash; } });
|
|
23
|
+
Object.defineProperty(exports, "getNativeHashLoadError", { enumerable: true, get: function () { return hash_1.getNativeHashLoadError; } });
|
|
24
|
+
// Fallback implementations (for testing)
|
|
25
|
+
Object.defineProperty(exports, "xxhash64Fallback", { enumerable: true, get: function () { return hash_1.xxhash64Fallback; } });
|
|
26
|
+
Object.defineProperty(exports, "xxhash64FallbackAsNumber", { enumerable: true, get: function () { return hash_1.xxhash64FallbackAsNumber; } });
|
|
27
|
+
Object.defineProperty(exports, "xxhash64BatchFallback", { enumerable: true, get: function () { return hash_1.xxhash64BatchFallback; } });
|
|
28
|
+
Object.defineProperty(exports, "xxhash64BatchFallbackAsNumbers", { enumerable: true, get: function () { return hash_1.xxhash64BatchFallbackAsNumbers; } });
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+BAsBgB;AArBd,sBAAsB;AACtB,gGAAA,QAAQ,OAAA;AACR,wGAAA,gBAAgB,OAAA;AAChB,qGAAA,aAAa,OAAA;AACb,8GAAA,sBAAsB,OAAA;AACtB,2GAAA,mBAAmB,OAAA;AACnB,iDAAiD;AACjD,kGAAA,UAAU,OAAA;AACV,wGAAA,gBAAgB,OAAA;AAChB,sBAAsB;AACtB,6GAAA,qBAAqB,OAAA;AACrB,qGAAA,aAAa,OAAA;AACb,8GAAA,sBAAsB,OAAA;AACtB,yCAAyC;AACzC,wGAAA,gBAAgB,OAAA;AAChB,gHAAA,wBAAwB,OAAA;AACxB,6GAAA,qBAAqB,OAAA;AACrB,sHAAA,8BAA8B,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@topgunbuild/native",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Native performance modules for TopGun",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"build",
|
|
10
|
+
"binding.gyp",
|
|
11
|
+
"src/*.cc",
|
|
12
|
+
"deps"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"node-addon-api": "^8.3.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/jest": "^29.5.14",
|
|
19
|
+
"@types/node": "^22.10.2",
|
|
20
|
+
"jest": "^29.7.0",
|
|
21
|
+
"node-gyp": "^10.3.1",
|
|
22
|
+
"ts-jest": "^29.2.5",
|
|
23
|
+
"typescript": "^5.7.2"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18.0.0"
|
|
27
|
+
},
|
|
28
|
+
"os": [
|
|
29
|
+
"darwin",
|
|
30
|
+
"linux",
|
|
31
|
+
"win32"
|
|
32
|
+
],
|
|
33
|
+
"cpu": [
|
|
34
|
+
"x64",
|
|
35
|
+
"arm64"
|
|
36
|
+
],
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/topgunbuild/topgun.git",
|
|
40
|
+
"directory": "packages/native"
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"gypfile": true,
|
|
44
|
+
"scripts": {
|
|
45
|
+
"clean": "rm -rf dist build",
|
|
46
|
+
"build:native": "node-gyp rebuild",
|
|
47
|
+
"build:ts": "tsc",
|
|
48
|
+
"build": "npm run build:native && npm run build:ts",
|
|
49
|
+
"rebuild": "npm run clean && npm run build",
|
|
50
|
+
"test": "jest",
|
|
51
|
+
"typecheck": "tsc --noEmit"
|
|
52
|
+
}
|
|
53
|
+
}
|