diff --git a/README.md b/README.md index e41a79bca..c43e6394a 100755 --- a/README.md +++ b/README.md @@ -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)) diff --git a/hashset/hashset-tests.ts b/hashset/hashset-tests.ts new file mode 100644 index 000000000..fda2e4d1a --- /dev/null +++ b/hashset/hashset-tests.ts @@ -0,0 +1,36 @@ +/// + +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({ 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({ 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 diff --git a/hashset/hashset.d.ts b/hashset/hashset.d.ts new file mode 100644 index 000000000..fedf7381a --- /dev/null +++ b/hashset/hashset.d.ts @@ -0,0 +1,38 @@ +// Type definitions for jshashset 3.0 +// Project: http://www.timdown.co.uk/jshashtable/jshashset.html +// Definitions by: Sergey Gerasimov +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +interface IHashSet +{ + 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; + + isSubsetOf(set: IHashSet): boolean; + intersection(set: IHashSet): IHashSet; + union(set: IHashSet): IHashSet; + complement(set: IHashSet): IHashSet; +} + +interface IHashSetStatic { + new (): IHashSet; + new (options: IHashtableOptions): IHashSet; + new (hashCode?: (value: TValue) => any, equals?: (value1: TValue, value2: TValue) => boolean): IHashSet; +} + +declare var HashSet: IHashSetStatic; + +declare module "hashset" { + export = HashSet; +} \ No newline at end of file diff --git a/hashtable/hashtable.d.ts b/hashtable/hashtable.d.ts index 1a5ac47b9..fbc0f219a 100644 --- a/hashtable/hashtable.d.ts +++ b/hashtable/hashtable.d.ts @@ -1,6 +1,6 @@ // Type definitions for jshashtable 3.0 // Project: http://www.timdown.co.uk/jshashtable/ -// Definitions by: Sergey Gerasimov +// Definitions by: Sergey Gerasimov // Definitions: https://github.com/borisyankov/DefinitelyTyped interface IHashtable