TreeNode.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. var __extends = this && this.t || function() {
  2. var extendStatics = function(e, n) {
  3. extendStatics = Object.setPrototypeOf || {
  4. __proto__: []
  5. } instanceof Array && function(e, n) {
  6. e.__proto__ = n;
  7. } || function(e, n) {
  8. for (var i in n) if (Object.prototype.hasOwnProperty.call(n, i)) e[i] = n[i];
  9. };
  10. return extendStatics(e, n);
  11. };
  12. return function(e, n) {
  13. if (typeof n !== "function" && n !== null) throw new TypeError("Class extends value " + String(n) + " is not a constructor or null");
  14. extendStatics(e, n);
  15. function __() {
  16. this.constructor = e;
  17. }
  18. e.prototype = n === null ? Object.create(n) : (__.prototype = n.prototype, new __);
  19. };
  20. }();
  21. var TreeNode = function() {
  22. function TreeNode(e, n) {
  23. this.ee = 1;
  24. this.W = undefined;
  25. this.L = undefined;
  26. this.Y = undefined;
  27. this.Z = undefined;
  28. this.tt = undefined;
  29. this.W = e;
  30. this.L = n;
  31. }
  32. TreeNode.prototype.pre = function() {
  33. var e = this;
  34. if (e.ee === 1 && e.tt.tt === e) {
  35. e = e.Z;
  36. } else if (e.Y) {
  37. e = e.Y;
  38. while (e.Z) {
  39. e = e.Z;
  40. }
  41. } else {
  42. var n = e.tt;
  43. while (n.Y === e) {
  44. e = n;
  45. n = e.tt;
  46. }
  47. e = n;
  48. }
  49. return e;
  50. };
  51. TreeNode.prototype.next = function() {
  52. var e = this;
  53. if (e.Z) {
  54. e = e.Z;
  55. while (e.Y) {
  56. e = e.Y;
  57. }
  58. return e;
  59. } else {
  60. var n = e.tt;
  61. while (n.Z === e) {
  62. e = n;
  63. n = e.tt;
  64. }
  65. if (e.Z !== n) {
  66. return n;
  67. } else return e;
  68. }
  69. };
  70. TreeNode.prototype.rotateLeft = function() {
  71. var e = this.tt;
  72. var n = this.Z;
  73. var i = n.Y;
  74. if (e.tt === this) e.tt = n; else if (e.Y === this) e.Y = n; else e.Z = n;
  75. n.tt = e;
  76. n.Y = this;
  77. this.tt = n;
  78. this.Z = i;
  79. if (i) i.tt = this;
  80. return n;
  81. };
  82. TreeNode.prototype.rotateRight = function() {
  83. var e = this.tt;
  84. var n = this.Y;
  85. var i = n.Z;
  86. if (e.tt === this) e.tt = n; else if (e.Y === this) e.Y = n; else e.Z = n;
  87. n.tt = e;
  88. n.Z = this;
  89. this.tt = n;
  90. this.Y = i;
  91. if (i) i.tt = this;
  92. return n;
  93. };
  94. return TreeNode;
  95. }();
  96. export { TreeNode };
  97. var TreeNodeEnableIndex = function(e) {
  98. __extends(TreeNodeEnableIndex, e);
  99. function TreeNodeEnableIndex() {
  100. var n = e !== null && e.apply(this, arguments) || this;
  101. n.Y = undefined;
  102. n.Z = undefined;
  103. n.tt = undefined;
  104. n.rt = 1;
  105. return n;
  106. }
  107. TreeNodeEnableIndex.prototype.rotateLeft = function() {
  108. var n = e.prototype.rotateLeft.call(this);
  109. this.recount();
  110. n.recount();
  111. return n;
  112. };
  113. TreeNodeEnableIndex.prototype.rotateRight = function() {
  114. var n = e.prototype.rotateRight.call(this);
  115. this.recount();
  116. n.recount();
  117. return n;
  118. };
  119. TreeNodeEnableIndex.prototype.recount = function() {
  120. this.rt = 1;
  121. if (this.Y) this.rt += this.Y.rt;
  122. if (this.Z) this.rt += this.Z.rt;
  123. };
  124. return TreeNodeEnableIndex;
  125. }(TreeNode);
  126. export { TreeNodeEnableIndex };