|
59 | 59 | return new Node(key, value, null, null, true); |
60 | 60 | } |
61 | 61 | if (node.getKey() > key) { |
62 | | - node.setLeft(this._put(key, value, node.getLeft())); |
| 62 | + node._left = this._put(key, value, node._left); |
63 | 63 | } else if (node.getKey() < key) { |
64 | | - node.setRight(this._put(key, value, node.getRight())); |
| 64 | + node._right = this._put(key, value, node._right); |
65 | 65 | } |
66 | | - if (this.isRed(node.getRight()) && !this.isRed(node.getLeft())) { |
| 66 | + if (this.isRed(node._right) && !this.isRed(node._left)) { |
67 | 67 | newRoot = this._rotateLeft(node); |
68 | 68 | } |
69 | | - if (this.isRed(node.getLeft()) && this.isRed(node.getLeft().getLeft())) { |
| 69 | + if (this.isRed(node._left) && this.isRed(node._left._left)) { |
70 | 70 | newRoot = this._rotateRight(node); |
71 | 71 | } |
72 | | - if (this.isRed(node.getLeft()) && this.isRed(node.getRight())) { |
| 72 | + if (this.isRed(node._left) && this.isRed(node._right)) { |
73 | 73 | this._flipColors(node); |
74 | 74 | } |
75 | 75 | return newRoot; |
76 | 76 | }; |
77 | 77 |
|
78 | 78 | RBTree.prototype._flipColors = function (node) { |
79 | | - node.getLeft().flipColor(); |
80 | | - node.getRight().flipColor(); |
| 79 | + node._left.flipColor(); |
| 80 | + node._right.flipColor(); |
81 | 81 | }; |
82 | 82 |
|
83 | 83 | RBTree.prototype._rotateLeft = function (node) { |
84 | | - var x = node.getRight(); |
| 84 | + var x = node._right; |
85 | 85 | if (x !== null) { |
86 | | - var temp = x.getLeft(); |
| 86 | + var temp = x._left; |
87 | 87 | node.setRight(temp); |
88 | | - x.setLeft(node); |
| 88 | + x._left = node; |
89 | 89 | } |
90 | 90 | return x; |
91 | 91 | }; |
92 | 92 |
|
93 | 93 | RBTree.prototype._rotateRight = function (node) { |
94 | | - var x = node.getLeft(); |
| 94 | + var x = node._left; |
95 | 95 | if (x !== null) { |
96 | | - var temp = x.getRight(); |
97 | | - node.setLeft(temp); |
98 | | - x.setRight(node); |
| 96 | + var temp = x._right; |
| 97 | + node._left = temp; |
| 98 | + x._right = node; |
99 | 99 | } |
100 | 100 | return x; |
101 | 101 | }; |
102 | 102 |
|
| 103 | + RBTree.prototype.getIterator = function () { |
| 104 | + return new RBTIterator(this); |
| 105 | + }; |
| 106 | + |
| 107 | + function RBTIterator(tree) { |
| 108 | + this._tree = tree; |
| 109 | + } |
| 110 | + |
103 | 111 | global.RBTree = RBTree; |
104 | 112 |
|
| 113 | + |
| 114 | + |
105 | 115 | }(typeof window === 'undefined' ? module.exports : window)); |
0 commit comments