* Get data from cache * @template R * @param {(set: SortableSet<T>) => R} fn function to calculate value * @returns {R} returns result of fn(this), cached until set changes
(fn)
| 113 | * @returns {R} returns result of fn(this), cached until set changes |
| 114 | */ |
| 115 | getFromCache(fn) { |
| 116 | if (this._cache === undefined) { |
| 117 | this._cache = new Map(); |
| 118 | } else { |
| 119 | const result = this._cache.get(fn); |
| 120 | const data = /** @type {R} */ (result); |
| 121 | if (data !== undefined) { |
| 122 | return data; |
| 123 | } |
| 124 | } |
| 125 | const newData = fn(this); |
| 126 | this._cache.set(fn, newData); |
| 127 | return newData; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Get data from cache (ignoring sorting) |
no test coverage detected