all files / mapbox-gl-draw/src/lib/ string_set.js

97.37% Statements 37/38
91.67% Branches 11/12
100% Functions 7/7
100% Lines 24/24
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  526× 526× 526× 16× 16× 16×       1187× 1187× 1187×     408× 408× 408×     698×     798× 798×     122× 122× 122×      
function StringSet(items) {
  this._items = {};
  this._length = items ? items.length : 0;
  if (!items) return;
  for (let i = 0, l = items.length; i < l; i++) {
    Iif (items[i] === undefined) continue;
    this._items[items[i]] = i;
  }
}
 
StringSet.prototype.add = function(x) {
  this._length = this._items[x] ? this._length : this._length + 1;
  this._items[x] = this._items[x] ? this._items[x] : this._length;
  return this;
};
 
StringSet.prototype.delete = function(x) {
  this._length = this._items[x] ? this._length - 1 : this._length;
  delete this._items[x];
  return this;
};
 
StringSet.prototype.has = function(x) {
  return this._items[x] !== undefined;
};
 
StringSet.prototype.values = function() {
  const orderedKeys = Object.keys(this._items).sort((a, b) => this._items[a] - this._items[b]);
  return orderedKeys;
};
 
StringSet.prototype.clear = function() {
  this._length = 0;
  this._items = {};
  return this;
};
 
module.exports = StringSet;