@@ -820,17 +820,17 @@ private[collection] object RedBlackTree {
820
820
} else mkTree(isRedTree(tl) || isRedTree(tr), k, v, tl, tr)
821
821
}
822
822
823
- private [this ] def split [A , B ](t : Tree [A , B ], k : A )(implicit ordering : Ordering [A ]): (Tree [A , B ], Tree [A , B ], Tree [A , B ]) =
824
- if (t eq null ) (null , null , null )
823
+ private [this ] def split [A , B ](t : Tree [A , B ], k2 : A )(implicit ordering : Ordering [A ]): (Tree [A , B ], Tree [A , B ], Tree [A , B ], A ) =
824
+ if (t eq null ) (null , null , null , k2 )
825
825
else {
826
- val cmp = ordering.compare(k , t.key)
827
- if (cmp == 0 ) (t.left, t, t.right)
826
+ val cmp = ordering.compare(k2 , t.key)
827
+ if (cmp == 0 ) (t.left, t, t.right, t.key )
828
828
else if (cmp < 0 ) {
829
- val (ll, b, lr) = split(t.left, k )
830
- (ll, b, join(lr, t.key, t.value, t.right))
829
+ val (ll, b, lr, k1 ) = split(t.left, k2 )
830
+ (ll, b, join(lr, t.key, t.value, t.right), k1 )
831
831
} else {
832
- val (rl, b, rr) = split(t.right, k )
833
- (join(t.left, t.key, t.value, rl), b, rr)
832
+ val (rl, b, rr, k1 ) = split(t.right, k2 )
833
+ (join(t.left, t.key, t.value, rl), b, rr, k1 )
834
834
}
835
835
}
836
836
@@ -853,28 +853,28 @@ private[collection] object RedBlackTree {
853
853
if ((t1 eq null ) || (t1 eq t2)) t2
854
854
else if (t2 eq null ) t1
855
855
else {
856
- val (l2 , _, r2 ) = split(t2, t1 .key)
857
- val tl = _union(t1.left, l2 )
858
- val tr = _union(t1.right, r2 )
859
- join(tl, t1.key, t1 .value, tr)
856
+ val (l1 , _, r1, k1 ) = split(t1, t2 .key)
857
+ val tl = _union(l1, t2.left )
858
+ val tr = _union(r1, t2.right )
859
+ join(tl, k1, t2 .value, tr)
860
860
}
861
861
862
862
private [this ] def _intersect [A , B ](t1 : Tree [A , B ], t2 : Tree [A , B ])(implicit ordering : Ordering [A ]): Tree [A , B ] =
863
863
if ((t1 eq null ) || (t2 eq null )) null
864
864
else if (t1 eq t2) t1
865
865
else {
866
- val (l2 , b, r2 ) = split(t2, t1 .key)
867
- val tl = _intersect(t1.left, l2 )
868
- val tr = _intersect(t1.right, r2 )
869
- if (b ne null ) join(tl, t1.key, t1 .value, tr)
866
+ val (l1 , b, r1, k1 ) = split(t1, t2 .key)
867
+ val tl = _intersect(l1, t2.left )
868
+ val tr = _intersect(r1, t2.right )
869
+ if (b ne null ) join(tl, k1, t2 .value, tr)
870
870
else join2(tl, tr)
871
871
}
872
872
873
873
private [this ] def _difference [A , B ](t1 : Tree [A , B ], t2 : Tree [A , B ])(implicit ordering : Ordering [A ]): Tree [A , B ] =
874
874
if ((t1 eq null ) || (t2 eq null )) t1
875
875
else if (t1 eq t2) null
876
876
else {
877
- val (l1, _, r1) = split(t1, t2.key)
877
+ val (l1, _, r1, k1 ) = split(t1, t2.key)
878
878
val tl = _difference(l1, t2.left)
879
879
val tr = _difference(r1, t2.right)
880
880
join2(tl, tr)
0 commit comments