RandomIterator.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. import { ContainerIterator } from "../../ContainerBase";
  22. var RandomIterator = function(t) {
  23. __extends(RandomIterator, t);
  24. function RandomIterator(r, n, e, i, o) {
  25. var a = t.call(this, o) || this;
  26. a.D = r;
  27. a.I = n;
  28. a.g = e;
  29. a.R = i;
  30. if (a.iteratorType === 0) {
  31. a.pre = function() {
  32. if (this.D === 0) {
  33. throw new RangeError("Random iterator access denied!");
  34. }
  35. this.D -= 1;
  36. return this;
  37. };
  38. a.next = function() {
  39. if (this.D === this.I()) {
  40. throw new RangeError("Random Iterator access denied!");
  41. }
  42. this.D += 1;
  43. return this;
  44. };
  45. } else {
  46. a.pre = function() {
  47. if (this.D === this.I() - 1) {
  48. throw new RangeError("Random iterator access denied!");
  49. }
  50. this.D += 1;
  51. return this;
  52. };
  53. a.next = function() {
  54. if (this.D === -1) {
  55. throw new RangeError("Random iterator access denied!");
  56. }
  57. this.D -= 1;
  58. return this;
  59. };
  60. }
  61. return a;
  62. }
  63. Object.defineProperty(RandomIterator.prototype, "pointer", {
  64. get: function() {
  65. if (this.D < 0 || this.D > this.I() - 1) {
  66. throw new RangeError;
  67. }
  68. return this.g(this.D);
  69. },
  70. set: function(t) {
  71. if (this.D < 0 || this.D > this.I() - 1) {
  72. throw new RangeError;
  73. }
  74. this.R(this.D, t);
  75. },
  76. enumerable: false,
  77. configurable: true
  78. });
  79. RandomIterator.prototype.equals = function(t) {
  80. return this.D === t.D;
  81. };
  82. return RandomIterator;
  83. }(ContainerIterator);
  84. export { RandomIterator };