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

18
LINES

< > BotCompany Repo | #1029029 // intersectSortedIntArrays_ofs [add offset to second list]

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

Libraryless. Click here for Pure Java version (2521L/16K).

// is allowed to return null when result is empty
static int[] intersectSortedIntArrays_ofs(int[] a, int[] b, int ofs) {
  int i = 0, j = 0, la = l(a), lb = l(b);
  if (la == 0 || lb == 0) null;
  IntBuffer buf = new(min(la, lb));
  while (i < la && j < lb) {
    int x = a[i], y = b[j]+ofs;
    if (x == y) {
      buf.add(x);
      ++i;
      ++j;
    } else if (x < y)
      ++i;
    else
      ++j;
  }
  ret buf.toArray();
}

Author comment

Began life as a copy of #1029026

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: #1029029
Snippet name: intersectSortedIntArrays_ofs [add offset to second list]
Eternal ID of this version: #1029029/5
Text MD5: 0a2104065ffa7ccf376df18aa852a768
Transpilation MD5: 9c5605d5bc5fdb1e6ba1c5f21587b622
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-17 01:31:44
Source code size: 446 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 162 / 248
Version history: 4 change(s)
Referenced in: [show references]