Libraryless. Click here for Pure Java version (48L/1K).
1 | // Like Arrays.binarySearch, but without range checks. |
2 | static int intArrayBinarySearch(int[] a, int key) { |
3 | ret intArrayBinarySearch(a, 0, a.length, key); |
4 | } |
5 | |
6 | static int intArrayBinarySearch(int[] a, int fromIndex, int toIndex, int key) { |
7 | int low = fromIndex; |
8 | int high = toIndex - 1; |
9 | |
10 | while (low <= high) { |
11 | int mid = (low + high) >>> 1; |
12 | int midVal = a[mid]; |
13 | |
14 | if (midVal < key) |
15 | low = mid + 1; |
16 | else if (midVal > key) |
17 | high = mid - 1; |
18 | else |
19 | return mid; // key found |
20 | } |
21 | return -(low + 1); // key not found. |
22 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1029041 |
Snippet name: | intArrayBinarySearch |
Eternal ID of this version: | #1029041/4 |
Text MD5: | bd35c1c2f1ae3a04cb1163fe4239ae82 |
Transpilation MD5: | b1cb705896a664ef5be4475388b27df6 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-17 14:13:39 |
Source code size: | 579 bytes / 22 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 191 / 294 |
Version history: | 3 change(s) |
Referenced in: | [show references] |