( values: ReadonlyArray<number>, size: number, dir: "next" | "prev" )
| 200 | } |
| 201 | |
| 202 | const lookupTable = ( |
| 203 | values: ReadonlyArray<number>, |
| 204 | size: number, |
| 205 | dir: "next" | "prev" |
| 206 | ): Array<number | undefined> => { |
| 207 | const result = new Array(size).fill(undefined) |
| 208 | if (values.length === 0) { |
| 209 | return result |
| 210 | } |
| 211 | |
| 212 | let current: number | undefined = undefined |
| 213 | |
| 214 | if (dir === "next") { |
| 215 | let index = values.length - 1 |
| 216 | for (let i = size - 1; i >= 0; i--) { |
| 217 | while (index >= 0 && values[index] >= i) { |
| 218 | current = values[index--] |
| 219 | } |
| 220 | result[i] = current |
| 221 | } |
| 222 | } else { |
| 223 | let index = 0 |
| 224 | for (let i = 0; i < size; i++) { |
| 225 | while (index < values.length && values[index] <= i) { |
| 226 | current = values[index++] |
| 227 | } |
| 228 | result[i] = current |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | return result |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * @since 2.0.0 |
no outgoing calls
no test coverage detected
searching dependent graphs…