| 5 | */ |
| 6 | |
| 7 | class FenwickTree { |
| 8 | constructor(feneickArray, array, n) { |
| 9 | for (let i = 1; i <= n; i++) { |
| 10 | feneickArray[i] = 0 |
| 11 | } |
| 12 | for (let i = 0; i < n; i++) { |
| 13 | this.update(feneickArray, n, i, array[i]) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | update(feneickArray, n, index, value) { |
| 18 | index = index + 1 |
| 19 | while (index <= n) { |
| 20 | feneickArray[index] += value |
| 21 | index += index & -index |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | getPrefixSum(feneickArray, index) { |
| 26 | let currSum = 0 |
| 27 | index = index + 1 |
| 28 | while (index > 0) { |
| 29 | currSum += feneickArray[index] |
| 30 | index -= index & -index |
| 31 | } |
| 32 | |
| 33 | return currSum |
| 34 | } |
| 35 | } |
| 36 | export { FenwickTree } |
nothing calls this directly
no outgoing calls
no test coverage detected