forked from montagejs/collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti-map.js
39 lines (31 loc) · 940 Bytes
/
multi-map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict";
var Map = require("./map");
module.exports = MultiMap;
function MultiMap(values, bucket, equals, hash) {
if (!(this instanceof MultiMap)) {
return new MultiMap(values, bucket, equals, hash);
}
this.bucket = bucket || this.bucket;
Map.call(this, values, equals, hash, function getDefault(key) {
var bucket = this.bucket();
Map.prototype.set.call(this, key, bucket);
return bucket;
});
}
MultiMap.prototype = Object.create(Map.prototype);
MultiMap.prototype.constructor = MultiMap;
MultiMap.prototype.constructClone = function (values) {
return new this.constructor(
values,
this.bucket,
this.contentEquals,
this.contentHash
);
};
MultiMap.prototype.set = function (key, newValues) {
var values = this.get(key);
values.swap(0, values.length, newValues);
};
MultiMap.prototype.bucket = function (key) {
return [];
};