TreeIterator.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. "use strict";
  2. Object.defineProperty(exports, "t", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _ContainerBase = require("../../ContainerBase");
  7. class TreeIterator extends _ContainerBase.ContainerIterator {
  8. constructor(t, e, r) {
  9. super(r);
  10. this.I = t;
  11. this.S = e;
  12. if (this.iteratorType === 0) {
  13. this.pre = function() {
  14. if (this.I === this.S.U) {
  15. throw new RangeError("Tree iterator access denied!");
  16. }
  17. this.I = this.I.pre();
  18. return this;
  19. };
  20. this.next = function() {
  21. if (this.I === this.S) {
  22. throw new RangeError("Tree iterator access denied!");
  23. }
  24. this.I = this.I.next();
  25. return this;
  26. };
  27. } else {
  28. this.pre = function() {
  29. if (this.I === this.S.J) {
  30. throw new RangeError("Tree iterator access denied!");
  31. }
  32. this.I = this.I.next();
  33. return this;
  34. };
  35. this.next = function() {
  36. if (this.I === this.S) {
  37. throw new RangeError("Tree iterator access denied!");
  38. }
  39. this.I = this.I.pre();
  40. return this;
  41. };
  42. }
  43. }
  44. get index() {
  45. let t = this.I;
  46. const e = this.S.tt;
  47. if (t === this.S) {
  48. if (e) {
  49. return e.et - 1;
  50. }
  51. return 0;
  52. }
  53. let r = 0;
  54. if (t.U) {
  55. r += t.U.et;
  56. }
  57. while (t !== e) {
  58. const e = t.tt;
  59. if (t === e.J) {
  60. r += 1;
  61. if (e.U) {
  62. r += e.U.et;
  63. }
  64. }
  65. t = e;
  66. }
  67. return r;
  68. }
  69. equals(t) {
  70. return this.I === t.I;
  71. }
  72. }
  73. var _default = TreeIterator;
  74. exports.default = _default;