-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathsorted-map.js
68 lines (59 loc) · 2.08 KB
/
sorted-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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";
var Shim = require("./shim");
var SortedSet = require("./sorted-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 = SortedMap;
function SortedMap(values, equals, compare, getDefault) {
if (!(this instanceof SortedMap)) {
return new SortedMap(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 SortedSet(
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-map").SortedMap will work in MontageJS
SortedMap.SortedMap = SortedMap;
SortedMap.from = GenericCollection.from;
Object.addEach(SortedMap.prototype, GenericCollection.prototype);
Object.addEach(SortedMap.prototype, GenericMap.prototype);
Object.addEach(SortedMap.prototype, PropertyChanges.prototype);
Object.addEach(SortedMap.prototype, MapChanges.prototype);
Object.defineProperty(SortedMap.prototype,"size",GenericCollection._sizePropertyDescriptor);
SortedMap.prototype.constructClone = function (values) {
return new this.constructor(
values,
this.contentEquals,
this.contentCompare,
this.getDefault
);
};
SortedMap.prototype.iterate = function () {
return this.store.iterate();
};
SortedMap.prototype.log = function (charmap, logNode, callback, thisp) {
logNode = logNode || this.logNode
this.store.log(charmap, function (node, log, logBefore) {
logNode(node.value, log, logBefore);
}, callback, thisp);
};
SortedMap.prototype.logNode = function (node, log) {
log(" key: " + node.key);
log(" value: " + node.value);
};