-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
114 lines (77 loc) · 1.66 KB
/
Copy pathindex.js
File metadata and controls
114 lines (77 loc) · 1.66 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
(function (window) {
'use strict';
// UMD
if(typeof define !== 'function') {
window.define = function(deps, definition) {
window.pintxos = window.pintxos || {};
window.pintxos.Map = definition();
define = null;
};
}
define([], function () {
var Map;
/* Constructor
----------------------------------------------- */
Map = function () {
this._data = [];
this._length = 0;
};
/* Methods
----------------------------------------------- */
Map.prototype.get = function (key) {
var index;
index = this._indexOf(key);
return (index > -1) ? clone(this._data[index]) : undefined;
};
Map.prototype.set = function (key, value) {
var entry, index;
entry = {
key: key,
value: value
};
index = this._indexOf(key);
if(index > -1) {
this._data[index] = entry;
}else {
this._data.push(entry);
this._length = this._data.length;
}
};
Map.prototype._indexOf = function (key) {
var result, i;
i = 0;
result = -1;
for ( ; i < this._length; i ++) {
if(this._data[i].key === key) {
result = i;
break;
}
}
return result;
};
Map.prototype.remove = function (key) {
var index;
index = this._indexOf(key);
if(index > -1) {
this._data.splice(index, 1);
}
};
Map.prototype.empty = function () {
this._data = [];
this._length = 0;
}
/* Helpers
----------------------------------------------- */
function clone (obj) {
var dest;
dest = {};
for (var key in obj) {
dest[key] = obj[key];
}
return dest;
}
/* Export
----------------------------------------------- */
return Map;
});
})(this);