本文整理汇总了TypeScript中vs/base/common/linkedList.LinkedList类的典型用法代码示例。如果您正苦于以下问题:TypeScript LinkedList类的具体用法?TypeScript LinkedList怎么用?TypeScript LinkedList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LinkedList类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('Push/Iter', function () {
const list = new LinkedList<number>();
list.push(0);
list.push(1);
list.push(2);
assertElements(list, 0, 1, 2);
});
示例2: test
test('Insert/Iter', function () {
const list = new LinkedList<number>();
list.insert(0);
list.insert(1);
list.insert(2);
assertElements(list, 0, 1, 2);
});
示例3: test
test('unshift/toArray', () => {
let list = new LinkedList<string>();
list.unshift('foo');
list.unshift('bar');
list.unshift('far');
list.unshift('boo');
assertElements(list, 'boo', 'far', 'bar', 'foo');
});
示例4:
function assertElements<E>(list: LinkedList<E>, ...elements: E[]) {
// first: assert toArray
assert.deepEqual(list.toArray(), elements);
// second: assert iterator
for (let iter = list.iterator(), element = iter.next(); !element.done; element = iter.next()) {
assert.equal(elements.shift(), element.value);
}
assert.equal(elements.length, 0);
}
示例5: add
public add(callback: Function, context: any = null, bucket?: IDisposable[]): () => void {
if (!this._callbacks) {
this._callbacks = new LinkedList<[Function, any]>();
}
const remove = this._callbacks.push([callback, context]);
if (Array.isArray(bucket)) {
bucket.push({ dispose: remove });
}
return remove;
}
示例6: entries
public entries(): [Function, any][] {
if (!this._callbacks) {
return [];
}
return this._callbacks
? this._callbacks.toArray()
: [];
}
示例7: invoke
public invoke(...args: any[]): any[] {
if (!this._callbacks) {
return undefined;
}
const ret: any[] = [];
const elements = this._callbacks.toArray();
for (const [callback, context] of elements) {
try {
ret.push(callback.apply(context, args));
} catch (e) {
onUnexpectedError(e);
}
}
return ret;
}