Libraryless. Click here for Pure Java version (88L/1K).
1 | static int indexOfIntPairInContentsIndexedList(IContentsIndexedList2<Int> l, Int pa, Int pb, int idx) { |
2 | SortedSet<HasIndex> setA = l.indicesOf_treeSetOfHasIndex(pa); |
3 | if (setA == null) ret -1; |
4 | SortedSet<HasIndex> setB = l.indicesOf_treeSetOfHasIndex(pb); |
5 | if (setB == null) ret -1; |
6 | |
7 | // Take size now because size of a tailSet is costly to compute |
8 | if (setA.size() <= setB.size()) { |
9 | // quickly skip entries left of idx |
10 | if (idx > 0) |
11 | setA = setA.tailSet(HasIndex(idx)); |
12 | |
13 | // scan set, check if it's a pair |
14 | int n = l.size(); |
15 | for (HasIndex hi : setA) { |
16 | int i = hi.idx; |
17 | if (i+1 < n && eq(l.get(i+1), pb)) |
18 | ret i; |
19 | } |
20 | } else { |
21 | // quickly skip entries left of idx+1 |
22 | setB = setB.tailSet(HasIndex(idx+1)); |
23 | |
24 | // scan set, check if it's a pair |
25 | for (HasIndex hi : setB) { |
26 | int i = hi.idx; |
27 | if (eq(l.get(i-1), pa)) |
28 | ret i-1; |
29 | } |
30 | } |
31 | |
32 | ret -1; |
33 | } |
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: | #1028241 |
Snippet name: | indexOfIntPairInContentsIndexedList |
Eternal ID of this version: | #1028241/8 |
Text MD5: | 01d942b3a265c00e4de28ce286bc86ff |
Transpilation MD5: | a842eb4df13ffcce52516cb1604084b6 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-05-27 21:55:58 |
Source code size: | 962 bytes / 33 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 230 / 331 |
Version history: | 7 change(s) |
Referenced in: | [show references] |