(Object key)
| 4845 | /// if the specified key is `null` and the comparator |
| 4846 | /// cannot handle `null` keys. |
| 4847 | @SuppressWarnings("unchecked") |
| 4848 | @Override |
| 4849 | public V remove(Object key) { |
| 4850 | java.lang.Comparable<K> object = comparator == null ? toComparable((K) key) : null; |
| 4851 | if (size == 0) { |
| 4852 | return null; |
| 4853 | } |
| 4854 | K keyK = (K) key; |
| 4855 | Node<K, V> node = root; |
| 4856 | while (node != null) { |
| 4857 | K[] keys = node.keys; |
| 4858 | int left_idx = node.left_idx; |
| 4859 | int result = cmp(object, keyK, keys[left_idx]); |
| 4860 | if (result < 0) { |
| 4861 | node = node.left; |
| 4862 | } else if (result == 0) { |
| 4863 | V value = node.values[left_idx]; |
| 4864 | removeLeftmost(node); |
| 4865 | return value; |
| 4866 | } else { |
| 4867 | int right_idx = node.right_idx; |
| 4868 | if (left_idx != right_idx) { |
| 4869 | result = cmp(object, keyK, keys[right_idx]); |
| 4870 | } |
| 4871 | if (result > 0) { |
| 4872 | node = node.right; |
| 4873 | } else if (result == 0) { |
| 4874 | V value = node.values[right_idx]; |
| 4875 | removeRightmost(node); |
| 4876 | return value; |
| 4877 | } else { /*search in node*/ |
| 4878 | int low = left_idx + 1, mid = 0, high = right_idx - 1; |
| 4879 | while (low <= high) { |
| 4880 | mid = (low + high) >>> 1; |
| 4881 | result = cmp(object, keyK, keys[mid]); |
| 4882 | if (result > 0) { |
| 4883 | low = mid + 1; |
| 4884 | } else if (result == 0) { |
| 4885 | V value = node.values[mid]; |
| 4886 | removeMiddleElement(node, mid); |
| 4887 | return value; |
| 4888 | } else { |
| 4889 | high = mid - 1; |
| 4890 | } |
| 4891 | } |
| 4892 | return null; |
| 4893 | } |
| 4894 | } |
| 4895 | } |
| 4896 | return null; |
| 4897 | } |
| 4898 | |
| 4899 | K removeLeftmost(Node<K, V> node) { |
| 4900 | int index = node.left_idx; |
no test coverage detected