48315ce95a4e821c33bf7a198cbfcc2ba9d079d6afe1afc72ecaefb01547a08daabf87c35904d2bf9a29b5b2b6c06013eee63e1da1e9fc2730c060a2c5466e 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. var __extends = this && this.t || function() {
  2. var extendStatics = function(i, r) {
  3. extendStatics = Object.setPrototypeOf || {
  4. __proto__: []
  5. } instanceof Array && function(i, r) {
  6. i.__proto__ = r;
  7. } || function(i, r) {
  8. for (var t in r) if (Object.prototype.hasOwnProperty.call(r, t)) i[t] = r[t];
  9. };
  10. return extendStatics(i, r);
  11. };
  12. return function(i, r) {
  13. if (typeof r !== "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
  14. extendStatics(i, r);
  15. function __() {
  16. this.constructor = i;
  17. }
  18. i.prototype = r === null ? Object.create(r) : (__.prototype = r.prototype, new __);
  19. };
  20. }();
  21. var __read = this && this.q || function(i, r) {
  22. var t = typeof Symbol === "function" && i[Symbol.iterator];
  23. if (!t) return i;
  24. var e = t.call(i), n, u = [], s;
  25. try {
  26. while ((r === void 0 || r-- > 0) && !(n = e.next()).done) u.push(n.value);
  27. } catch (i) {
  28. s = {
  29. error: i
  30. };
  31. } finally {
  32. try {
  33. if (n && !n.done && (t = e["return"])) t.call(e);
  34. } finally {
  35. if (s) throw s.error;
  36. }
  37. }
  38. return u;
  39. };
  40. var __spreadArray = this && this.D || function(i, r, t) {
  41. if (t || arguments.length === 2) for (var e = 0, n = r.length, u; e < n; e++) {
  42. if (u || !(e in r)) {
  43. if (!u) u = Array.prototype.slice.call(r, 0, e);
  44. u[e] = r[e];
  45. }
  46. }
  47. return i.concat(u || Array.prototype.slice.call(r));
  48. };
  49. import { Base } from "../ContainerBase";
  50. var PriorityQueue = function(i) {
  51. __extends(PriorityQueue, i);
  52. function PriorityQueue(r, t, e) {
  53. if (r === void 0) {
  54. r = [];
  55. }
  56. if (t === void 0) {
  57. t = function(i, r) {
  58. if (i > r) return -1;
  59. if (i < r) return 1;
  60. return 0;
  61. };
  62. }
  63. if (e === void 0) {
  64. e = true;
  65. }
  66. var n = i.call(this) || this;
  67. n.$ = t;
  68. if (Array.isArray(r)) {
  69. n.ii = e ? __spreadArray([], __read(r), false) : r;
  70. } else {
  71. n.ii = [];
  72. var u = n;
  73. r.forEach((function(i) {
  74. u.ii.push(i);
  75. }));
  76. }
  77. n.M = n.ii.length;
  78. var s = n.M >> 1;
  79. for (var o = n.M - 1 >> 1; o >= 0; --o) {
  80. n.ri(o, s);
  81. }
  82. return n;
  83. }
  84. PriorityQueue.prototype.ti = function(i) {
  85. var r = this.ii[i];
  86. while (i > 0) {
  87. var t = i - 1 >> 1;
  88. var e = this.ii[t];
  89. if (this.$(e, r) <= 0) break;
  90. this.ii[i] = e;
  91. i = t;
  92. }
  93. this.ii[i] = r;
  94. };
  95. PriorityQueue.prototype.ri = function(i, r) {
  96. var t = this.ii[i];
  97. while (i < r) {
  98. var e = i << 1 | 1;
  99. var n = e + 1;
  100. var u = this.ii[e];
  101. if (n < this.M && this.$(u, this.ii[n]) > 0) {
  102. e = n;
  103. u = this.ii[n];
  104. }
  105. if (this.$(u, t) >= 0) break;
  106. this.ii[i] = u;
  107. i = e;
  108. }
  109. this.ii[i] = t;
  110. };
  111. PriorityQueue.prototype.clear = function() {
  112. this.M = 0;
  113. this.ii.length = 0;
  114. };
  115. PriorityQueue.prototype.push = function(i) {
  116. this.ii.push(i);
  117. this.ti(this.M);
  118. this.M += 1;
  119. };
  120. PriorityQueue.prototype.pop = function() {
  121. if (this.M === 0) return;
  122. var i = this.ii[0];
  123. var r = this.ii.pop();
  124. this.M -= 1;
  125. if (this.M) {
  126. this.ii[0] = r;
  127. this.ri(0, this.M >> 1);
  128. }
  129. return i;
  130. };
  131. PriorityQueue.prototype.top = function() {
  132. return this.ii[0];
  133. };
  134. PriorityQueue.prototype.find = function(i) {
  135. return this.ii.indexOf(i) >= 0;
  136. };
  137. PriorityQueue.prototype.remove = function(i) {
  138. var r = this.ii.indexOf(i);
  139. if (r < 0) return false;
  140. if (r === 0) {
  141. this.pop();
  142. } else if (r === this.M - 1) {
  143. this.ii.pop();
  144. this.M -= 1;
  145. } else {
  146. this.ii.splice(r, 1, this.ii.pop());
  147. this.M -= 1;
  148. this.ti(r);
  149. this.ri(r, this.M >> 1);
  150. }
  151. return true;
  152. };
  153. PriorityQueue.prototype.updateItem = function(i) {
  154. var r = this.ii.indexOf(i);
  155. if (r < 0) return false;
  156. this.ti(r);
  157. this.ri(r, this.M >> 1);
  158. return true;
  159. };
  160. PriorityQueue.prototype.toArray = function() {
  161. return __spreadArray([], __read(this.ii), false);
  162. };
  163. return PriorityQueue;
  164. }(Base);
  165. export default PriorityQueue;
  166. //# sourceMappingURL=PriorityQueue.js.map