IntTree < V > changeKeysAbove ( final long key , final int delta ) { if ( size == 0 || delta == 0 ) return this ; if ( this . key >= key ) // adding delta to this.key changes the keys of _all_ children of this, // so we now need to un-change the children of this smaller than key, // all of which are to the left. note that we still use the 'old' relative key...: return new IntTree < V > ( this . key + delta , value , left . changeKeysBelow ( key - this . key , - delta ) , right ) ; // otherwise, doesn't apply yet, look to the right: IntTree < V > newRight = right . changeKeysAbove ( key - this . key , delta ) ; if ( newRight == right ) return this ; return new IntTree < V > ( this . key , value , left , newRight ) ; }
Changes every key k > = key to k + delta .