src/vs/base/common/linkedList.ts
151 LOC · 142 covered · 9 uncovered · 45 ranges · 17534 concepts · 24 introducers · 10859 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
linkedList.ts ×13
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
class Node<E> {
static readonly Undefined = new Node<unknown>(undefined);
element: E;
next: Node<E> | typeof Node.Undefined;
prev: Node<E> | typeof Node.Undefined;
constructor(element: E) {
this.element = element;
this.next = Node.Undefined;
this.prev = Node.Undefined;
}
}
export class LinkedList<E> {
private _first: Node<E> | typeof Node.Undefined = Node.Undefined;
private _last: Node<E> | typeof Node.Undefined = Node.Undefined;
private _size: number = 0;
get size(): number {
}
isEmpty(): boolean {
}
clear(): void {
while (node !== Node.Undefined) {
node.prev = Node.Undefined;
node.next = Node.Undefined;
node = next;
}
this._first = Node.Undefined;
this._last = Node.Undefined;
this._size = 0;
}
unshift(element: E): () => void {
}
push(element: E): () => void {
}
private _insert(element: E, atTheEnd: boolean): () => void {
if (this._first === Node.Undefined) {
this._first = newNode;
this._last = newNode;
} else if (atTheEnd) {
const oldLast = this._last;
this._last = newNode;
newNode.prev = oldLast;
oldLast.next = newNode;
const oldFirst = this._first;
this._first = newNode;
newNode.next = oldFirst;
oldFirst.prev = newNode;
}
let didRemove = false;
return () => {
didRemove = true;
this._remove(newNode);
}
};
shift(): E | undefined {
return undefined;
const res = this._first.element;
this._remove(this._first);
return res as E;
}
}
pop(): E | undefined {
return undefined;
const res = this._last.element;
this._remove(this._last);
return res as E;
}
}
peek(): E | undefined {
if (this._last === Node.Undefined) {
return undefined;
} else {
const res = this._last.element;
return res as E;
}
}
private _remove(node: Node<E> | typeof Node.Undefined): void {
const anchor = node.prev;
anchor.next = node.next;
node.next.prev = anchor;
this._first = Node.Undefined;
this._last = Node.Undefined;
this._last = this._last.prev!;
this._last.next = Node.Undefined;
this._first = this._first.next!;
this._first.prev = Node.Undefined;
}
// done
this._size -= 1;
}
*[Symbol.iterator](): Iterator<E> {
while (node !== Node.Undefined) {
}