@@ -90,24 +90,24 @@ export class AvlTree<K, V> implements AvlTreeApi<K, V> {
90
90
root . height = Math . max ( root . leftHeight , root . rightHeight ) + 1 ;
91
91
const balanceState = this . _getBalanceState ( root ) ;
92
92
93
- if ( root . left && balanceState === BalanceState . UNBALANCED_LEFT ) {
94
- if ( this . _compare ( key , root . left . key ) < 0 ) {
93
+ if ( balanceState === BalanceState . UNBALANCED_LEFT ) {
94
+ if ( this . _compare ( key , ( < Node < K , V > > root . left ) . key ) < 0 ) {
95
95
// Left left case
96
96
root = root . rotateRight ( ) ;
97
97
} else {
98
98
// Left right case
99
- root . left = root . left . rotateLeft ( ) ;
99
+ root . left = ( < Node < K , V > > root . left ) . rotateLeft ( ) ;
100
100
return root . rotateRight ( ) ;
101
101
}
102
102
}
103
103
104
- if ( root . right && balanceState === BalanceState . UNBALANCED_RIGHT ) {
105
- if ( this . _compare ( key , root . right . key ) > 0 ) {
104
+ if ( balanceState === BalanceState . UNBALANCED_RIGHT ) {
105
+ if ( this . _compare ( key , ( < Node < K , V > > root . right ) . key ) > 0 ) {
106
106
// Right right case
107
107
root = root . rotateLeft ( ) ;
108
108
} else {
109
109
// Right left case
110
- root . right = root . right . rotateRight ( ) ;
110
+ root . right = ( < Node < K , V > > root . right ) . rotateRight ( ) ;
111
111
return root . rotateLeft ( ) ;
112
112
}
113
113
}
@@ -168,27 +168,27 @@ export class AvlTree<K, V> implements AvlTreeApi<K, V> {
168
168
root . height = Math . max ( root . leftHeight , root . rightHeight ) + 1 ;
169
169
const balanceState = this . _getBalanceState ( root ) ;
170
170
171
- if ( root . left && balanceState === BalanceState . UNBALANCED_LEFT ) {
171
+ if ( balanceState === BalanceState . UNBALANCED_LEFT ) {
172
172
// Left left case
173
- if ( this . _getBalanceState ( root . left ) === BalanceState . BALANCED ||
174
- this . _getBalanceState ( root . left ) === BalanceState . SLIGHTLY_UNBALANCED_LEFT ) {
173
+ if ( this . _getBalanceState ( ( < Node < K , V > > root . left ) ) === BalanceState . BALANCED ||
174
+ this . _getBalanceState ( ( < Node < K , V > > root . left ) ) === BalanceState . SLIGHTLY_UNBALANCED_LEFT ) {
175
175
return root . rotateRight ( ) ;
176
176
}
177
177
// Left right case
178
178
// this._getBalanceState(root.left) === BalanceState.SLIGHTLY_UNBALANCED_RIGHT
179
- root . left = root . left . rotateLeft ( ) ;
179
+ root . left = ( < Node < K , V > > root . left ) . rotateLeft ( ) ;
180
180
return root . rotateRight ( ) ;
181
181
}
182
182
183
- if ( root . right && balanceState === BalanceState . UNBALANCED_RIGHT ) {
183
+ if ( balanceState === BalanceState . UNBALANCED_RIGHT ) {
184
184
// Right right case
185
- if ( this . _getBalanceState ( root . right ) === BalanceState . BALANCED ||
186
- this . _getBalanceState ( root . right ) === BalanceState . SLIGHTLY_UNBALANCED_RIGHT ) {
185
+ if ( this . _getBalanceState ( ( < Node < K , V > > root . right ) ) === BalanceState . BALANCED ||
186
+ this . _getBalanceState ( ( < Node < K , V > > root . right ) ) === BalanceState . SLIGHTLY_UNBALANCED_RIGHT ) {
187
187
return root . rotateLeft ( ) ;
188
188
}
189
189
// Right left case
190
190
// this._getBalanceState(root.right) === BalanceState.SLIGHTLY_UNBALANCED_LEFT
191
- root . right = root . right . rotateRight ( ) ;
191
+ root . right = ( < Node < K , V > > root . right ) . rotateRight ( ) ;
192
192
return root . rotateLeft ( ) ;
193
193
}
194
194
0 commit comments