TreeIterator.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. import { ContainerIterator } from "../../ContainerBase";
  22. var TreeIterator = function(t) {
  23. __extends(TreeIterator, t);
  24. function TreeIterator(r, e, n) {
  25. var i = t.call(this, n) || this;
  26. i.D = r;
  27. i.J = e;
  28. if (i.iteratorType === 0) {
  29. i.pre = function() {
  30. if (this.D === this.J.Y) {
  31. throw new RangeError("Tree iterator access denied!");
  32. }
  33. this.D = this.D.pre();
  34. return this;
  35. };
  36. i.next = function() {
  37. if (this.D === this.J) {
  38. throw new RangeError("Tree iterator access denied!");
  39. }
  40. this.D = this.D.next();
  41. return this;
  42. };
  43. } else {
  44. i.pre = function() {
  45. if (this.D === this.J.Z) {
  46. throw new RangeError("Tree iterator access denied!");
  47. }
  48. this.D = this.D.next();
  49. return this;
  50. };
  51. i.next = function() {
  52. if (this.D === this.J) {
  53. throw new RangeError("Tree iterator access denied!");
  54. }
  55. this.D = this.D.pre();
  56. return this;
  57. };
  58. }
  59. return i;
  60. }
  61. Object.defineProperty(TreeIterator.prototype, "index", {
  62. get: function() {
  63. var t = this.D;
  64. var r = this.J.tt;
  65. if (t === this.J) {
  66. if (r) {
  67. return r.rt - 1;
  68. }
  69. return 0;
  70. }
  71. var e = 0;
  72. if (t.Y) {
  73. e += t.Y.rt;
  74. }
  75. while (t !== r) {
  76. var n = t.tt;
  77. if (t === n.Z) {
  78. e += 1;
  79. if (n.Y) {
  80. e += n.Y.rt;
  81. }
  82. }
  83. t = n;
  84. }
  85. return e;
  86. },
  87. enumerable: false,
  88. configurable: true
  89. });
  90. TreeIterator.prototype.equals = function(t) {
  91. return this.D === t.D;
  92. };
  93. return TreeIterator;
  94. }(ContainerIterator);
  95. export default TreeIterator;