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

16
LINES

< > BotCompany Repo | #1027514 // substringsScoreIC_optimized1 - how many elements of a list are substrings of a string? [dev.]

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

Libraryless. Click here for Pure Java version (2343L/15K).

1  
// set must be a case-insensitive set
2  
// set must not contain empty string
3  
static int substringsScoreIC_optimized1(S s, Set<S> set) {
4  
  int maxLength = lengthOfLongestString(set);
5  
  int n = l(s);
6  
  Set<S> seen = ciSet();
7  
  for i to n: {
8  
    int k = min(i+maxLength, n);
9  
    for (int j = i+1; j <= k; j++) {
10  
      S sub = substring(s, i, j);
11  
      if (set.contains(sub))
12  
        seen.add(sub);
13  
    }
14  
  }
15  
  ret l(seen);
16  
}

Author comment

Began life as a copy of #1027490

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: #1027514
Snippet name: substringsScoreIC_optimized1 - how many elements of a list are substrings of a string? [dev.]
Eternal ID of this version: #1027514/3
Text MD5: 196522928a127314d3ec6dbd531890eb
Transpilation MD5: d89160877cef9552606d885f06544368
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-22 17:13:33
Source code size: 434 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 194 / 275
Version history: 2 change(s)
Referenced in: [show references]