MCPcopy Create free account
hub / github.com/dumbledore/AlbiteREADER / binarySearch

Method binarySearch

src/org/albite/lang/TextTools.java:160–193  ·  view source on GitHub ↗
(final char[][] haystack, final char[] key)

Source from the content-addressed store, hash-verified

158 }
159
160 public static int binarySearch(final char[][] haystack, final char[] key) {
161
162 int left = 0;
163 int right = haystack.length;
164 int middle;
165
166 int compare = 0;
167
168 while (right > left) {
169 middle = left + ((right - left) / 2);
170
171 compare =
172 compareCharArrays(
173 key, 0, key.length,
174 haystack[middle], 0, haystack[middle].length);
175
176 if (compare == 0) {
177 return middle;
178 }
179
180 if (compare < 0) {
181 right = middle;
182 } else {
183 left = middle + 1;
184 }
185 }
186
187 /*
188 * Decrease the index by one. Thus, one can make the difference
189 * whether the exact word has been found when the returned index
190 * should be zero.
191 */
192 return -left -1;
193 }
194 //endif
195
196// public static void toLowerCase(

Callers 2

lookUpMethod · 0.95
getDefinitionMethod · 0.95

Calls 1

compareCharArraysMethod · 0.95

Tested by

no test coverage detected