15

Typescriptコンパイラのコードに、「HashTable」の実装が表示されます(src/compiler/core/hashTable.tsファイル内)。

Typescriptプロジェクトで直接使用できる方法があることを知っていますか?

4

4 に答える 4

1

ファイル「hashTable.ts」をダウンロードして、ファイルのすぐ隣に置きます。次に、ファイルの先頭で次のようにします。

///<reference path='hashTable.ts' />

PS: 私が作成したライブラリを確認することをお勧めします TypeScript Generic Collections。辞書のサンプルは次のとおりです。

class Person {
    constructor(public name: string, public yearOfBirth: number,public city?:string) {
    }
    toString() {
        return this.name + "-" + this.yearOfBirth; // City is not a part of the key. 
    }
}

class Car {
    constructor(public company: string, public type: string, public year: number) {
    }
    toString() {
        // Short hand. Adds each own property 
        return collections.toString(this);
    }
}
var dict = new collections.Dictionary<Person, Car>();
dict.setValue(new Person("john", 1970,"melbourne"), new Car("honda", "city", 2002));
dict.setValue(new Person("gavin", 1984), new Car("ferrari", "F50", 2006));
console.log("Orig");
console.log(dict);

// Changes the same john, since city is not part of key 
dict.setValue(new Person("john", 1970, "sydney"), new Car("honda", "accord", 2006)); 
// Add a new john
dict.setValue(new Person("john", 1971), new Car("nissan", "micra", 2010)); 
console.log("Updated");
console.log(dict);

// Showing getting / setting a single car: 
console.log("Single Item");
var person = new Person("john", 1970); 
console.log("-Person:");
console.log(person);

var car = dict.getValue(person);
console.log("-Car:");
console.log(car.toString());
于 2013-09-12T08:02:53.310 に答える