97937c6d0a33146fa9f89a3a4d669772de49da0d5f6d520cfec570756898227d2dbe76f3958980f0712f43b42810860133b24e0cdfbec8e5ad44f6a90213fe 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. var __extends = this && this.t || function() {
  2. var extendStatics = function(t, r) {
  3. extendStatics = Object.setPrototypeOf || {
  4. __proto__: []
  5. } instanceof Array && function(t, r) {
  6. t.__proto__ = r;
  7. } || function(t, r) {
  8. for (var n in r) if (Object.prototype.hasOwnProperty.call(r, n)) t[n] = r[n];
  9. };
  10. return extendStatics(t, r);
  11. };
  12. return function(t, r) {
  13. if (typeof r !== "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
  14. extendStatics(t, r);
  15. function __() {
  16. this.constructor = t;
  17. }
  18. t.prototype = r === null ? Object.create(r) : (__.prototype = r.prototype, new __);
  19. };
  20. }();
  21. var __generator = this && this.i || function(t, r) {
  22. var n = {
  23. label: 0,
  24. sent: function() {
  25. if (a[0] & 1) throw a[1];
  26. return a[1];
  27. },
  28. trys: [],
  29. ops: []
  30. }, e, i, a, s;
  31. return s = {
  32. next: verb(0),
  33. throw: verb(1),
  34. return: verb(2)
  35. }, typeof Symbol === "function" && (s[Symbol.iterator] = function() {
  36. return this;
  37. }), s;
  38. function verb(t) {
  39. return function(r) {
  40. return step([ t, r ]);
  41. };
  42. }
  43. function step(s) {
  44. if (e) throw new TypeError("Generator is already executing.");
  45. while (n) try {
  46. if (e = 1, i && (a = s[0] & 2 ? i["return"] : s[0] ? i["throw"] || ((a = i["return"]) && a.call(i),
  47. 0) : i.next) && !(a = a.call(i, s[1])).done) return a;
  48. if (i = 0, a) s = [ s[0] & 2, a.value ];
  49. switch (s[0]) {
  50. case 0:
  51. case 1:
  52. a = s;
  53. break;
  54. case 4:
  55. n.label++;
  56. return {
  57. value: s[1],
  58. done: false
  59. };
  60. case 5:
  61. n.label++;
  62. i = s[1];
  63. s = [ 0 ];
  64. continue;
  65. case 7:
  66. s = n.ops.pop();
  67. n.trys.pop();
  68. continue;
  69. default:
  70. if (!(a = n.trys, a = a.length > 0 && a[a.length - 1]) && (s[0] === 6 || s[0] === 2)) {
  71. n = 0;
  72. continue;
  73. }
  74. if (s[0] === 3 && (!a || s[1] > a[0] && s[1] < a[3])) {
  75. n.label = s[1];
  76. break;
  77. }
  78. if (s[0] === 6 && n.label < a[1]) {
  79. n.label = a[1];
  80. a = s;
  81. break;
  82. }
  83. if (a && n.label < a[2]) {
  84. n.label = a[2];
  85. n.ops.push(s);
  86. break;
  87. }
  88. if (a[2]) n.ops.pop();
  89. n.trys.pop();
  90. continue;
  91. }
  92. s = r.call(t, n);
  93. } catch (t) {
  94. s = [ 6, t ];
  95. i = 0;
  96. } finally {
  97. e = a = 0;
  98. }
  99. if (s[0] & 5) throw s[1];
  100. return {
  101. value: s[0] ? s[1] : void 0,
  102. done: true
  103. };
  104. }
  105. };
  106. import { HashContainer, HashContainerIterator } from "./Base";
  107. import checkObject from "../../utils/checkObject";
  108. import { throwIteratorAccessError } from "../../utils/throwError";
  109. var HashMapIterator = function(t) {
  110. __extends(HashMapIterator, t);
  111. function HashMapIterator(r, n, e, i) {
  112. var a = t.call(this, r, n, i) || this;
  113. a.container = e;
  114. return a;
  115. }
  116. Object.defineProperty(HashMapIterator.prototype, "pointer", {
  117. get: function() {
  118. if (this.o === this.h) {
  119. throwIteratorAccessError();
  120. }
  121. var t = this;
  122. return new Proxy([], {
  123. get: function(r, n) {
  124. if (n === "0") return t.o.u; else if (n === "1") return t.o.p;
  125. },
  126. set: function(r, n, e) {
  127. if (n !== "1") {
  128. throw new TypeError("props must be 1");
  129. }
  130. t.o.p = e;
  131. return true;
  132. }
  133. });
  134. },
  135. enumerable: false,
  136. configurable: true
  137. });
  138. HashMapIterator.prototype.copy = function() {
  139. return new HashMapIterator(this.o, this.h, this.container, this.iteratorType);
  140. };
  141. return HashMapIterator;
  142. }(HashContainerIterator);
  143. var HashMap = function(t) {
  144. __extends(HashMap, t);
  145. function HashMap(r) {
  146. if (r === void 0) {
  147. r = [];
  148. }
  149. var n = t.call(this) || this;
  150. var e = n;
  151. r.forEach((function(t) {
  152. e.setElement(t[0], t[1]);
  153. }));
  154. return n;
  155. }
  156. HashMap.prototype.begin = function() {
  157. return new HashMapIterator(this.H, this.h, this);
  158. };
  159. HashMap.prototype.end = function() {
  160. return new HashMapIterator(this.h, this.h, this);
  161. };
  162. HashMap.prototype.rBegin = function() {
  163. return new HashMapIterator(this.l, this.h, this, 1);
  164. };
  165. HashMap.prototype.rEnd = function() {
  166. return new HashMapIterator(this.h, this.h, this, 1);
  167. };
  168. HashMap.prototype.front = function() {
  169. if (this.M === 0) return;
  170. return [ this.H.u, this.H.p ];
  171. };
  172. HashMap.prototype.back = function() {
  173. if (this.M === 0) return;
  174. return [ this.l.u, this.l.p ];
  175. };
  176. HashMap.prototype.setElement = function(t, r, n) {
  177. return this.v(t, r, n);
  178. };
  179. HashMap.prototype.getElementByKey = function(t, r) {
  180. if (r === undefined) r = checkObject(t);
  181. if (r) {
  182. var n = t[this.HASH_TAG];
  183. return n !== undefined ? this._[n].p : undefined;
  184. }
  185. var e = this.I[t];
  186. return e ? e.p : undefined;
  187. };
  188. HashMap.prototype.getElementByPos = function(t) {
  189. if (t < 0 || t > this.M - 1) {
  190. throw new RangeError;
  191. }
  192. var r = this.H;
  193. while (t--) {
  194. r = r.m;
  195. }
  196. return [ r.u, r.p ];
  197. };
  198. HashMap.prototype.find = function(t, r) {
  199. var n = this.g(t, r);
  200. return new HashMapIterator(n, this.h, this);
  201. };
  202. HashMap.prototype.forEach = function(t) {
  203. var r = 0;
  204. var n = this.H;
  205. while (n !== this.h) {
  206. t([ n.u, n.p ], r++, this);
  207. n = n.m;
  208. }
  209. };
  210. HashMap.prototype[Symbol.iterator] = function() {
  211. return function() {
  212. var t;
  213. return __generator(this, (function(r) {
  214. switch (r.label) {
  215. case 0:
  216. t = this.H;
  217. r.label = 1;
  218. case 1:
  219. if (!(t !== this.h)) return [ 3, 3 ];
  220. return [ 4, [ t.u, t.p ] ];
  221. case 2:
  222. r.sent();
  223. t = t.m;
  224. return [ 3, 1 ];
  225. case 3:
  226. return [ 2 ];
  227. }
  228. }));
  229. }.bind(this)();
  230. };
  231. return HashMap;
  232. }(HashContainer);
  233. export default HashMap;
  234. //# sourceMappingURL=HashMap.js.map