Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

33
LINES

< > BotCompany Repo | #1028241 // indexOfIntPairInContentsIndexedList

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (88L/1K).

static int indexOfIntPairInContentsIndexedList(IContentsIndexedList2<Int> l, Int pa, Int pb, int idx) {
  SortedSet<HasIndex> setA = l.indicesOf_treeSetOfHasIndex(pa);
  if (setA == null) ret -1;
  SortedSet<HasIndex> setB = l.indicesOf_treeSetOfHasIndex(pb);
  if (setB == null) ret -1;
  
  // Take size now because size of a tailSet is costly to compute
  if (setA.size() <= setB.size()) {
    // quickly skip entries left of idx
    if (idx > 0)
      setA = setA.tailSet(HasIndex(idx));

    // scan set, check if it's a pair
    int n = l.size();
    for (HasIndex hi : setA) {
      int i = hi.idx;
      if (i+1 < n && eq(l.get(i+1), pb))
        ret i;
    }
  } else {
    // quickly skip entries left of idx+1
    setB = setB.tailSet(HasIndex(idx+1));
    
    // scan set, check if it's a pair
    for (HasIndex hi : setB) {
      int i = hi.idx;
      if (eq(l.get(i-1), pa))
        ret i-1;
    }
  }
  
  ret -1;
}

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: 229 / 329
Version history: 7 change(s)
Referenced in: [show references]