4 ms·
Create a wrapper class that takes a stringifying function that converts the key objects into a primitive and use a Map<string, [K, V]> as the backing store. fas
by mediumdeviation 5y ago
Create a wrapper class that takes a stringifying function that converts the key objects into a primitive and use a Map<string, [K, V]> as the backing store. fast-json-stable-stringify can be used as the default stringifier, and if the objects are large or have a natural key a custom stringifier can also be supplied. Since we are using TS we can have our custom class implement Map<K, V>.
- arsome 5y agoThat's very similar to the solution I'm using and that I hate - it involves unnecessary generation and storage of strings and is far less ideal than something like the implementation in tstl I linked above where you can simply provide a custom hash function and equality comparison.