javasetmap.ts
Java-style Set and Map collections (on { hashCode(): int, equals(x: any): boolean}
objects) written in TypeScript.
Installation
NPM: npm install javasetmap.ts --save
In the browser, you can include the UMD bundle in a script tag, and the module will be available under the global javasetmap_ts
Usage
import {JavaMap} from 'javasetmap.ts'
declare global {
interface Array<T> extends Equalable {}
interface Number extends Equalable {}
}
Array.prototype.equals = function (o) {
return this == o || this.length == o.length && this.every((el, i) => el.equals(o[i]))
}
Array.prototype.hashCode = function () {
return this.reduce((acc, current) => acc * 31 + current.hashCode(), 0)
}
Number.prototype.equals = function (o) { return this == o }
Number.prototype.hashCode = function () { return this | 0 }
const myMap = new JavaMap<[number, number], string>()
myMap.set([1, 2], "foo")
myMap.has([1, 2])
myMap.get([1, 2])
myMap.has([1, 3])
myMap.get([2, 1])
LICENSE
MIT