76292d1c652cda5fd2affbcc0bb9ca6cba8f8db6e519ae9c6a9671ce43923692bacacc24f2b99e145b0c5b55179e77bef0e46cb6453f7b534af7ea6e6995b0 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 e in r) if (Object.prototype.hasOwnProperty.call(r, e)) t[e] = r[e];
  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 e = {
  23. label: 0,
  24. sent: function() {
  25. if (o[0] & 1) throw o[1];
  26. return o[1];
  27. },
  28. trys: [],
  29. ops: []
  30. }, n, i, o, u;
  31. return u = {
  32. next: verb(0),
  33. throw: verb(1),
  34. return: verb(2)
  35. }, typeof Symbol === "function" && (u[Symbol.iterator] = function() {
  36. return this;
  37. }), u;
  38. function verb(t) {
  39. return function(r) {
  40. return step([ t, r ]);
  41. };
  42. }
  43. function step(u) {
  44. if (n) throw new TypeError("Generator is already executing.");
  45. while (e) try {
  46. if (n = 1, i && (o = u[0] & 2 ? i["return"] : u[0] ? i["throw"] || ((o = i["return"]) && o.call(i),
  47. 0) : i.next) && !(o = o.call(i, u[1])).done) return o;
  48. if (i = 0, o) u = [ u[0] & 2, o.value ];
  49. switch (u[0]) {
  50. case 0:
  51. case 1:
  52. o = u;
  53. break;
  54. case 4:
  55. e.label++;
  56. return {
  57. value: u[1],
  58. done: false
  59. };
  60. case 5:
  61. e.label++;
  62. i = u[1];
  63. u = [ 0 ];
  64. continue;
  65. case 7:
  66. u = e.ops.pop();
  67. e.trys.pop();
  68. continue;
  69. default:
  70. if (!(o = e.trys, o = o.length > 0 && o[o.length - 1]) && (u[0] === 6 || u[0] === 2)) {
  71. e = 0;
  72. continue;
  73. }
  74. if (u[0] === 3 && (!o || u[1] > o[0] && u[1] < o[3])) {
  75. e.label = u[1];
  76. break;
  77. }
  78. if (u[0] === 6 && e.label < o[1]) {
  79. e.label = o[1];
  80. o = u;
  81. break;
  82. }
  83. if (o && e.label < o[2]) {
  84. e.label = o[2];
  85. e.ops.push(u);
  86. break;
  87. }
  88. if (o[2]) e.ops.pop();
  89. e.trys.pop();
  90. continue;
  91. }
  92. u = r.call(t, e);
  93. } catch (t) {
  94. u = [ 6, t ];
  95. i = 0;
  96. } finally {
  97. n = o = 0;
  98. }
  99. if (u[0] & 5) throw u[1];
  100. return {
  101. value: u[0] ? u[1] : void 0,
  102. done: true
  103. };
  104. }
  105. };
  106. var __read = this && this.q || function(t, r) {
  107. var e = typeof Symbol === "function" && t[Symbol.iterator];
  108. if (!e) return t;
  109. var n = e.call(t), i, o = [], u;
  110. try {
  111. while ((r === void 0 || r-- > 0) && !(i = n.next()).done) o.push(i.value);
  112. } catch (t) {
  113. u = {
  114. error: t
  115. };
  116. } finally {
  117. try {
  118. if (i && !i.done && (e = n["return"])) e.call(n);
  119. } finally {
  120. if (u) throw u.error;
  121. }
  122. }
  123. return o;
  124. };
  125. var __spreadArray = this && this.D || function(t, r, e) {
  126. if (e || arguments.length === 2) for (var n = 0, i = r.length, o; n < i; n++) {
  127. if (o || !(n in r)) {
  128. if (!o) o = Array.prototype.slice.call(r, 0, n);
  129. o[n] = r[n];
  130. }
  131. }
  132. return t.concat(o || Array.prototype.slice.call(r));
  133. };
  134. var __values = this && this.V || function(t) {
  135. var r = typeof Symbol === "function" && Symbol.iterator, e = r && t[r], n = 0;
  136. if (e) return e.call(t);
  137. if (t && typeof t.length === "number") return {
  138. next: function() {
  139. if (t && n >= t.length) t = void 0;
  140. return {
  141. value: t && t[n++],
  142. done: !t
  143. };
  144. }
  145. };
  146. throw new TypeError(r ? "Object is not iterable." : "Symbol.iterator is not defined.");
  147. };
  148. import SequentialContainer from "./Base";
  149. import { RandomIterator } from "./Base/RandomIterator";
  150. var VectorIterator = function(t) {
  151. __extends(VectorIterator, t);
  152. function VectorIterator(r, e, n) {
  153. var i = t.call(this, r, n) || this;
  154. i.container = e;
  155. return i;
  156. }
  157. VectorIterator.prototype.copy = function() {
  158. return new VectorIterator(this.o, this.container, this.iteratorType);
  159. };
  160. return VectorIterator;
  161. }(RandomIterator);
  162. var Vector = function(t) {
  163. __extends(Vector, t);
  164. function Vector(r, e) {
  165. if (r === void 0) {
  166. r = [];
  167. }
  168. if (e === void 0) {
  169. e = true;
  170. }
  171. var n = t.call(this) || this;
  172. if (Array.isArray(r)) {
  173. n.J = e ? __spreadArray([], __read(r), false) : r;
  174. n.M = r.length;
  175. } else {
  176. n.J = [];
  177. var i = n;
  178. r.forEach((function(t) {
  179. i.pushBack(t);
  180. }));
  181. }
  182. return n;
  183. }
  184. Vector.prototype.clear = function() {
  185. this.M = 0;
  186. this.J.length = 0;
  187. };
  188. Vector.prototype.begin = function() {
  189. return new VectorIterator(0, this);
  190. };
  191. Vector.prototype.end = function() {
  192. return new VectorIterator(this.M, this);
  193. };
  194. Vector.prototype.rBegin = function() {
  195. return new VectorIterator(this.M - 1, this, 1);
  196. };
  197. Vector.prototype.rEnd = function() {
  198. return new VectorIterator(-1, this, 1);
  199. };
  200. Vector.prototype.front = function() {
  201. return this.J[0];
  202. };
  203. Vector.prototype.back = function() {
  204. return this.J[this.M - 1];
  205. };
  206. Vector.prototype.getElementByPos = function(t) {
  207. if (t < 0 || t > this.M - 1) {
  208. throw new RangeError;
  209. }
  210. return this.J[t];
  211. };
  212. Vector.prototype.eraseElementByPos = function(t) {
  213. if (t < 0 || t > this.M - 1) {
  214. throw new RangeError;
  215. }
  216. this.J.splice(t, 1);
  217. this.M -= 1;
  218. return this.M;
  219. };
  220. Vector.prototype.eraseElementByValue = function(t) {
  221. var r = 0;
  222. for (var e = 0; e < this.M; ++e) {
  223. if (this.J[e] !== t) {
  224. this.J[r++] = this.J[e];
  225. }
  226. }
  227. this.M = this.J.length = r;
  228. return this.M;
  229. };
  230. Vector.prototype.eraseElementByIterator = function(t) {
  231. var r = t.o;
  232. t = t.next();
  233. this.eraseElementByPos(r);
  234. return t;
  235. };
  236. Vector.prototype.pushBack = function(t) {
  237. this.J.push(t);
  238. this.M += 1;
  239. return this.M;
  240. };
  241. Vector.prototype.popBack = function() {
  242. if (this.M === 0) return;
  243. this.M -= 1;
  244. return this.J.pop();
  245. };
  246. Vector.prototype.setElementByPos = function(t, r) {
  247. if (t < 0 || t > this.M - 1) {
  248. throw new RangeError;
  249. }
  250. this.J[t] = r;
  251. };
  252. Vector.prototype.insert = function(t, r, e) {
  253. var n;
  254. if (e === void 0) {
  255. e = 1;
  256. }
  257. if (t < 0 || t > this.M) {
  258. throw new RangeError;
  259. }
  260. (n = this.J).splice.apply(n, __spreadArray([ t, 0 ], __read(new Array(e).fill(r)), false));
  261. this.M += e;
  262. return this.M;
  263. };
  264. Vector.prototype.find = function(t) {
  265. for (var r = 0; r < this.M; ++r) {
  266. if (this.J[r] === t) {
  267. return new VectorIterator(r, this);
  268. }
  269. }
  270. return this.end();
  271. };
  272. Vector.prototype.reverse = function() {
  273. this.J.reverse();
  274. };
  275. Vector.prototype.unique = function() {
  276. var t = 1;
  277. for (var r = 1; r < this.M; ++r) {
  278. if (this.J[r] !== this.J[r - 1]) {
  279. this.J[t++] = this.J[r];
  280. }
  281. }
  282. this.M = this.J.length = t;
  283. return this.M;
  284. };
  285. Vector.prototype.sort = function(t) {
  286. this.J.sort(t);
  287. };
  288. Vector.prototype.forEach = function(t) {
  289. for (var r = 0; r < this.M; ++r) {
  290. t(this.J[r], r, this);
  291. }
  292. };
  293. Vector.prototype[Symbol.iterator] = function() {
  294. return function() {
  295. return __generator(this, (function(t) {
  296. switch (t.label) {
  297. case 0:
  298. return [ 5, __values(this.J) ];
  299. case 1:
  300. t.sent();
  301. return [ 2 ];
  302. }
  303. }));
  304. }.bind(this)();
  305. };
  306. return Vector;
  307. }(SequentialContainer);
  308. export default Vector;
  309. //# sourceMappingURL=Vector.js.map