| 641 | } |
| 642 | |
| 643 | AvlNode<E> remove(Comparator<? super E> comparator, @Nullable E e, int count, int[] result) { |
| 644 | int cmp = comparator.compare(e, elem); |
| 645 | if (cmp < 0) { |
| 646 | AvlNode<E> initLeft = left; |
| 647 | if (initLeft == null) { |
| 648 | result[0] = 0; |
| 649 | return this; |
| 650 | } |
| 651 | left = initLeft.remove(comparator, e, count, result); |
| 652 | if (result[0] > 0) { |
| 653 | if (count >= result[0]) { |
| 654 | this.distinctElements--; |
| 655 | this.totalCount -= result[0]; |
| 656 | } else { |
| 657 | this.totalCount -= count; |
| 658 | } |
| 659 | } |
| 660 | return (result[0] == 0) ? this : rebalance(); |
| 661 | } |
| 662 | else if (cmp > 0) { |
| 663 | AvlNode<E> initRight = right; |
| 664 | if (initRight == null) { |
| 665 | result[0] = 0; |
| 666 | return this; |
| 667 | } |
| 668 | right = initRight.remove(comparator, e, count, result); |
| 669 | if (result[0] > 0) { |
| 670 | if (count >= result[0]) { |
| 671 | this.distinctElements--; |
| 672 | this.totalCount -= result[0]; |
| 673 | } else { |
| 674 | this.totalCount -= count; |
| 675 | } |
| 676 | } |
| 677 | return rebalance(); |
| 678 | } |
| 679 | |
| 680 | // removing count from me! |
| 681 | result[0] = elemCount; |
| 682 | if (count >= elemCount) { |
| 683 | return deleteMe(); |
| 684 | } else { |
| 685 | this.elemCount -= count; |
| 686 | this.totalCount -= count; |
| 687 | return this; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | AvlNode<E> setCount(Comparator<? super E> comparator, @Nullable E e, int count, int[] result) { |
| 692 | int cmp = comparator.compare(e, elem); |