-
Notifications
You must be signed in to change notification settings - Fork 184
/
sorted-array-map.js
54 lines (46 loc) · 1.69 KB
/
sorted-array-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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
var Shim = require("./shim");
var SortedArraySet = require("./sorted-array-set");
var GenericCollection = require("./generic-collection");
var GenericMap = require("./generic-map");
var PropertyChanges = require("./listen/property-changes");
var MapChanges = require("./listen/map-changes");
module.exports = SortedArrayMap;
function SortedArrayMap(values, equals, compare, getDefault) {
if (!(this instanceof SortedArrayMap)) {
return new SortedArrayMap(values, equals, compare, getDefault);
}
equals = equals || Object.equals;
compare = compare || Object.compare;
getDefault = getDefault || Function.noop;
this.contentEquals = equals;
this.contentCompare = compare;
this.getDefault = getDefault;
this.store = new SortedArraySet(
null,
function keysEqual(a, b) {
return equals(a.key, b.key);
},
function compareKeys(a, b) {
return compare(a.key, b.key);
}
);
this.length = 0;
this.addEach(values);
}
// hack so require("sorted-array-map").SortedArrayMap will work in MontageJS
SortedArrayMap.SortedArrayMap = SortedArrayMap;
Object.addEach(SortedArrayMap.prototype, GenericCollection.prototype);
Object.addEach(SortedArrayMap.prototype, GenericMap.prototype);
Object.addEach(SortedArrayMap.prototype, PropertyChanges.prototype);
Object.addEach(SortedArrayMap.prototype, MapChanges.prototype);
SortedArrayMap.from = GenericCollection.from;
SortedArrayMap.prototype.isSorted = true;
SortedArrayMap.prototype.constructClone = function (values) {
return new this.constructor(
values,
this.contentEquals,
this.contentCompare,
this.getDefault
);
};