mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-30 23:30:06 +00:00
25
hashtable/hashtable-tests.ts
Normal file
25
hashtable/hashtable-tests.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/// <reference path="hashtable.d.ts" />
|
||||
|
||||
class Point {
|
||||
constructor(public x: number, public y: number) {
|
||||
}
|
||||
}
|
||||
|
||||
function hashPoint(p: Point) {
|
||||
return "Point:" + p.x + "," + p.y;
|
||||
}
|
||||
|
||||
function pointsEqual(p1: Point, p2: Point) {
|
||||
return p1.x === p2.x && p1.y === p2.y;
|
||||
}
|
||||
|
||||
var coloursForPoints = new Hashtable<Point, string>({ hashCode: hashPoint, equals: pointsEqual });
|
||||
|
||||
function getColourAt(x: number, y: number) {
|
||||
var point = new Point(x, y);
|
||||
return coloursForPoints.get(point);
|
||||
}
|
||||
|
||||
coloursForPoints.put(new Point(1, 2), "green");
|
||||
|
||||
alert(getColourAt(1, 2)); // Alerts green
|
||||
48
hashtable/hashtable.d.ts
vendored
Normal file
48
hashtable/hashtable.d.ts
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
// Type definitions for jshashtable 3.0
|
||||
// Project: http://www.timdown.co.uk/jshashtable/
|
||||
// Definitions by: Sergey Gerasimov <https://github.com/gerichhome/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface IHashtable<TKey, TValue>
|
||||
{
|
||||
put(key: TKey, value: TValue): TValue;
|
||||
putAll(hashtable: IHashtable<TKey, TValue>, conflictCallback?: (key: TKey, thisValue: TValue, value: TValue) => TValue): void;
|
||||
|
||||
get(key: TKey): TValue;
|
||||
containsKey(key: TKey): boolean;
|
||||
containsValue(value: TValue): boolean;
|
||||
|
||||
clear(): void;
|
||||
isEmpty(): boolean;
|
||||
|
||||
keys(): TKey[];
|
||||
values(): TValue[];
|
||||
entries(): any[][];
|
||||
|
||||
remove(key: TKey): TValue;
|
||||
size(): number;
|
||||
|
||||
clone(): IHashtable<TKey, TValue>;
|
||||
each(callback: (key: TKey, value: TValue) => void): void;
|
||||
|
||||
equals(hashtable: IHashtable<TKey, TValue>): boolean;
|
||||
toQueryString(): string;
|
||||
}
|
||||
|
||||
interface IHashtableOptions<TKey> {
|
||||
hashCode?: (key: TKey) => any;
|
||||
equals?: (key1: TKey, key2: TKey) => boolean;
|
||||
replaceDuplicateKey?: boolean;
|
||||
}
|
||||
|
||||
interface IHashtableStatic {
|
||||
new <TKey, TValue>(): IHashtable<TKey, TValue>;
|
||||
new <TKey, TValue>(options: IHashtableOptions<TKey>): IHashtable<TKey, TValue>;
|
||||
new <TKey, TValue>(hashCode?: (value: TValue) => any, equals?: (value1: TValue, value2: TValue) => boolean): IHashtable<TKey, TValue>;
|
||||
}
|
||||
|
||||
declare var Hashtable: IHashtableStatic;
|
||||
|
||||
declare module "hashtable" {
|
||||
export = Hashtable;
|
||||
}
|
||||
Reference in New Issue
Block a user