PrioritizedList.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.PrioritizedList = void 0;
  4. var PrioritizedList = (function () {
  5. function PrioritizedList() {
  6. this.items = [];
  7. this.items = [];
  8. }
  9. PrioritizedList.prototype[Symbol.iterator] = function () {
  10. var i = 0;
  11. var items = this.items;
  12. return {
  13. next: function () {
  14. return { value: items[i++], done: (i > items.length) };
  15. }
  16. };
  17. };
  18. PrioritizedList.prototype.add = function (item, priority) {
  19. if (priority === void 0) { priority = PrioritizedList.DEFAULTPRIORITY; }
  20. var i = this.items.length;
  21. do {
  22. i--;
  23. } while (i >= 0 && priority < this.items[i].priority);
  24. this.items.splice(i + 1, 0, { item: item, priority: priority });
  25. return item;
  26. };
  27. PrioritizedList.prototype.remove = function (item) {
  28. var i = this.items.length;
  29. do {
  30. i--;
  31. } while (i >= 0 && this.items[i].item !== item);
  32. if (i >= 0) {
  33. this.items.splice(i, 1);
  34. }
  35. };
  36. PrioritizedList.DEFAULTPRIORITY = 5;
  37. return PrioritizedList;
  38. }());
  39. exports.PrioritizedList = PrioritizedList;
  40. //# sourceMappingURL=PrioritizedList.js.map