Johannes Rieken 2022-09-28 15:11:24 +02:00 committed by GitHub
parent dfca1cc002
commit 2428297798
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 5 deletions

View file

@ -576,12 +576,16 @@ export class TernarySearchTree<K, V> {
if (!node.mid && !node.value) {
if (node.left && node.right) {
// full node
// replace deleted-node with the min-node of the right branch.
// If there is no true min-node leave things as they are
const min = this._min(node.right);
const { key, value, segment } = min;
this._delete(min.key!, false);
node.key = key;
node.value = value;
node.segment = segment;
if (min.key) {
const { key, value, segment } = min;
this._delete(min.key!, false);
node.key = key;
node.value = value;
node.segment = segment;
}
} else {
// empty or half empty

View file

@ -862,6 +862,49 @@ suite('Map', () => {
}
});
test('TernarySearchTree: Cannot read properties of undefined (reading \'length\'): #161618 (simple)', function () {
const raw = 'config.debug.toolBarLocation,floating,config.editor.renderControlCharacters,true,config.editor.renderWhitespace,selection,config.files.autoSave,off,config.git.enabled,true,config.notebook.globalToolbar,true,config.terminal.integrated.tabs.enabled,true,config.terminal.integrated.tabs.showActions,singleTerminalOrNarrow,config.terminal.integrated.tabs.showActiveTerminal,singleTerminalOrNarrow,config.workbench.activityBar.visible,true,config.workbench.experimental.settingsProfiles.enabled,true,config.workbench.layoutControl.type,both,config.workbench.sideBar.location,left,config.workbench.statusBar.visible,true';
const array = raw.split(',');
const tuples: [string, string][] = [];
for (let i = 0; i < array.length; i += 2) {
tuples.push([array[i], array[i + 1]]);
}
const map = TernarySearchTree.forConfigKeys<string>();
map.fill(tuples);
assert.strictEqual([...map].join(), raw);
assert.ok(map.has('config.editor.renderWhitespace'));
const len = [...map].length;
map.delete('config.editor.renderWhitespace');
assert.ok(map._isBalanced());
assert.strictEqual([...map].length, len - 1);
});
test('TernarySearchTree: Cannot read properties of undefined (reading \'length\'): #161618 (random)', function () {
const raw = 'config.debug.toolBarLocation,floating,config.editor.renderControlCharacters,true,config.editor.renderWhitespace,selection,config.files.autoSave,off,config.git.enabled,true,config.notebook.globalToolbar,true,config.terminal.integrated.tabs.enabled,true,config.terminal.integrated.tabs.showActions,singleTerminalOrNarrow,config.terminal.integrated.tabs.showActiveTerminal,singleTerminalOrNarrow,config.workbench.activityBar.visible,true,config.workbench.experimental.settingsProfiles.enabled,true,config.workbench.layoutControl.type,both,config.workbench.sideBar.location,left,config.workbench.statusBar.visible,true';
const array = raw.split(',');
const tuples: [string, string][] = [];
for (let i = 0; i < array.length; i += 2) {
tuples.push([array[i], array[i + 1]]);
}
for (let round = 100; round >= 0; round--) {
shuffle(tuples);
const map = TernarySearchTree.forConfigKeys<string>();
map.fill(tuples);
assert.strictEqual([...map].join(), raw);
assert.ok(map.has('config.editor.renderWhitespace'));
const len = [...map].length;
map.delete('config.editor.renderWhitespace');
assert.ok(map._isBalanced());
assert.strictEqual([...map].length, len - 1);
}
});
test('TernarySearchTree (PathSegments) - lookup', function () {
const map = new TernarySearchTree<string, number>(new PathIterator());