tuple-ts 0.4.6 → 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.map +1 -1
- package/dist/hash.js +6 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/package.json +1 -1
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,23 +93,5 @@ function valueHash(value) {
|
|
|
95
93
|
return stableRandomHash(objectHashMap, value);
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
// function valueHashes(values: Iterable<unknown>): Array<number> {
|
|
101
|
-
// return Array.from(values, valueHash);
|
|
102
|
-
// }
|
|
103
|
-
// export function tupleHash(elements: readonly unknown[]): number {
|
|
104
|
-
// return mixHashes(valueHashes(elements), tupleSeed);
|
|
105
|
-
// }
|
|
106
|
-
// function keyAndValueHashes(struct: Record<string, unknown>): Array<number> {
|
|
107
|
-
// return Object.keys(struct).sort().flatMap(key => [
|
|
108
|
-
// valueHash(key),
|
|
109
|
-
// valueHash(struct[key])
|
|
110
|
-
// ]);
|
|
111
|
-
// }
|
|
112
|
-
// export function structHash(struct: Record<string, unknown>): number {
|
|
113
|
-
// return mixHashes(
|
|
114
|
-
// keyAndValueHashes(struct),
|
|
115
|
-
// structSeed
|
|
116
|
-
// );
|
|
117
|
-
// }
|
|
96
|
+
export const valuesHash = (values, seed) => hashMixFn(Array.from(values, valueHash), seed);
|
|
97
|
+
const hashMixFn = murmurHash3Mix_32bit;
|
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,7 +1,5 @@
|
|
|
1
1
|
import InternCache from "./intern-cache";
|
|
2
2
|
import * as hash from "./hash";
|
|
3
|
-
const TUPLE_SEED = 0x7A3F91C2;
|
|
4
|
-
const STRUCT_SEED = 0xE84B26D7;
|
|
5
3
|
function arrayEquivalent(a1, a2) {
|
|
6
4
|
if (a2.length !== a1.length)
|
|
7
5
|
return false;
|
|
@@ -26,6 +24,6 @@ function structEquivalent(r1, r2) {
|
|
|
26
24
|
return true;
|
|
27
25
|
}
|
|
28
26
|
export const _tupleCache = new InternCache(hash.valuesHash, arrayEquivalent);
|
|
29
|
-
export const _structCache = new InternCache((r) => hash.valuesHash(Object.
|
|
27
|
+
export const _structCache = new InternCache((r) => hash.valuesHash(Object.keys(r).sort().flatMap(k => [k, r[k]])), structEquivalent);
|
|
30
28
|
export const tuple = (...t) => Object.freeze(_tupleCache.get(t));
|
|
31
29
|
export const struct = ({ ...r }) => Object.freeze(_structCache.get(r));
|