54046c8695cfd4fe116dcb07e22c997d10f249c42d7fce2f032cdf3c8fc567512dbcf116c031a0bc5d6cf758305b0b7a5e304dc40f9986e43796eb3a3e1812 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. exports.__esModule = true;
  3. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5. /**
  6. * @class Queue
  7. * @util
  8. */
  9. var Queue = function () {
  10. function Queue() {
  11. var initial = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  12. _classCallCheck(this, Queue);
  13. /**
  14. * Items collection.
  15. *
  16. * @type {Array}
  17. */
  18. this.items = initial;
  19. }
  20. /**
  21. * Add new item or items at the back of the queue.
  22. *
  23. * @param {*} items An item to add.
  24. */
  25. _createClass(Queue, [{
  26. key: "enqueue",
  27. value: function enqueue() {
  28. var _items;
  29. (_items = this.items).push.apply(_items, arguments);
  30. }
  31. /**
  32. * Remove the first element from the queue and returns it.
  33. *
  34. * @returns {*}
  35. */
  36. }, {
  37. key: "dequeue",
  38. value: function dequeue() {
  39. return this.items.shift();
  40. }
  41. /**
  42. * Return the first element from the queue (without modification queue stack).
  43. *
  44. * @returns {*}
  45. */
  46. }, {
  47. key: "peek",
  48. value: function peek() {
  49. return this.isEmpty() ? void 0 : this.items[0];
  50. }
  51. /**
  52. * Check if the queue is empty.
  53. *
  54. * @returns {Boolean}
  55. */
  56. }, {
  57. key: "isEmpty",
  58. value: function isEmpty() {
  59. return !this.size();
  60. }
  61. /**
  62. * Return number of elements in the queue.
  63. *
  64. * @returns {Number}
  65. */
  66. }, {
  67. key: "size",
  68. value: function size() {
  69. return this.items.length;
  70. }
  71. }]);
  72. return Queue;
  73. }();
  74. exports.default = Queue;