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

11
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) {
  if (sublist == list) ret 0;
  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/6
Text MD5: 29873311d9fb41353db33fa575be6f38
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-04 12:21:11
Source code size: 410 bytes / 11 lines
Pitched / IR pitched: No / No
Views / Downloads: 273 / 1021
Version history: 5 change(s)
Referenced in: [show references]