Merge VS Code 1.31.1 (#4283)

This commit is contained in:
Matt Irvine
2019-03-15 13:09:45 -07:00
committed by GitHub
parent 7d31575149
commit 86bac90001
1716 changed files with 53308 additions and 48375 deletions

View File

@@ -32,17 +32,18 @@ export class LinkedList<E> {
clear(): void {
this._first = undefined;
this._last = undefined;
this._size = 0;
}
unshift(element: E) {
return this.insert(element, false);
unshift(element: E): () => void {
return this._insert(element, false);
}
push(element: E) {
return this.insert(element, true);
push(element: E): () => void {
return this._insert(element, true);
}
private insert(element: E, atTheEnd: boolean) {
private _insert(element: E, atTheEnd: boolean): () => void {
const newNode = new Node(element);
if (!this._first) {
this._first = newNode;
@@ -63,41 +64,63 @@ export class LinkedList<E> {
oldFirst.prev = newNode;
}
this._size += 1;
return this._remove.bind(this, newNode);
}
return () => {
let candidate: Node<E> | undefined = this._first;
while (candidate instanceof Node) {
if (candidate !== newNode) {
candidate = candidate.next;
continue;
}
if (candidate.prev && candidate.next) {
// middle
let anchor = candidate.prev;
anchor.next = candidate.next;
candidate.next.prev = anchor;
} else if (!candidate.prev && !candidate.next) {
// only node
this._first = undefined;
this._last = undefined;
shift(): E | undefined {
if (!this._first) {
return undefined;
} else {
const res = this._first.element;
this._remove(this._first);
return res;
}
}
} else if (!candidate.next) {
// last
this._last = this._last!.prev!;
this._last.next = undefined;
pop(): E | undefined {
if (!this._last) {
return undefined;
} else {
const res = this._last.element;
this._remove(this._last);
return res;
}
}
} else if (!candidate.prev) {
// first
this._first = this._first!.next!;
this._first.prev = undefined;
}
// done
this._size -= 1;
break;
private _remove(node: Node<E>): void {
let candidate: Node<E> | undefined = this._first;
while (candidate instanceof Node) {
if (candidate !== node) {
candidate = candidate.next;
continue;
}
};
if (candidate.prev && candidate.next) {
// middle
let anchor = candidate.prev;
anchor.next = candidate.next;
candidate.next.prev = anchor;
} else if (!candidate.prev && !candidate.next) {
// only node
this._first = undefined;
this._last = undefined;
} else if (!candidate.next) {
// last
this._last = this._last!.prev!;
this._last.next = undefined;
} else if (!candidate.prev) {
// first
this._first = this._first!.next!;
this._first.prev = undefined;
}
// done
this._size -= 1;
break;
}
}
iterator(): Iterator<E> {