Libraryless. Click here for Pure Java version (2704L/18K).
1 | sclass LCSortedPairIndex { |
2 | long[] pairs; |
3 | int[] index; |
4 | int ofs; // added to every result |
5 | |
6 | *(long[] pairs, int *ofs) { |
7 | this(pairs); |
8 | } |
9 | |
10 | *(long[] pairs) { |
11 | this(pairs, null); |
12 | } |
13 | |
14 | // primer is destroyed in the process |
15 | *(long[] *pairs, LCSortedPairIndex primer) { |
16 | int[] primerData = primer?.index; |
17 | if (primer != null) primer.pairs = null; |
18 | index = lc_sortedPairIndex(pairs, primerData); |
19 | } |
20 | |
21 | int get(long pair) { |
22 | int i = intArrayBinarySearchWithGeneralizedComparator(index, a -> { |
23 | int x = cmp(pairs[a], pair); |
24 | ifdef LCSortedPairIndex_debug |
25 | printVars_str(+a, val := pairs[a], +pair, +x); |
26 | endifdef |
27 | ret x; |
28 | }); |
29 | ret i >= 0 ? index[i]+ofs : -1; |
30 | } |
31 | } |
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: | #1029420 |
Snippet name: | LCSortedPairIndex (OK) |
Eternal ID of this version: | #1029420/14 |
Text MD5: | b88068fc3d0cd962ea56acd8ec9cf0df |
Transpilation MD5: | f13330dbd57faf734abc704237a393c9 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-08-06 02:28:01 |
Source code size: | 757 bytes / 31 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 277 / 602 |
Version history: | 13 change(s) |
Referenced in: | [show references] |