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

10
LINES

< > TinyBrain | #1001832 - magicIndexOfSubList

JavaX fragment (include)

// Finds out the index of a sublist in the original list
// Works with nested (grand-parent) sublists.
// Does not work with lists not made with subList() (returns -1)

static <A> int magicIndexOfSubList(L<A> list, L<A> sublist) {
  Int o2 = cast get(sublist, "offset");
  if (o2 == null) ret -1;
  Int o1 = cast getOpt(list, "offset");
  ret o2-(o1 != null ? o1 : 0);
}

download  show line numbers  debug dex   

Travelled to 10 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1001832
Snippet name: magicIndexOfSubList
Eternal ID of this version: #1001832/5
Text MD5: 1d4068d3c2b4e6bdcbba9b92710ded50
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-11 17:23:24
Source code size: 379 bytes / 10 lines
Pitched / IR pitched: No / No
Views / Downloads: 209 / 894
Version history: 4 change(s)
Referenced in: [show]