private TreeNode < T > assimilateOverlappingIntervals ( TreeNode < T > from ) { ArrayList < Interval < T >> tmp = new ArrayList <> ( ) ; if ( midpoint . compareTo ( from . midpoint ) < 0 ) { for ( Interval < T > next : from . increasing ) { if ( next . isRightOf ( midpoint ) ) break ; tmp . add ( next ) ; } } else { for ( Interval < T > next : from . decreasing ) { if ( next . isLeftOf ( midpoint ) ) break ; tmp . add ( next ) ; } } from . increasing . removeAll ( tmp ) ; from . decreasing . removeAll ( tmp ) ; increasing . addAll ( tmp ) ; decreasing . addAll ( tmp ) ; if ( from . increasing . size ( ) == 0 ) { return deleteNode ( from ) ; } return from ; }
Transfers all intervals from a target node to the current node if they intersect the middlepoint of the current node . After this operation it is possible that the target node remains empty . If so it needs to be deleted possible causing the subtree to be rebalanced .