| 19 | } |
| 20 | |
| 21 | addInfo(info: T): void { |
| 22 | const depth = this.getDepth(info); |
| 23 | if (depth <= this.maxDequeuedDepth) { |
| 24 | throw new Error( |
| 25 | `try to addInfo at depth ${depth} after having dequeued at depth ` + |
| 26 | this.maxDequeuedDepth, |
| 27 | ); |
| 28 | } |
| 29 | let map = this.depthQueues.get(depth); |
| 30 | if (!map) { |
| 31 | map = new Map(); |
| 32 | this.depthQueues.set(depth, map); |
| 33 | } |
| 34 | const key = this.getKey(info); |
| 35 | const curInfo = map.get(key); |
| 36 | const mergedInfo = curInfo ? this.mergeFunction(curInfo, info) : info; |
| 37 | map.set(key, mergedInfo); |
| 38 | if (depth > this.maxEnqueuedDepth) { |
| 39 | this.maxEnqueuedDepth = depth; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | addInfos(infos: $ReadOnlyArray<T>) { |
| 44 | for (const info of infos) { |