-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
75 lines (64 loc) · 1.66 KB
/
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
69
70
71
72
73
74
75
'use strict';
module.exports = d3_Map;
function d3_Map() {}
d3_class(d3_Map, {
has: d3_map_has,
get: function(key) {
return this[d3_map_prefix + key];
},
set: function(key, value) {
return this[d3_map_prefix + key] = value;
},
remove: d3_map_remove,
keys: d3_map_keys,
values: function() {
var values = [];
this.forEach(function(key, value) { values.push(value); });
return values;
},
entries: function() {
var entries = [];
this.forEach(function(key, value) { entries.push({key: key, value: value}); });
return entries;
},
size: d3_map_size,
empty: d3_map_empty,
forEach: function(f) {
for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) f.call(this, key.substring(1), this[key]);
}
});
var d3_map_prefix = "\0", // prevent collision with built-ins
d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
function d3_map_has(key) {
return d3_map_prefix + key in this;
}
function d3_map_remove(key) {
key = d3_map_prefix + key;
return key in this && delete this[key];
}
function d3_map_keys() {
var keys = [];
this.forEach(function(key) { keys.push(key); });
return keys;
}
function d3_map_size() {
var size = 0;
for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) ++size;
return size;
}
function d3_map_empty() {
for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) return false;
return true;
}
function d3_class(ctor, properties) {
try {
for (var key in properties) {
Object.defineProperty(ctor.prototype, key, {
value: properties[key],
enumerable: false
});
}
} catch (e) {
ctor.prototype = properties;
}
}