You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project relies on the [object-hash](https://github.com/puleos/object-hash) library to map object types to strings.
43
+
This project relies on the [object-hash](https://github.com/puleos/object-hash) library to normalize object types to unique strings.
44
44
45
45
## Comparable Interface
46
46
@@ -58,16 +58,55 @@ set1.contains(set3); // true
58
58
59
59
## Configuration Options
60
60
61
+
The default settings should be suitable for most use cases, but behavior can be configured.
62
+
61
63
```typescript
62
-
newDeepSet(values?, options?)
63
-
newDeepMap(entries?, options?)
64
+
newDeepSet<K>(values?, options?)
65
+
newDeepMap<K,V>(entries?, options?)
64
66
```
65
67
66
-
The `options` argument is a superset of the options defined for [object-hash](https://github.com/puleos/object-hash#hashvalue-options), with the same defaults (exception: the default algoritm is `md5`).
68
+
The `options` argument is a superset of the options defined for [object-hash](https://github.com/puleos/object-hash#hashvalue-options), with the same defaults (exception: the default algoritm is `md5`). There are also library-specific options.
69
+
70
+
### Library-specific options:
71
+
72
+
- `transformer` - a custom function that transforms Map keys/Set values prior to hashing. It does not affect the values that are stored.
73
+
74
+
```typescript
75
+
typeMyType= { val: number; other: number };
76
+
consta:MyType= { val: 1, other: 1 };
77
+
constb:MyType= { val: 1, other: 2 };
78
+
consttransformer= (obj:MyType) => ({ val });
79
+
80
+
constset=newDeepSet([a, b]);
81
+
set.size; // 2
82
+
constset=newDeepSet([a, b], { transformer });
83
+
set.size; // 1
84
+
85
+
[...set.values()]; // [{ val: 1, other: 2 }]
86
+
```
87
+
88
+
- `mapValueTransformer` - a custom function that transforms Map values prior to hashing. This is only relevant to `Comparable` interface operations. It does not affect the values that are stored.
89
+
90
+
```typescript
91
+
typeMyType= { val: number; other: number };
92
+
consta: MyType= { val: 1, other: 1 };
93
+
constb: MyType= { val: 1, other: 2 };
94
+
constmapValueTransformer= (obj:MyType) => ({ val });
- Don't mutate a map key (or set value) while still using the data structure. The internal representation is not affected by this mutation, so behavior may be unexpected.
129
+
- This still supports primitive keys/values like traditional `Map`/`Set`.
130
+
- Don't mutate objects stored in the data structure. The internal representation is not affected by this mutation, so behavior may be unexpected.
131
+
- Don't mutate objects in the user-supplied `transformer` or `mapValueTransformer` functions. It will affect the stored version.
91
132
- This implementation does not explicitly "handle" key collisions. However, with the default algorithm (MD5), even if a map contained one TRILLION entries, the probability of a collision on the next insert is only 0.000000000000001. If you need better odds, use SHA1, SHA256, etc.
0 commit comments