webpack/lib/ArrayMap.js

58 lines
962 B
JavaScript
Raw Normal View History

2013-01-31 01:49:25 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
class ArrayMap {
constructor() {
this.keys = [];
this.values = [];
}
get(key) {
for(let i = 0; i < this.keys.length; i++) {
if(this.keys[i] === key) {
return this.values[i];
}
2013-01-31 01:49:25 +08:00
}
return;
2013-01-31 01:49:25 +08:00
}
set(key, value) {
for(let i = 0; i < this.keys.length; i++) {
if(this.keys[i] === key) {
this.values[i] = value;
return this;
}
2013-01-31 01:49:25 +08:00
}
this.keys.push(key);
this.values.push(value);
return this;
2013-01-31 01:49:25 +08:00
}
remove(key) {
for(let i = 0; i < this.keys.length; i++) {
if(this.keys[i] === key) {
this.keys.splice(i, 1);
this.values.splice(i, 1);
return true;
}
2013-01-31 01:49:25 +08:00
}
return false;
2013-01-31 01:49:25 +08:00
}
clone() {
const newMap = new ArrayMap();
for(let i = 0; i < this.keys.length; i++) {
newMap.keys.push(this.keys[i]);
newMap.values.push(this.values[i]);
}
return newMap;
2013-01-31 01:49:25 +08:00
}
}
module.exports = ArrayMap;