tuple-ts 0.4.5 → 0.4.7
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/dist/hash.d.ts +1 -2
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +6 -22
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/package.json +1 -1
package/dist/hash.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare function structHash(struct: Record<string, unknown>): number;
|
|
1
|
+
export declare const valuesHash: (values: Iterable<unknown>, seed?: number) => number;
|
|
3
2
|
//# sourceMappingURL=hash.d.ts.map
|
package/dist/hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AA4GA,eAAO,MAAM,UAAU,GAAI,QAAQ,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,MAAM,KAAG,MACtB,CAAC"}
|
package/dist/hash.js
CHANGED
|
@@ -26,8 +26,6 @@ function linearCongruentialGenerator(seed = Date.now()) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
const randomUint32 = linearCongruentialGenerator();
|
|
29
|
-
const tupleSeed = randomUint32();
|
|
30
|
-
const structSeed = randomUint32();
|
|
31
29
|
const nullHash = randomUint32();
|
|
32
30
|
const undefinedHash = randomUint32();
|
|
33
31
|
const falseHash = randomUint32();
|
|
@@ -75,18 +73,18 @@ function bigintToUint32s(value) {
|
|
|
75
73
|
function valueHash(value) {
|
|
76
74
|
switch (typeof value) {
|
|
77
75
|
case "string":
|
|
78
|
-
return
|
|
76
|
+
return hashMixFn(stringToUint32s(value), stringSeed);
|
|
79
77
|
case "number":
|
|
80
|
-
return
|
|
78
|
+
return hashMixFn(numberToUint32s(value), numberSeed);
|
|
81
79
|
case "bigint":
|
|
82
|
-
return
|
|
80
|
+
return hashMixFn(bigintToUint32s(value), bigIntSeed);
|
|
83
81
|
case "boolean":
|
|
84
82
|
return value ? trueHash : falseHash;
|
|
85
83
|
case "symbol":
|
|
86
84
|
const k = Symbol.keyFor(value);
|
|
87
85
|
return k === undefined
|
|
88
86
|
? stableRandomHash(symbolHashMap, value)
|
|
89
|
-
:
|
|
87
|
+
: hashMixFn(stringToUint32s(k), registeredSymbolSeed);
|
|
90
88
|
case "undefined":
|
|
91
89
|
return undefinedHash;
|
|
92
90
|
case "object":
|
|
@@ -95,19 +93,5 @@ function valueHash(value) {
|
|
|
95
93
|
return stableRandomHash(objectHashMap, value);
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
return Array.from(values, valueHash);
|
|
101
|
-
}
|
|
102
|
-
export function tupleHash(elements) {
|
|
103
|
-
return mixHashes(valueHashes(elements), tupleSeed);
|
|
104
|
-
}
|
|
105
|
-
function keyAndValueHashes(struct) {
|
|
106
|
-
return Object.keys(struct).sort().flatMap(key => [
|
|
107
|
-
valueHash(key),
|
|
108
|
-
valueHash(struct[key])
|
|
109
|
-
]);
|
|
110
|
-
}
|
|
111
|
-
export function structHash(struct) {
|
|
112
|
-
return mixHashes(keyAndValueHashes(struct), structSeed);
|
|
113
|
-
}
|
|
96
|
+
export const valuesHash = (values, seed) => hashMixFn(Array.from(values, valueHash), seed);
|
|
97
|
+
const hashMixFn = murmurHash3Mix_32bit;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import InternCache from "./intern-cache";
|
|
2
|
-
export { InternCache };
|
|
3
2
|
export declare const _tupleCache: InternCache<number, readonly unknown[]>;
|
|
4
3
|
export declare const _structCache: InternCache<number, Record<string, unknown>>;
|
|
5
4
|
export declare const tuple: <const T extends readonly unknown[]>(...t: T) => Readonly<T>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,gBAAgB,CAAC;AA6BzC,eAAO,MAAM,WAAW,yCAGvB,CAAC;AAEF,eAAO,MAAM,YAAY,8CAGxB,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,KAAK,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAAE,GAAG,GAAG,CAAC,gBAC9B,CAAC;AAEpC,eAAO,MAAM,MAAM,GAAI,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,gBACvC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import InternCache from "./intern-cache";
|
|
2
|
-
export { InternCache };
|
|
3
2
|
import * as hash from "./hash";
|
|
4
3
|
function arrayEquivalent(a1, a2) {
|
|
5
4
|
if (a2.length !== a1.length)
|
|
@@ -24,7 +23,7 @@ function structEquivalent(r1, r2) {
|
|
|
24
23
|
}
|
|
25
24
|
return true;
|
|
26
25
|
}
|
|
27
|
-
export const _tupleCache = new InternCache(hash.
|
|
28
|
-
export const _structCache = new InternCache(hash.
|
|
26
|
+
export const _tupleCache = new InternCache(hash.valuesHash, arrayEquivalent);
|
|
27
|
+
export const _structCache = new InternCache((r) => hash.valuesHash(Object.keys(r).sort().flatMap(k => [k, r[k]])), structEquivalent);
|
|
29
28
|
export const tuple = (...t) => Object.freeze(_tupleCache.get(t));
|
|
30
29
|
export const struct = ({ ...r }) => Object.freeze(_structCache.get(r));
|