mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
hashset definitions
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/// <reference path="hashset.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 points = new HashSet<Point>({ hashCode: hashPoint, equals: pointsEqual });
|
||||
|
||||
points.add(new Point(1, 2));
|
||||
points.add(new Point(2, 3));
|
||||
points.add(new Point(1, 2));
|
||||
points.add(new Point(6, 5));
|
||||
|
||||
alert(points.size()); // Alerts 3
|
||||
|
||||
var otherPoints = new HashSet<Point>({ hashCode: hashPoint, equals: pointsEqual });
|
||||
|
||||
otherPoints.add(new Point(4, 4));
|
||||
otherPoints.add(new Point(7, 9));
|
||||
otherPoints.add(new Point(2, 3));
|
||||
otherPoints.add(new Point(6, 5));
|
||||
|
||||
var intersection = points.intersection(otherPoints);
|
||||
|
||||
alert(intersection.contains(new Point(2, 3))); // Alerts true
|
||||
alert(intersection.contains(new Point(7, 9))); // Alerts false
|
||||
alert(intersection.size()); // Alerts 2
|
||||
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
// Type definitions for jshashset 3.0
|
||||
// Project: http://www.timdown.co.uk/jshashtable/jshashset.html
|
||||
// Definitions by: Sergey Gerasimov <https://github.com/gerichhome/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../hashtable/hashtable.d.ts" />
|
||||
|
||||
interface IHashSet<TValue>
|
||||
{
|
||||
add(value: TValue): void;
|
||||
addAll(arr: TValue[]): void;
|
||||
contains(value: TValue): boolean;
|
||||
|
||||
clear(): void;
|
||||
isEmpty(): boolean; values(): TValue[];
|
||||
|
||||
remove(value: TValue): void;
|
||||
size(): number;
|
||||
|
||||
clone(): IHashSet<TValue>;
|
||||
|
||||
isSubsetOf(set: IHashSet<TValue>): boolean;
|
||||
intersection(set: IHashSet<TValue>): IHashSet<TValue>;
|
||||
union(set: IHashSet<TValue>): IHashSet<TValue>;
|
||||
complement(set: IHashSet<TValue>): IHashSet<TValue>;
|
||||
}
|
||||
|
||||
interface IHashSetStatic {
|
||||
new <TValue>(): IHashSet<TValue>;
|
||||
new <TValue>(options: IHashtableOptions<TValue>): IHashSet<TValue>;
|
||||
new <TValue>(hashCode?: (value: TValue) => any, equals?: (value1: TValue, value2: TValue) => boolean): IHashSet<TValue>;
|
||||
}
|
||||
|
||||
declare var HashSet: IHashSetStatic;
|
||||
|
||||
declare module "hashset" {
|
||||
export = HashSet;
|
||||
}
|
||||
Reference in New Issue
Block a user