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

23
LINES

< > BotCompany Repo | #1013680 // countSubList - count occurrences of sublist; doesn't count overlapping instances

JavaX fragment (include)

1  
static <A> int countSubList(L<A> x, L<A> y) {
2  
  int n = 0, lx = l(x), ly = l(y);
3  
  outer: for (int i = 0; i+ly <= lx; i++) {
4  
    for (int j = 0; j < ly; j++)
5  
      if (neq(x.get(i+j), y.get(j)))
6  
        continue outer;
7  
    ++n;
8  
    i += ly-1;
9  
  }
10  
  ret n;
11  
}
12  
13  
static <A> int countSubList(L<A> x, A... y) {
14  
  int n = 0, lx = l(x), ly = l(y);
15  
  outer: for (int i = 0; i+ly <= lx; i++) {
16  
    for (int j = 0; j < ly; j++)
17  
      if (neq(x.get(i+j), y[j]))
18  
        continue outer;
19  
    ++n;
20  
    i += ly-1;
21  
  }
22  
  ret n;
23  
}

Author comment

Began life as a copy of #1002135

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1013680
Snippet name: countSubList - count occurrences of sublist; doesn't count overlapping instances
Eternal ID of this version: #1013680/3
Text MD5: 40601b5de56fe1d2a6aae451208e098b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-21 14:41:16
Source code size: 534 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 420 / 454
Version history: 2 change(s)
Referenced in: [show references]