(K key, V value)
| 4411 | } |
| 4412 | |
| 4413 | private V putImpl(K key, V value) { |
| 4414 | if (root == null) { |
| 4415 | root = createNode(key, value); |
| 4416 | size = 1; |
| 4417 | modCount++; |
| 4418 | return null; |
| 4419 | } |
| 4420 | java.lang.Comparable<K> object = comparator == null ? toComparable((K) key) |
| 4421 | : null; |
| 4422 | K keyK = (K) key; |
| 4423 | Node<K, V> node = root; |
| 4424 | Node<K, V> prevNode = null; |
| 4425 | int result = 0; |
| 4426 | while (node != null) { |
| 4427 | prevNode = node; |
| 4428 | K[] keys = node.keys; |
| 4429 | int left_idx = node.left_idx; |
| 4430 | result = cmp(object, keyK, keys[left_idx]); |
| 4431 | if (result < 0) { |
| 4432 | node = node.left; |
| 4433 | } else if (result == 0) { |
| 4434 | V res = node.values[left_idx]; |
| 4435 | node.values[left_idx] = value; |
| 4436 | return res; |
| 4437 | } else { |
| 4438 | int right_idx = node.right_idx; |
| 4439 | if (left_idx != right_idx) { |
| 4440 | result = cmp(object, keyK, keys[right_idx]); |
| 4441 | } |
| 4442 | if (result > 0) { |
| 4443 | node = node.right; |
| 4444 | } else if (result == 0) { |
| 4445 | V res = node.values[right_idx]; |
| 4446 | node.values[right_idx] = value; |
| 4447 | return res; |
| 4448 | } else { /* search in node */ |
| 4449 | int low = left_idx + 1, mid = 0, high = right_idx - 1; |
| 4450 | while (low <= high) { |
| 4451 | mid = (low + high) >>> 1; |
| 4452 | result = cmp(object, keyK, keys[mid]); |
| 4453 | if (result > 0) { |
| 4454 | low = mid + 1; |
| 4455 | } else if (result == 0) { |
| 4456 | V res = node.values[mid]; |
| 4457 | node.values[mid] = value; |
| 4458 | return res; |
| 4459 | } else { |
| 4460 | high = mid - 1; |
| 4461 | } |
| 4462 | } |
| 4463 | result = low; |
| 4464 | break; |
| 4465 | } |
| 4466 | } |
| 4467 | } /* while */ |
| 4468 | /* |
| 4469 | * if(node == null) { if(prevNode==null) { - case of empty Tree } else { |
| 4470 | * result < 0 - prevNode.left==null - attach here result > 0 - |
no test coverage detected