Returns whether this map contains the specified key. @param key the key to search for. @return true if this map contains the specified key, false otherwise. @throws ClassCastException if the specified key cannot be compared with the keys in this
(Object key)
| 3781 | * cannot handle {@code null} keys. |
| 3782 | */ |
| 3783 | @SuppressWarnings("unchecked") |
| 3784 | @Override |
| 3785 | public boolean containsKey(Object key) { |
| 3786 | java.lang.Comparable<K> object = comparator == null ? toComparable((K) key) |
| 3787 | : null; |
| 3788 | K keyK = (K) key; |
| 3789 | Node<K, V> node = root; |
| 3790 | while (node != null) { |
| 3791 | K[] keys = node.keys; |
| 3792 | int left_idx = node.left_idx; |
| 3793 | int result = object != null ? object.compareTo(keys[left_idx]) |
| 3794 | : -comparator.compare(keys[left_idx], keyK); |
| 3795 | if (result < 0) { |
| 3796 | node = node.left; |
| 3797 | } else if (result == 0) { |
| 3798 | return true; |
| 3799 | } else { |
| 3800 | int right_idx = node.right_idx; |
| 3801 | if (left_idx != right_idx) { |
| 3802 | result = cmp(object, keyK, keys[right_idx]); |
| 3803 | } |
| 3804 | if (result > 0) { |
| 3805 | node = node.right; |
| 3806 | } else if (result == 0) { |
| 3807 | return true; |
| 3808 | } else { /* search in node */ |
| 3809 | int low = left_idx + 1, mid = 0, high = right_idx - 1; |
| 3810 | while (low <= high) { |
| 3811 | mid = (low + high) >>> 1; |
| 3812 | result = cmp(object, keyK, keys[mid]); |
| 3813 | if (result > 0) { |
| 3814 | low = mid + 1; |
| 3815 | } else if (result == 0) { |
| 3816 | return true; |
| 3817 | } else { |
| 3818 | high = mid - 1; |
| 3819 | } |
| 3820 | } |
| 3821 | return false; |
| 3822 | } |
| 3823 | } |
| 3824 | } |
| 3825 | return false; |
| 3826 | } |
| 3827 | |
| 3828 | /** |
| 3829 | * Returns whether this map contains the specified value. |
no test coverage detected