tuple-ts 0.4.4 → 0.4.6
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/README.md +1 -1
- package/dist/hash.d.ts +1 -2
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +21 -17
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Equal values are **interned to the same object**.
|
|
|
22
22
|
|
|
23
23
|
That makes tuples and structs immutable, naturally usable as composite `Map` keys and `Set` values, and particularly pleasant to use in functional TypeScript.
|
|
24
24
|
|
|
25
|
-
**Zero dependencies ·
|
|
25
|
+
**Zero dependencies · Less than 1 KB gzipped**
|
|
26
26
|
|
|
27
27
|
## Install
|
|
28
28
|
|
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":"AAgHA,eAAO,MAAM,UAAU,GAAI,QAAQ,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,MAAM,KAAG,MACtB,CAAC"}
|
package/dist/hash.js
CHANGED
|
@@ -26,8 +26,8 @@ function linearCongruentialGenerator(seed = Date.now()) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
const randomUint32 = linearCongruentialGenerator();
|
|
29
|
-
const tupleSeed = randomUint32();
|
|
30
|
-
const structSeed = randomUint32();
|
|
29
|
+
// const tupleSeed = randomUint32();
|
|
30
|
+
// const structSeed = randomUint32();
|
|
31
31
|
const nullHash = randomUint32();
|
|
32
32
|
const undefinedHash = randomUint32();
|
|
33
33
|
const falseHash = randomUint32();
|
|
@@ -96,18 +96,22 @@ function valueHash(value) {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
const mixHashes = murmurHash3Mix_32bit;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
99
|
+
export const valuesHash = (values, seed) => mixHashes(Array.from(values, valueHash), seed);
|
|
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
|
+
// }
|
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;AAgCzC,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,6 +1,7 @@
|
|
|
1
1
|
import InternCache from "./intern-cache";
|
|
2
|
-
export { InternCache };
|
|
3
2
|
import * as hash from "./hash";
|
|
3
|
+
const TUPLE_SEED = 0x7A3F91C2;
|
|
4
|
+
const STRUCT_SEED = 0xE84B26D7;
|
|
4
5
|
function arrayEquivalent(a1, a2) {
|
|
5
6
|
if (a2.length !== a1.length)
|
|
6
7
|
return false;
|
|
@@ -24,7 +25,7 @@ function structEquivalent(r1, r2) {
|
|
|
24
25
|
}
|
|
25
26
|
return true;
|
|
26
27
|
}
|
|
27
|
-
export const _tupleCache = new InternCache(hash.
|
|
28
|
-
export const _structCache = new InternCache(hash.
|
|
28
|
+
export const _tupleCache = new InternCache(hash.valuesHash, arrayEquivalent);
|
|
29
|
+
export const _structCache = new InternCache((r) => hash.valuesHash(Object.entries(r).flat()), structEquivalent);
|
|
29
30
|
export const tuple = (...t) => Object.freeze(_tupleCache.get(t));
|
|
30
31
|
export const struct = ({ ...r }) => Object.freeze(_structCache.get(r));
|