@@ -151,6 +151,10 @@ private[collection] object NewRedBlackTree {
151
151
mutableBalanceLeft(tree, mutableUpd(tree.left, k))
152
152
else if (cmp > 0 )
153
153
mutableBalanceRight(tree, mutableUpd(tree.right, k))
154
+ else if (k != tree.key)
155
+ tree.mutableWithK(k)
156
+ // Note - in 2.13 remove the above else clause
157
+ // due to the different handling of key equality
154
158
else tree
155
159
}
156
160
}
@@ -166,6 +170,10 @@ private[collection] object NewRedBlackTree {
166
170
mutableBalanceLeft(tree, mutableUpd(tree.left, k, v))
167
171
else if (cmp > 0 )
168
172
mutableBalanceRight(tree, mutableUpd(tree.right, k, v))
173
+ else if (k != tree.key)
174
+ tree.mutableWithKV(k,v)
175
+ // Note - in 2.13 remove the above else clause
176
+ // due to the different handling of key equality
169
177
else tree.mutableWithV(v)
170
178
}
171
179
}
@@ -569,12 +577,32 @@ private[collection] object NewRedBlackTree {
569
577
// }
570
578
// else new Tree(_key, _value, _left, _right, initialRedCount)
571
579
// }
572
- def mutableWithV [B1 >: B ](value : B1 ): Tree [A , B1 ] = {
573
- if (value.asInstanceOf [AnyRef ] eq _value.asInstanceOf [AnyRef ]) this
580
+ // Note - in 2.13 remove his method
581
+ // due to the handling of keys in 2.13 we never replace a key
582
+ def mutableWithK [B1 >: B ](newKey : A ): Tree [A , B1 ] = {
583
+ if (newKey.asInstanceOf [AnyRef ] eq _key.asInstanceOf [AnyRef ]) this
574
584
else if (mutable) {
585
+ _key = newKey
586
+ this
587
+ } else new Tree (newKey, _value.asInstanceOf [AnyRef ], _left, _right, _count)
588
+ }
589
+ def mutableWithV [B1 >: B ](newValue : B1 ): Tree [A , B1 ] = {
590
+ if (newValue.asInstanceOf [AnyRef ] eq _value.asInstanceOf [AnyRef ]) this
591
+ else if (mutable) {
592
+ _value = newValue.asInstanceOf [AnyRef ]
593
+ this
594
+ } else new Tree (_key, newValue.asInstanceOf [AnyRef ], _left, _right, _count)
595
+ }
596
+ // Note - in 2.13 remove his method
597
+ // due to the handling of keys in 2.13 we never replace a key
598
+ def mutableWithKV [B1 >: B ](newKey : A , newValue : B1 ): Tree [A , B1 ] = {
599
+ if ((newKey.asInstanceOf [AnyRef ] eq _key.asInstanceOf [AnyRef ]) &&
600
+ (newValue.asInstanceOf [AnyRef ] eq _value.asInstanceOf [AnyRef ])) this
601
+ else if (mutable) {
602
+ _key = newKey
575
603
_value = value.asInstanceOf [AnyRef ]
576
604
this
577
- } else new Tree (_key, value .asInstanceOf [AnyRef ], _left, _right, _count)
605
+ } else new Tree (newKey, newValue .asInstanceOf [AnyRef ], _left, _right, _count)
578
606
}
579
607
def mutableWithLeft [B1 >: B ](newLeft : Tree [A , B1 ]): Tree [A , B1 ] = {
580
608
if (_left eq newLeft) this
0 commit comments