OrderedMap.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. var __extends = this && this.t || function() {
  2. var extendStatics = function(r, e) {
  3. extendStatics = Object.setPrototypeOf || {
  4. __proto__: []
  5. } instanceof Array && function(r, e) {
  6. r.__proto__ = e;
  7. } || function(r, e) {
  8. for (var t in e) if (Object.prototype.hasOwnProperty.call(e, t)) r[t] = e[t];
  9. };
  10. return extendStatics(r, e);
  11. };
  12. return function(r, e) {
  13. if (typeof e !== "function" && e !== null) throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
  14. extendStatics(r, e);
  15. function __() {
  16. this.constructor = r;
  17. }
  18. r.prototype = e === null ? Object.create(e) : (__.prototype = e.prototype, new __);
  19. };
  20. }();
  21. var __generator = this && this.i || function(r, e) {
  22. var t = {
  23. label: 0,
  24. sent: function() {
  25. if (a[0] & 1) throw a[1];
  26. return a[1];
  27. },
  28. trys: [],
  29. ops: []
  30. }, n, i, a, o;
  31. return o = {
  32. next: verb(0),
  33. throw: verb(1),
  34. return: verb(2)
  35. }, typeof Symbol === "function" && (o[Symbol.iterator] = function() {
  36. return this;
  37. }), o;
  38. function verb(r) {
  39. return function(e) {
  40. return step([ r, e ]);
  41. };
  42. }
  43. function step(o) {
  44. if (n) throw new TypeError("Generator is already executing.");
  45. while (t) try {
  46. if (n = 1, i && (a = o[0] & 2 ? i["return"] : o[0] ? i["throw"] || ((a = i["return"]) && a.call(i),
  47. 0) : i.next) && !(a = a.call(i, o[1])).done) return a;
  48. if (i = 0, a) o = [ o[0] & 2, a.value ];
  49. switch (o[0]) {
  50. case 0:
  51. case 1:
  52. a = o;
  53. break;
  54. case 4:
  55. t.label++;
  56. return {
  57. value: o[1],
  58. done: false
  59. };
  60. case 5:
  61. t.label++;
  62. i = o[1];
  63. o = [ 0 ];
  64. continue;
  65. case 7:
  66. o = t.ops.pop();
  67. t.trys.pop();
  68. continue;
  69. default:
  70. if (!(a = t.trys, a = a.length > 0 && a[a.length - 1]) && (o[0] === 6 || o[0] === 2)) {
  71. t = 0;
  72. continue;
  73. }
  74. if (o[0] === 3 && (!a || o[1] > a[0] && o[1] < a[3])) {
  75. t.label = o[1];
  76. break;
  77. }
  78. if (o[0] === 6 && t.label < a[1]) {
  79. t.label = a[1];
  80. a = o;
  81. break;
  82. }
  83. if (a && t.label < a[2]) {
  84. t.label = a[2];
  85. t.ops.push(o);
  86. break;
  87. }
  88. if (a[2]) t.ops.pop();
  89. t.trys.pop();
  90. continue;
  91. }
  92. o = e.call(r, t);
  93. } catch (r) {
  94. o = [ 6, r ];
  95. i = 0;
  96. } finally {
  97. n = a = 0;
  98. }
  99. if (o[0] & 5) throw o[1];
  100. return {
  101. value: o[0] ? o[1] : void 0,
  102. done: true
  103. };
  104. }
  105. };
  106. var __read = this && this._ || function(r, e) {
  107. var t = typeof Symbol === "function" && r[Symbol.iterator];
  108. if (!t) return r;
  109. var n = t.call(r), i, a = [], o;
  110. try {
  111. while ((e === void 0 || e-- > 0) && !(i = n.next()).done) a.push(i.value);
  112. } catch (r) {
  113. o = {
  114. error: r
  115. };
  116. } finally {
  117. try {
  118. if (i && !i.done && (t = n["return"])) t.call(n);
  119. } finally {
  120. if (o) throw o.error;
  121. }
  122. }
  123. return a;
  124. };
  125. var __values = this && this.u || function(r) {
  126. var e = typeof Symbol === "function" && Symbol.iterator, t = e && r[e], n = 0;
  127. if (t) return t.call(r);
  128. if (r && typeof r.length === "number") return {
  129. next: function() {
  130. if (r && n >= r.length) r = void 0;
  131. return {
  132. value: r && r[n++],
  133. done: !r
  134. };
  135. }
  136. };
  137. throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
  138. };
  139. import TreeContainer from "./Base";
  140. import TreeIterator from "./Base/TreeIterator";
  141. var OrderedMapIterator = function(r) {
  142. __extends(OrderedMapIterator, r);
  143. function OrderedMapIterator() {
  144. return r !== null && r.apply(this, arguments) || this;
  145. }
  146. Object.defineProperty(OrderedMapIterator.prototype, "pointer", {
  147. get: function() {
  148. var r = this;
  149. if (this.D === this.J) {
  150. throw new RangeError("OrderedMap iterator access denied");
  151. }
  152. return new Proxy([], {
  153. get: function(e, t) {
  154. if (t === "0") return r.D.W; else if (t === "1") return r.D.L;
  155. },
  156. set: function(e, t, n) {
  157. if (t !== "1") {
  158. throw new TypeError("props must be 1");
  159. }
  160. r.D.L = n;
  161. return true;
  162. }
  163. });
  164. },
  165. enumerable: false,
  166. configurable: true
  167. });
  168. OrderedMapIterator.prototype.copy = function() {
  169. return new OrderedMapIterator(this.D, this.J, this.iteratorType);
  170. };
  171. return OrderedMapIterator;
  172. }(TreeIterator);
  173. export { OrderedMapIterator };
  174. var OrderedMap = function(r) {
  175. __extends(OrderedMap, r);
  176. function OrderedMap(e, t, n) {
  177. if (e === void 0) {
  178. e = [];
  179. }
  180. var i = r.call(this, t, n) || this;
  181. i.X = function(r) {
  182. return __generator(this, (function(e) {
  183. switch (e.label) {
  184. case 0:
  185. if (r === undefined) return [ 2 ];
  186. return [ 5, __values(this.X(r.Y)) ];
  187. case 1:
  188. e.sent();
  189. return [ 4, [ r.W, r.L ] ];
  190. case 2:
  191. e.sent();
  192. return [ 5, __values(this.X(r.Z)) ];
  193. case 3:
  194. e.sent();
  195. return [ 2 ];
  196. }
  197. }));
  198. };
  199. e.forEach((function(r) {
  200. var e = __read(r, 2), t = e[0], n = e[1];
  201. return i.setElement(t, n);
  202. }));
  203. return i;
  204. }
  205. OrderedMap.prototype.begin = function() {
  206. return new OrderedMapIterator(this.J.Y || this.J, this.J);
  207. };
  208. OrderedMap.prototype.end = function() {
  209. return new OrderedMapIterator(this.J, this.J);
  210. };
  211. OrderedMap.prototype.rBegin = function() {
  212. return new OrderedMapIterator(this.J.Z || this.J, this.J, 1);
  213. };
  214. OrderedMap.prototype.rEnd = function() {
  215. return new OrderedMapIterator(this.J, this.J, 1);
  216. };
  217. OrderedMap.prototype.front = function() {
  218. if (!this.o) return undefined;
  219. var r = this.J.Y;
  220. return [ r.W, r.L ];
  221. };
  222. OrderedMap.prototype.back = function() {
  223. if (!this.o) return undefined;
  224. var r = this.J.Z;
  225. return [ r.W, r.L ];
  226. };
  227. OrderedMap.prototype.forEach = function(r) {
  228. var e, t;
  229. var n = 0;
  230. try {
  231. for (var i = __values(this), a = i.next(); !a.done; a = i.next()) {
  232. var o = a.value;
  233. r(o, n++);
  234. }
  235. } catch (r) {
  236. e = {
  237. error: r
  238. };
  239. } finally {
  240. try {
  241. if (a && !a.done && (t = i.return)) t.call(i);
  242. } finally {
  243. if (e) throw e.error;
  244. }
  245. }
  246. };
  247. OrderedMap.prototype.lowerBound = function(r) {
  248. var e = this.$(this.rr, r);
  249. return new OrderedMapIterator(e, this.J);
  250. };
  251. OrderedMap.prototype.upperBound = function(r) {
  252. var e = this.er(this.rr, r);
  253. return new OrderedMapIterator(e, this.J);
  254. };
  255. OrderedMap.prototype.reverseLowerBound = function(r) {
  256. var e = this.tr(this.rr, r);
  257. return new OrderedMapIterator(e, this.J);
  258. };
  259. OrderedMap.prototype.reverseUpperBound = function(r) {
  260. var e = this.nr(this.rr, r);
  261. return new OrderedMapIterator(e, this.J);
  262. };
  263. OrderedMap.prototype.setElement = function(r, e, t) {
  264. this.ir(r, e, t);
  265. };
  266. OrderedMap.prototype.find = function(r) {
  267. var e = this.ar(this.rr, r);
  268. if (e !== undefined) {
  269. return new OrderedMapIterator(e, this.J);
  270. }
  271. return this.end();
  272. };
  273. OrderedMap.prototype.getElementByKey = function(r) {
  274. var e = this.ar(this.rr, r);
  275. return e ? e.L : undefined;
  276. };
  277. OrderedMap.prototype.getElementByPos = function(r) {
  278. var e, t;
  279. if (r < 0 || r > this.o - 1) {
  280. throw new RangeError;
  281. }
  282. var n;
  283. var i = 0;
  284. try {
  285. for (var a = __values(this), o = a.next(); !o.done; o = a.next()) {
  286. var u = o.value;
  287. if (i === r) {
  288. n = u;
  289. break;
  290. }
  291. i += 1;
  292. }
  293. } catch (r) {
  294. e = {
  295. error: r
  296. };
  297. } finally {
  298. try {
  299. if (o && !o.done && (t = a.return)) t.call(a);
  300. } finally {
  301. if (e) throw e.error;
  302. }
  303. }
  304. return n;
  305. };
  306. OrderedMap.prototype.union = function(r) {
  307. var e = this;
  308. r.forEach((function(r) {
  309. var t = __read(r, 2), n = t[0], i = t[1];
  310. return e.setElement(n, i);
  311. }));
  312. };
  313. OrderedMap.prototype[Symbol.iterator] = function() {
  314. return this.X(this.rr);
  315. };
  316. return OrderedMap;
  317. }(TreeContainer);
  318. export default OrderedMap;