You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
964 B

5 years ago
  1. /*! (c) Andrea Giammarchi - ISC */
  2. var self = this || /* istanbul ignore next */ {};
  3. try { self.Map = Map; }
  4. catch (Map) {
  5. self.Map = function Map() {
  6. var i = 0;
  7. var k = [];
  8. var v = [];
  9. return {
  10. delete: function (key) {
  11. var had = contains(key);
  12. if (had) {
  13. k.splice(i, 1);
  14. v.splice(i, 1);
  15. }
  16. return had;
  17. },
  18. forEach: function forEach(callback, context) {
  19. k.forEach(
  20. function (key, i) {
  21. callback.call(context, v[i], key, this);
  22. },
  23. this
  24. );
  25. },
  26. get: function get(key) {
  27. return contains(key) ? v[i] : void 0;
  28. },
  29. has: function has(key) {
  30. return contains(key);
  31. },
  32. set: function set(key, value) {
  33. v[contains(key) ? i : (k.push(key) - 1)] = value;
  34. return this;
  35. }
  36. };
  37. function contains(v) {
  38. i = k.indexOf(v);
  39. return -1 < i;
  40. }
  41. };
  42. }