mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
Merge pull request #18202 from CjS77/master
Update bintrees to Typescript 2.4
This commit is contained in:
@@ -1,14 +1,50 @@
|
||||
/// <reference types="mocha" />
|
||||
/// <reference types="node" />
|
||||
import assert = require('assert');
|
||||
import { BinTree, RBTree } from 'bintrees';
|
||||
|
||||
let treeA = new RBTree((a:number, b:number) => a - b);
|
||||
describe('bintrees', () => {
|
||||
it('builds a simple tree', () => {
|
||||
let treeA = new RBTree((a: number, b: number) => a - b);
|
||||
|
||||
treeA.insert(5);
|
||||
treeA.insert(3);
|
||||
treeA.remove(3);
|
||||
treeA.insert(5);
|
||||
treeA.insert(3);
|
||||
treeA.remove(3);
|
||||
|
||||
let treeB = new BinTree((a:string, b:string) => a.length - b.length);
|
||||
assert.equal(treeA.size, 1);
|
||||
});
|
||||
|
||||
it('builds a tree of strings', () => {
|
||||
let treeB = new BinTree((a:string, b:string) => a.length - b.length);
|
||||
|
||||
treeB.insert('hi');
|
||||
treeB.insert('there');
|
||||
treeB.insert('how');
|
||||
treeB.insert('are'); // ignored
|
||||
treeB.remove('how');
|
||||
|
||||
assert.equal(treeB.size, 2);
|
||||
assert.equal(treeB.min(), 'hi');
|
||||
});
|
||||
|
||||
it('maintains a tree of objects', () => {
|
||||
|
||||
interface C {
|
||||
id: number
|
||||
}
|
||||
|
||||
let treeC = new BinTree<C>((a: C, b: C) => a.id - b.id);
|
||||
|
||||
treeC.insert({ id: 100 });
|
||||
treeC.insert({ id: 110 });
|
||||
treeC.insert({ id: 105 });
|
||||
|
||||
let ids: number[] = [];
|
||||
treeC.each((val: C) => {
|
||||
ids.push(val.id);
|
||||
});
|
||||
|
||||
assert.deepEqual(ids, [100, 105, 110]);
|
||||
});
|
||||
});
|
||||
|
||||
treeB.insert('hi');
|
||||
treeB.insert('there');
|
||||
treeB.insert('how');
|
||||
treeB.insert('are');
|
||||
|
||||
Vendored
+6
-6
@@ -5,8 +5,8 @@
|
||||
|
||||
declare module 'bintrees' {
|
||||
|
||||
type Callback = <T>(item: T) => void;
|
||||
type Comparator = <T>(a: T, b: T) => number;
|
||||
type Callback<T> = (item: T) => void;
|
||||
type Comparator<T> = (a: T, b: T) => number;
|
||||
|
||||
class Iterator<T> {
|
||||
constructor(tree: TreeBase<T>);
|
||||
@@ -37,14 +37,14 @@ declare module 'bintrees' {
|
||||
|
||||
iterator(): Iterator<T>;
|
||||
|
||||
each(cb: Callback): void;
|
||||
each(cb: Callback<T>): void;
|
||||
|
||||
reach(cb: Callback): void;
|
||||
reach(cb: Callback<T>): void;
|
||||
}
|
||||
|
||||
|
||||
export class RBTree<T> extends TreeBase<T> {
|
||||
constructor(comparator: Comparator);
|
||||
constructor(comparator: Comparator<T>);
|
||||
|
||||
insert(item: T): boolean;
|
||||
|
||||
@@ -52,7 +52,7 @@ declare module 'bintrees' {
|
||||
}
|
||||
|
||||
export class BinTree<T> extends TreeBase<T> {
|
||||
constructor(comparator: Comparator);
|
||||
constructor(comparator: Comparator<T>);
|
||||
|
||||
insert(item: T): boolean;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user