本文整理匯總了TypeScript中vs/editor/common/viewModel/prefixSumComputer.PrefixSumComputer.getAccumulatedValue方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript PrefixSumComputer.getAccumulatedValue方法的具體用法?TypeScript PrefixSumComputer.getAccumulatedValue怎麽用?TypeScript PrefixSumComputer.getAccumulatedValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vs/editor/common/viewModel/prefixSumComputer.PrefixSumComputer
的用法示例。
在下文中一共展示了PrefixSumComputer.getAccumulatedValue方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: convertInputPositionToOutputPosition
public convertInputPositionToOutputPosition(inputLineNumber: number, inputColumn: number): editorCommon.IEditorPosition {
this._ensureValidState();
if (inputLineNumber > this.lines.length) {
inputLineNumber = this.lines.length;
}
let lineIndex = inputLineNumber - 1, lineIndexChanged = false;
while (lineIndex > 0 && !this.lines[lineIndex].isVisible()) {
lineIndex--;
lineIndexChanged = true;
}
if (lineIndex === 0 && !this.lines[lineIndex].isVisible()) {
// Could not reach a real line
return new Position(1, 1);
}
var deltaLineNumber = 1 + (lineIndex === 0 ? 0 : this.prefixSumComputer.getAccumulatedValue(lineIndex - 1));
var r:editorCommon.IEditorPosition;
if (lineIndexChanged) {
r = this.lines[lineIndex].getOutputPositionOfInputPosition(deltaLineNumber, this.model.getLineMaxColumn(lineIndex + 1));
} else {
r = this.lines[inputLineNumber - 1].getOutputPositionOfInputPosition(deltaLineNumber, inputColumn);
}
// console.log('in -> out ' + inputLineNumber + ',' + inputColumn + ' ===> ' + r.lineNumber + ',' + r.column);
return r;
}
示例2: getInputOffsetOfOutputPosition
public getInputOffsetOfOutputPosition(outputLineIndex: number, outputOffset: number): number {
if (outputLineIndex === 0) {
return outputOffset;
} else {
return this._prefixSums.getAccumulatedValue(outputLineIndex - 1) + outputOffset;
}
}
示例3: convertInputPositionToOutputPosition
public convertInputPositionToOutputPosition(_inputLineNumber: number, _inputColumn: number): Position {
this._ensureValidState();
let validPosition = this.model.validatePosition(new Position(_inputLineNumber, _inputColumn));
let inputLineNumber = validPosition.lineNumber;
let inputColumn = validPosition.column;
let lineIndex = inputLineNumber - 1, lineIndexChanged = false;
while (lineIndex > 0 && !this.lines[lineIndex].isVisible()) {
lineIndex--;
lineIndexChanged = true;
}
if (lineIndex === 0 && !this.lines[lineIndex].isVisible()) {
// Could not reach a real line
// console.log('in -> out ' + inputLineNumber + ',' + inputColumn + ' ===> ' + 1 + ',' + 1);
return new Position(1, 1);
}
let deltaLineNumber = 1 + (lineIndex === 0 ? 0 : this.prefixSumComputer.getAccumulatedValue(lineIndex - 1));
let r:Position;
if (lineIndexChanged) {
r = this.lines[lineIndex].getOutputPositionOfInputPosition(deltaLineNumber, this.model.getLineMaxColumn(lineIndex + 1));
} else {
r = this.lines[inputLineNumber - 1].getOutputPositionOfInputPosition(deltaLineNumber, inputColumn);
}
// console.log('in -> out ' + inputLineNumber + ',' + inputColumn + ' ===> ' + r.lineNumber + ',' + r);
return r;
}
示例4: onModelLinesDeleted
public onModelLinesDeleted(versionId: number, fromLineNumber: number, toLineNumber: number, emit: (evenType: string, payload: any) => void): void {
if (versionId <= this._validModelVersionId) {
return;
}
this._validModelVersionId = versionId;
var outputFromLineNumber = (fromLineNumber === 1 ? 1 : this.prefixSumComputer.getAccumulatedValue(fromLineNumber - 2) + 1);
var outputToLineNumber = this.prefixSumComputer.getAccumulatedValue(toLineNumber - 1);
this.lines.splice(fromLineNumber - 1, toLineNumber - fromLineNumber + 1);
this.prefixSumComputer.removeValues(fromLineNumber - 1, toLineNumber - fromLineNumber + 1);
var e:editorCommon.IViewLinesDeletedEvent = {
fromLineNumber: outputFromLineNumber,
toLineNumber: outputToLineNumber
};
emit(editorCommon.ViewEventNames.LinesDeletedEvent, e);
}
示例5: onModelLinesInserted
public onModelLinesInserted(versionId:number, fromLineNumber:number, toLineNumber:number, text:string[], emit:(evenType:string, payload:any)=>void): void {
if (versionId <= this._validModelVersionId) {
return;
}
this._validModelVersionId = versionId;
var hiddenAreas = this.getHiddenAreas();
var isInHiddenArea = false;
var testPosition = new Position(fromLineNumber, 1);
for (var i = 0; i < hiddenAreas.length; i++) {
if (hiddenAreas[i].containsPosition(testPosition)) {
isInHiddenArea = true;
break;
}
}
var outputFromLineNumber = (fromLineNumber === 1 ? 1 : this.prefixSumComputer.getAccumulatedValue(fromLineNumber - 2) + 1);
var line: ISplitLine,
outputLineCount: number,
totalOutputLineCount = 0;
var insertLines: ISplitLine[] = [],
insertPrefixSumValues: number[] = [];
for (var i = 0, len = text.length; i < len; i++) {
var line = createSplitLine(this.linePositionMapperFactory, text[i], this.tabSize, this.wrappingColumn, this.columnsForFullWidthChar, this.wrappingIndent, !isInHiddenArea);
insertLines.push(line);
outputLineCount = line.getOutputLineCount();
totalOutputLineCount += outputLineCount;
insertPrefixSumValues.push(outputLineCount);
}
this.lines = this.lines.slice(0, fromLineNumber - 1).concat(insertLines).concat(this.lines.slice(fromLineNumber - 1));
this.prefixSumComputer.insertValues(fromLineNumber - 1, insertPrefixSumValues);
var e:editorCommon.IViewLinesInsertedEvent = {
fromLineNumber: outputFromLineNumber,
toLineNumber: outputFromLineNumber + totalOutputLineCount - 1
};
emit(editorCommon.ViewEventNames.LinesInsertedEvent, e);
}
示例6: onModelLineChanged
public onModelLineChanged(versionId:number, lineNumber:number, newText:string, emit:(evenType:string, payload:any)=>void): boolean {
if (versionId <= this._validModelVersionId) {
return;
}
this._validModelVersionId = versionId;
var lineIndex = lineNumber - 1;
var oldOutputLineCount = this.lines[lineIndex].getOutputLineCount();
var isVisible = this.lines[lineIndex].isVisible();
var line = createSplitLine(this.linePositionMapperFactory, newText, this.tabSize, this.wrappingColumn, this.columnsForFullWidthChar, this.wrappingIndent, isVisible);
this.lines[lineIndex] = line;
var newOutputLineCount = this.lines[lineIndex].getOutputLineCount();
var lineMappingChanged = false,
changeFrom = 0,
changeTo = -1,
insertFrom = 0,
insertTo = -1,
deleteFrom = 0,
deleteTo = -1;
if (oldOutputLineCount > newOutputLineCount) {
changeFrom = (lineNumber === 1 ? 1 : this.prefixSumComputer.getAccumulatedValue(lineNumber - 2) + 1);
changeTo = changeFrom + newOutputLineCount - 1;
deleteFrom = changeTo + 1;
deleteTo = deleteFrom + (oldOutputLineCount - newOutputLineCount) - 1;
lineMappingChanged = true;
} else if (oldOutputLineCount < newOutputLineCount) {
changeFrom = (lineNumber === 1 ? 1 : this.prefixSumComputer.getAccumulatedValue(lineNumber - 2) + 1);
changeTo = changeFrom + oldOutputLineCount - 1;
insertFrom = changeTo + 1;
insertTo = insertFrom + (newOutputLineCount - oldOutputLineCount) - 1;
lineMappingChanged = true;
} else {
changeFrom = (lineNumber === 1 ? 1 : this.prefixSumComputer.getAccumulatedValue(lineNumber - 2) + 1);
changeTo = changeFrom + newOutputLineCount - 1;
}
this.prefixSumComputer.changeValue(lineIndex, newOutputLineCount);
var i:number,
e1:editorCommon.IViewLineChangedEvent,
e2:editorCommon.IViewLinesInsertedEvent,
e3:editorCommon.IViewLinesDeletedEvent;
if (changeFrom <= changeTo) {
for (var i = changeFrom; i <= changeTo; i++) {
e1 = {
lineNumber: i
};
emit(editorCommon.ViewEventNames.LineChangedEvent, e1);
}
}
if (insertFrom <= insertTo) {
e2 = {
fromLineNumber: insertFrom,
toLineNumber: insertTo
};
emit(editorCommon.ViewEventNames.LinesInsertedEvent, e2);
}
if (deleteFrom <= deleteTo) {
e3 = {
fromLineNumber: deleteFrom,
toLineNumber: deleteTo
};
emit(editorCommon.ViewEventNames.LinesDeletedEvent, e3);
}
return lineMappingChanged;
}
示例7: getOffsetAt
public getOffsetAt(lineNumber: number, column: number): number {
return this._lineStarts.getAccumulatedValue(lineNumber - 2) + column - 1;
}
示例8: test
test('PrefixSumComputer', () => {
var indexOfResult:IPrefixSumIndexOfResult = {
index: 0,
remainder: 0
};
var psc = new PrefixSumComputer([1, 1, 2, 1, 3]);
assert.equal(psc.getTotalValue(), 8);
assert.equal(psc.getAccumulatedValue(-1), 0);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 2);
assert.equal(psc.getAccumulatedValue(2), 4);
assert.equal(psc.getAccumulatedValue(3), 5);
assert.equal(psc.getAccumulatedValue(4), 8);
psc.getIndexOf(0, indexOfResult);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(1, indexOfResult);
assert.equal(indexOfResult.index, 1);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(2, indexOfResult);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(3, indexOfResult);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 1);
psc.getIndexOf(4, indexOfResult);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(5, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(6, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 1);
psc.getIndexOf(7, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 2);
psc.getIndexOf(8, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 3);
// [1, 2, 2, 1, 3]
psc.changeValue(1, 2);
assert.equal(psc.getTotalValue(), 9);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 3);
assert.equal(psc.getAccumulatedValue(2), 5);
assert.equal(psc.getAccumulatedValue(3), 6);
assert.equal(psc.getAccumulatedValue(4), 9);
// [1, 0, 2, 1, 3]
psc.changeValue(1, 0);
assert.equal(psc.getTotalValue(), 7);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 1);
assert.equal(psc.getAccumulatedValue(2), 3);
assert.equal(psc.getAccumulatedValue(3), 4);
assert.equal(psc.getAccumulatedValue(4), 7);
psc.getIndexOf(0, indexOfResult);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(1, indexOfResult);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(2, indexOfResult);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 1);
psc.getIndexOf(3, indexOfResult);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(4, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(5, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 1);
psc.getIndexOf(6, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 2);
psc.getIndexOf(7, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 3);
// [1, 0, 0, 1, 3]
psc.changeValue(2, 0);
assert.equal(psc.getTotalValue(), 5);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 1);
assert.equal(psc.getAccumulatedValue(2), 1);
assert.equal(psc.getAccumulatedValue(3), 2);
assert.equal(psc.getAccumulatedValue(4), 5);
psc.getIndexOf(0, indexOfResult);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(1, indexOfResult);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(2, indexOfResult);
assert.equal(indexOfResult.index, 4);
//.........這裏部分代碼省略.........
示例9: test
test('PrefixSumComputer', () => {
let indexOfResult: PrefixSumIndexOfResult;
let psc = new PrefixSumComputer(toUint32Array([1, 1, 2, 1, 3]));
assert.equal(psc.getTotalValue(), 8);
assert.equal(psc.getAccumulatedValue(-1), 0);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 2);
assert.equal(psc.getAccumulatedValue(2), 4);
assert.equal(psc.getAccumulatedValue(3), 5);
assert.equal(psc.getAccumulatedValue(4), 8);
indexOfResult = psc.getIndexOf(0);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(1);
assert.equal(indexOfResult.index, 1);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(2);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(3);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 1);
indexOfResult = psc.getIndexOf(4);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(5);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(6);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 1);
indexOfResult = psc.getIndexOf(7);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 2);
indexOfResult = psc.getIndexOf(8);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 3);
// [1, 2, 2, 1, 3]
psc.changeValue(1, 2);
assert.equal(psc.getTotalValue(), 9);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 3);
assert.equal(psc.getAccumulatedValue(2), 5);
assert.equal(psc.getAccumulatedValue(3), 6);
assert.equal(psc.getAccumulatedValue(4), 9);
// [1, 0, 2, 1, 3]
psc.changeValue(1, 0);
assert.equal(psc.getTotalValue(), 7);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 1);
assert.equal(psc.getAccumulatedValue(2), 3);
assert.equal(psc.getAccumulatedValue(3), 4);
assert.equal(psc.getAccumulatedValue(4), 7);
indexOfResult = psc.getIndexOf(0);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(1);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(2);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 1);
indexOfResult = psc.getIndexOf(3);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(4);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(5);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 1);
indexOfResult = psc.getIndexOf(6);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 2);
indexOfResult = psc.getIndexOf(7);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 3);
// [1, 0, 0, 1, 3]
psc.changeValue(2, 0);
assert.equal(psc.getTotalValue(), 5);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 1);
assert.equal(psc.getAccumulatedValue(2), 1);
assert.equal(psc.getAccumulatedValue(3), 2);
assert.equal(psc.getAccumulatedValue(4), 5);
indexOfResult = psc.getIndexOf(0);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(1);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(2);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(3);
assert.equal(indexOfResult.index, 4);
//.........這裏部分代碼省略.........