Skip to content

Commit ab4e800

Browse files
committed
Merge pull request DefinitelyTyped#1520 from gerich-home/master
hashset definitions
2 parents 22112f3 + a58a981 commit ab4e800

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ List of Definitions
9494
* [Google Url Shortener](https://developers.google.com/url-shortener/) (by [Frank M](https://github.com/sgtfrankieboy))
9595
* [Hammer.js](http://eightmedia.github.com/hammer.js/) (by [Boris Yankov](https://github.com/borisyankov))
9696
* [Handlebars](http://handlebarsjs.com/) (by [Boris Yankov](https://github.com/borisyankov))
97+
* [HashSet](http://www.timdown.co.uk/jshashtable/jshashset.html) (by [Sergey Gerasimov](https://github.com/gerich-home))
98+
* [Hashtable](http://www.timdown.co.uk/jshashtable/) (by [Sergey Gerasimov](https://github.com/gerich-home))
9799
* [Highcharts](http://www.highcharts.com/) (by [damianog](https://github.com/damianog))
98100
* [highlight.js](https://github.com/isagalaev/highlight.js) (by [Niklas Mollenhauer](https://github.com/nikeee))
99101
* [History.js](https://github.com/browserstate/history.js) (by [Boris Yankov](https://github.com/borisyankov))

hashset/hashset-tests.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// <reference path="hashset.d.ts" />
2+
3+
class Point {
4+
constructor(public x: number, public y: number) {
5+
}
6+
}
7+
8+
function hashPoint(p: Point) {
9+
return "Point:" + p.x + "," + p.y;
10+
}
11+
12+
function pointsEqual(p1: Point, p2: Point) {
13+
return p1.x === p2.x && p1.y === p2.y;
14+
}
15+
16+
var points = new HashSet<Point>({ hashCode: hashPoint, equals: pointsEqual });
17+
18+
points.add(new Point(1, 2));
19+
points.add(new Point(2, 3));
20+
points.add(new Point(1, 2));
21+
points.add(new Point(6, 5));
22+
23+
alert(points.size()); // Alerts 3
24+
25+
var otherPoints = new HashSet<Point>({ hashCode: hashPoint, equals: pointsEqual });
26+
27+
otherPoints.add(new Point(4, 4));
28+
otherPoints.add(new Point(7, 9));
29+
otherPoints.add(new Point(2, 3));
30+
otherPoints.add(new Point(6, 5));
31+
32+
var intersection = points.intersection(otherPoints);
33+
34+
alert(intersection.contains(new Point(2, 3))); // Alerts true
35+
alert(intersection.contains(new Point(7, 9))); // Alerts false
36+
alert(intersection.size()); // Alerts 2

hashset/hashset.d.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Type definitions for jshashset 3.0
2+
// Project: http://www.timdown.co.uk/jshashtable/jshashset.html
3+
// Definitions by: Sergey Gerasimov <https://github.com/gerich-home/>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
/// <reference path="../hashtable/hashtable.d.ts" />
7+
8+
interface IHashSet<TValue>
9+
{
10+
add(value: TValue): void;
11+
addAll(arr: TValue[]): void;
12+
contains(value: TValue): boolean;
13+
14+
clear(): void;
15+
isEmpty(): boolean; values(): TValue[];
16+
17+
remove(value: TValue): void;
18+
size(): number;
19+
20+
clone(): IHashSet<TValue>;
21+
22+
isSubsetOf(set: IHashSet<TValue>): boolean;
23+
intersection(set: IHashSet<TValue>): IHashSet<TValue>;
24+
union(set: IHashSet<TValue>): IHashSet<TValue>;
25+
complement(set: IHashSet<TValue>): IHashSet<TValue>;
26+
}
27+
28+
interface IHashSetStatic {
29+
new <TValue>(): IHashSet<TValue>;
30+
new <TValue>(options: IHashtableOptions<TValue>): IHashSet<TValue>;
31+
new <TValue>(hashCode?: (value: TValue) => any, equals?: (value1: TValue, value2: TValue) => boolean): IHashSet<TValue>;
32+
}
33+
34+
declare var HashSet: IHashSetStatic;
35+
36+
declare module "hashset" {
37+
export = HashSet;
38+
}

hashtable/hashtable.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Type definitions for jshashtable 3.0
22
// Project: http://www.timdown.co.uk/jshashtable/
3-
// Definitions by: Sergey Gerasimov <https://github.com/gerichhome/>
3+
// Definitions by: Sergey Gerasimov <https://github.com/gerich-home/>
44
// Definitions: https://github.com/borisyankov/DefinitelyTyped
55

66
interface IHashtable<TKey, TValue>

0 commit comments

Comments
 (0)