browserify-hmr
Version:
Hot Module Replacement plugin for Browserify
76 lines (72 loc) • 1.49 kB
JavaScript
'use strict';
var has = require('./has');
function StrSet(other) {
this._map = {};
this._size = 0;
if (other) {
for (var i=0,len=other.length; i<len; i++) {
this.add(other[i]);
}
}
}
StrSet.prototype.add = function(value) {
if (!this.has(value)) {
this._map[value] = true;
this._size++;
}
};
StrSet.prototype.has = function(value) {
return has(this._map, value);
};
StrSet.prototype.del = function(value) {
if (this.has(value)) {
delete this._map[value];
this._size--;
}
};
StrSet.prototype.size = function() {
return this._size;
};
StrSet.prototype.forEach = function(cb) {
for (var value in this._map) {
if (has(this._map, value)) {
cb(value);
}
}
};
StrSet.prototype.some = function(cb) {
for (var value in this._map) {
if (has(this._map, value)) {
if (cb(value)) {
return true;
}
}
}
return false;
};
StrSet.prototype.every = function(cb) {
return !this.some(function(x) {
return !cb(x);
});
};
StrSet.prototype.hasIntersection = function(otherStrSet) {
var value;
if (this._size < otherStrSet._size) {
return this.some(function(value) {
return otherStrSet.has(value);
});
} else {
var self = this;
return otherStrSet.some(function(value) {
return self.has(value);
});
}
};
StrSet.prototype.toArray = function() {
var arr = [];
this.forEach(function(value) {
arr.push(value);
});
return arr;
};
module.exports = StrSet;