Merge pull request #1520 from gerich-home/master

hashset definitions
This commit is contained in:
Igorbek
2014-01-09 01:02:04 -08:00
4 changed files with 77 additions and 1 deletions
+2
View File
@@ -94,6 +94,8 @@ List of Definitions
* [Google Url Shortener](https://developers.google.com/url-shortener/) (by [Frank M](https://github.com/sgtfrankieboy))
* [Hammer.js](http://eightmedia.github.com/hammer.js/) (by [Boris Yankov](https://github.com/borisyankov))
* [Handlebars](http://handlebarsjs.com/) (by [Boris Yankov](https://github.com/borisyankov))
* [HashSet](http://www.timdown.co.uk/jshashtable/jshashset.html) (by [Sergey Gerasimov](https://github.com/gerich-home))
* [Hashtable](http://www.timdown.co.uk/jshashtable/) (by [Sergey Gerasimov](https://github.com/gerich-home))
* [Highcharts](http://www.highcharts.com/) (by [damianog](https://github.com/damianog))
* [highlight.js](https://github.com/isagalaev/highlight.js) (by [Niklas Mollenhauer](https://github.com/nikeee))
* [History.js](https://github.com/browserstate/history.js) (by [Boris Yankov](https://github.com/borisyankov))
+36
View File
@@ -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
+38
View File
@@ -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/gerich-home/>
// 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;
}
+1 -1
View File
@@ -1,6 +1,6 @@
// Type definitions for jshashtable 3.0
// Project: http://www.timdown.co.uk/jshashtable/
// Definitions by: Sergey Gerasimov <https://github.com/gerichhome/>
// Definitions by: Sergey Gerasimov <https://github.com/gerich-home/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface IHashtable<TKey, TValue>