MCPcopy Create free account
hub / github.com/ReadyTalk/avian / binarySearch

Method binarySearch

classpath/java/util/Collections.java:153–167  ·  view source on GitHub ↗
(List<T> list, T needle)

Source from the content-addressed store, hash-verified

151 }
152
153 public static <T> int binarySearch(List<T> list, T needle) {
154 int left = -1, right = list.size();
155 while (left + 1 < right) {
156 int middle = (left + right) >> 1;
157 int result = ((Comparable)needle).compareTo(list.get(middle));
158 if (result < 0) {
159 right = middle;
160 } else if (result > 0) {
161 left = middle;
162 } else {
163 return middle;
164 }
165 }
166 return -1 - right;
167 }
168
169 public static <T> void reverse(List<T> list) {
170 int ascending = 0, descending = list.size() - 1;

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.65
compareToMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected