montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.09k stars 185 forks source link

Couldn't override equals and hash of Map #203

Open Deilan opened 6 years ago

Deilan commented 6 years ago

A very simple test couldn't pass:

var Map = require("collections/map");

var equals = function(a, b) {
    return a.x === b.x;
};
var hash = function(a) {
    return a.x;
}
var map = new Map([], equals, hash);
var key1 = {x: 1};
var key2 = {x: 1};
map.set(key1, 42);
console.log(map.has(key2));

Expected output: true

Actual output: false

lib v. 5.1.2, Node.js 8.9.1, macOS 10.13.4.

hthetiot commented 6 years ago

I dont think it is supported.

asiraky commented 5 years ago

But it's documented:

"The optional equals and hash override the contentEquals and contentHash properties that operate on the keys of the map to determine whether keys are equivalent and where to store them."

http://www.collectionsjs.com/map