public void Init(TElem[] data) { dataLength = data.Length; this.data = new TElem[dataLength]; Array.Copy(data, 0, this.data, 0, dataLength); leafsCount = 1; while (leafsCount < dataLength) { leafsCount *= 2; } nodesCount = leafsCount - 1; totalCount = nodesCount + leafsCount; tree = new TAcc[totalCount]; leftBoundary = new int[totalCount]; rightBoundary = new int[totalCount]; for (int i = 0; i < dataLength; i++) { tree[nodesCount + i] = accumulator.Compute(data[i]); } for (int i = dataLength; i < leafsCount; i++) { tree[nodesCount + i] = accumulator.Neutral; } for (int i = nodesCount; i < totalCount; i++) { leftBoundary[i] = rightBoundary[i] = i - nodesCount; } for (int i = nodesCount - 1; i >= 0; i--) { int l = LeftChild(i), r = RightChild(i); tree[i] = accumulator.Combine(tree[l], tree[r]); leftBoundary[i] = leftBoundary[l]; rightBoundary[i] = rightBoundary[r]; } }