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

31
LINES

< > BotCompany Repo | #1029420 // LCSortedPairIndex (OK)

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

Libraryless. Click here for Pure Java version (2704L/18K).

sclass LCSortedPairIndex {
  long[] pairs;
  int[] index;
  int ofs; // added to every result
  
  *(long[] pairs, int *ofs) {
    this(pairs);
  }
  
  *(long[] pairs) {
    this(pairs, null);
  }
  
  // primer is destroyed in the process
  *(long[] *pairs, LCSortedPairIndex primer) {
    int[] primerData = primer?.index;
    if (primer != null) primer.pairs = null;
    index = lc_sortedPairIndex(pairs, primerData);
  }
  
  int get(long pair) {
    int i = intArrayBinarySearchWithGeneralizedComparator(index, a -> {
      int x = cmp(pairs[a], pair);
      ifdef LCSortedPairIndex_debug
        printVars_str(+a, val := pairs[a], +pair, +x);
      endifdef
      ret x;
    });
    ret i >= 0 ? index[i]+ofs : -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: #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: 278 / 602
Version history: 13 change(s)
Referenced in: #1029427 - test_LCSortedPairIndex
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)