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)
| 1108 | * cannot handle {@code null} keys. |
| 1109 | */ |
| 1110 | @Override |
| 1111 | public boolean containsKey(Object key) { |
| 1112 | Comparable<K> object = comparator == null ? toComparable((K) key) : null; |
| 1113 | K keyK = (K) key; |
| 1114 | Node<K, V> node = root; |
| 1115 | while (node != null) { |
| 1116 | K[] keys = node.keys; |
| 1117 | int left_idx = node.left_idx; |
| 1118 | int result = cmp(object, keyK, keys[left_idx]); |
| 1119 | if (result < 0) { |
| 1120 | node = node.left; |
| 1121 | } else if (result == 0) { |
| 1122 | return true; |
| 1123 | } else { |
| 1124 | int right_idx = node.right_idx; |
| 1125 | if (left_idx != right_idx) { |
| 1126 | result = cmp(object, keyK, keys[right_idx]); |
| 1127 | } |
| 1128 | if (result > 0) { |
| 1129 | node = node.right; |
| 1130 | } else if (result == 0) { |
| 1131 | return true; |
| 1132 | } else { /*search in node*/ |
| 1133 | int low = left_idx + 1, mid = 0, high = right_idx - 1; |
| 1134 | while (low <= high) { |
| 1135 | mid = (low + high) >>> 1; |
| 1136 | result = cmp(object, keyK, keys[mid]); |
| 1137 | if (result > 0) { |
| 1138 | low = mid + 1; |
| 1139 | } else if (result == 0) { |
| 1140 | return true; |
| 1141 | } else { |
| 1142 | high = mid - 1; |
| 1143 | } |
| 1144 | } |
| 1145 | return false; |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | return false; |
| 1150 | } |
| 1151 | |
| 1152 | /** |
| 1153 | * Returns whether this map contains the specified value. |
nothing calls this directly
no test coverage detected