(K key)
| 3955 | } |
| 3956 | |
| 3957 | TreeMap.Entry<K, V> findCeilingEntry(K key) { |
| 3958 | if (root == null) { |
| 3959 | return null; |
| 3960 | } |
| 3961 | java.lang.Comparable<K> object = comparator == null ? toComparable((K) key) |
| 3962 | : null; |
| 3963 | K keyK = (K) key; |
| 3964 | Node<K, V> node = root; |
| 3965 | Node<K, V> foundNode = null; |
| 3966 | int foundIndex = 0; |
| 3967 | while (node != null) { |
| 3968 | K[] keys = node.keys; |
| 3969 | int left_idx = node.left_idx; |
| 3970 | int right_idx = node.right_idx; |
| 3971 | int result = cmp(object, keyK, keys[left_idx]); |
| 3972 | if (result < 0) { |
| 3973 | foundNode = node; |
| 3974 | foundIndex = left_idx; |
| 3975 | node = node.left; |
| 3976 | } else if (result == 0) { |
| 3977 | foundNode = node; |
| 3978 | foundIndex = left_idx; |
| 3979 | break; |
| 3980 | } else { |
| 3981 | if (left_idx != right_idx) { |
| 3982 | result = cmp(object, key, keys[right_idx]); |
| 3983 | } |
| 3984 | if (result > 0) { |
| 3985 | node = node.right; |
| 3986 | } else { /* search in node */ |
| 3987 | foundNode = node; |
| 3988 | foundIndex = right_idx; |
| 3989 | if (result == 0) { |
| 3990 | break; |
| 3991 | } |
| 3992 | int low = left_idx + 1, mid = 0, high = right_idx - 1; |
| 3993 | while (low <= high && result != 0) { |
| 3994 | mid = (low + high) >> 1; |
| 3995 | result = cmp(object, key, keys[mid]); |
| 3996 | if (result <= 0) { |
| 3997 | foundNode = node; |
| 3998 | foundIndex = mid; |
| 3999 | high = mid - 1; |
| 4000 | }else { |
| 4001 | low = mid + 1; |
| 4002 | } |
| 4003 | if (result == 0 || (low == high && high == mid)){ |
| 4004 | break; |
| 4005 | } |
| 4006 | } |
| 4007 | break; |
| 4008 | } |
| 4009 | } |
| 4010 | } |
| 4011 | if (foundNode != null |
| 4012 | && cmp(object,keyK, foundNode.keys[foundIndex]) > 0) { |
| 4013 | foundNode = null; |
| 4014 | } |
no test coverage detected